blob: 67f083ab96c271840696cf1b32f7fb3fab8c0b1b [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
661 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002587 const int32_t tex_width = 32;
2588 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
2609 buffer_create_info.size = tex_width;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort6c7dff72017-01-27 18:34:50 -08002704 // Try to bind memory to an object with an out-of-range memoryOffset
2705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2717 image_alloc_info.allocationSize = image_mem_reqs.size;
2718 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2719 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2720 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2721 ASSERT_TRUE(pass);
2722 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2723 ASSERT_TRUE(pass);
2724 VkDeviceMemory image_mem, buffer_mem;
2725 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2726 ASSERT_VK_SUCCESS(err);
2727 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2728 ASSERT_VK_SUCCESS(err);
2729
2730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2731 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2732 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2733 (void)err; // This may very well return an error.
2734 m_errorMonitor->VerifyFound();
2735
2736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2737 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2738 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2739 (void)err; // This may very well return an error.
2740 m_errorMonitor->VerifyFound();
2741
2742 vkFreeMemory(device(), image_mem, NULL);
2743 vkFreeMemory(device(), buffer_mem, NULL);
2744 vkDestroyImage(device(), image, NULL);
2745 vkDestroyBuffer(device(), buffer, NULL);
2746 }
2747
Cort Stratton4c38bb52017-01-28 13:33:10 -08002748 // Try to bind memory to an object with an invalid memory type
2749 {
2750 VkImage image = VK_NULL_HANDLE;
2751 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2752 ASSERT_VK_SUCCESS(err);
2753 VkBuffer buffer = VK_NULL_HANDLE;
2754 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2755 ASSERT_VK_SUCCESS(err);
2756 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2757 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2758 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2759 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2760 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2761 image_alloc_info.allocationSize = image_mem_reqs.size;
2762 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2763 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002764 // Create a mask of available memory types *not* supported by these resources,
2765 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002766 VkPhysicalDeviceMemoryProperties memory_properties = {};
2767 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002768 VkDeviceMemory image_mem, buffer_mem;
2769
Cort Stratton4c38bb52017-01-28 13:33:10 -08002770 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002771 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002772 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2773 ASSERT_TRUE(pass);
2774 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2775 ASSERT_VK_SUCCESS(err);
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2777 err = vkBindImageMemory(device(), image, image_mem, 0);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002781 }
2782
Cort Stratton4c38bb52017-01-28 13:33:10 -08002783 uint32_t buffer_unsupported_mem_type_bits =
2784 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002785 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002786 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2787 ASSERT_TRUE(pass);
2788 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2789 ASSERT_VK_SUCCESS(err);
2790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2791 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2792 (void)err; // This may very well return an error.
2793 m_errorMonitor->VerifyFound();
2794 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002795 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002796
Cort Stratton4c38bb52017-01-28 13:33:10 -08002797 vkDestroyImage(device(), image, NULL);
2798 vkDestroyBuffer(device(), buffer, NULL);
2799 }
2800
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002801 // Try to bind memory to an image created with sparse memory flags
2802 {
2803 VkImageCreateInfo sparse_image_create_info = image_create_info;
2804 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2805 VkImageFormatProperties image_format_properties = {};
2806 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2807 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2808 sparse_image_create_info.usage, sparse_image_create_info.flags,
2809 &image_format_properties);
2810 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2811 // most likely means sparse formats aren't supported here; skip this test.
2812 } else {
2813 ASSERT_VK_SUCCESS(err);
2814 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002815 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002816 return;
2817 } else {
2818 VkImage sparse_image = VK_NULL_HANDLE;
2819 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2820 ASSERT_VK_SUCCESS(err);
2821 VkMemoryRequirements sparse_mem_reqs = {};
2822 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2823 if (sparse_mem_reqs.memoryTypeBits != 0) {
2824 VkMemoryAllocateInfo sparse_mem_alloc = {};
2825 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2826 sparse_mem_alloc.pNext = NULL;
2827 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2828 sparse_mem_alloc.memoryTypeIndex = 0;
2829 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2830 ASSERT_TRUE(pass);
2831 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2832 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2833 ASSERT_VK_SUCCESS(err);
2834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2835 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2836 // This may very well return an error.
2837 (void)err;
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2840 }
2841 vkDestroyImage(m_device->device(), sparse_image, NULL);
2842 }
2843 }
2844 }
2845
2846 // Try to bind memory to a buffer created with sparse memory flags
2847 {
2848 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2849 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 if (!m_device->phy().features().sparseResidencyBuffer) {
2851 // most likely means sparse formats aren't supported here; skip this test.
2852 } else {
2853 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2854 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2855 ASSERT_VK_SUCCESS(err);
2856 VkMemoryRequirements sparse_mem_reqs = {};
2857 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2858 if (sparse_mem_reqs.memoryTypeBits != 0) {
2859 VkMemoryAllocateInfo sparse_mem_alloc = {};
2860 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2861 sparse_mem_alloc.pNext = NULL;
2862 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2863 sparse_mem_alloc.memoryTypeIndex = 0;
2864 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2865 ASSERT_TRUE(pass);
2866 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2867 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2868 ASSERT_VK_SUCCESS(err);
2869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2870 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2871 // This may very well return an error.
2872 (void)err;
2873 m_errorMonitor->VerifyFound();
2874 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2875 }
2876 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2877 }
2878 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002879}
2880
Karl Schultz6addd812016-02-02 17:17:23 -07002881TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2882 VkResult err;
2883 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002884
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002886
Tobin Ehlisec598302015-09-15 15:02:17 -06002887 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002888
Karl Schultz6addd812016-02-02 17:17:23 -07002889 // Create an image object, allocate memory, destroy the object and then try
2890 // to bind it
2891 VkImage image;
2892 VkDeviceMemory mem;
2893 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002894
Karl Schultz6addd812016-02-02 17:17:23 -07002895 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2896 const int32_t tex_width = 32;
2897 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002898
2899 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2901 image_create_info.pNext = NULL;
2902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2903 image_create_info.format = tex_format;
2904 image_create_info.extent.width = tex_width;
2905 image_create_info.extent.height = tex_height;
2906 image_create_info.extent.depth = 1;
2907 image_create_info.mipLevels = 1;
2908 image_create_info.arrayLayers = 1;
2909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2910 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2911 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2912 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002913
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002914 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002915 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2916 mem_alloc.pNext = NULL;
2917 mem_alloc.allocationSize = 0;
2918 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002919
Chia-I Wuf7458c52015-10-26 21:10:41 +08002920 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002921 ASSERT_VK_SUCCESS(err);
2922
Karl Schultz6addd812016-02-02 17:17:23 -07002923 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002924
2925 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002926 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002927 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002928
2929 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002931 ASSERT_VK_SUCCESS(err);
2932
2933 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002934 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002935 ASSERT_VK_SUCCESS(err);
2936
2937 // Now Try to bind memory to this destroyed object
2938 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2939 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002940 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002943
Chia-I Wuf7458c52015-10-26 21:10:41 +08002944 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002945}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002946
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002947TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2948 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2949
2950 ASSERT_NO_FATAL_FAILURE(InitState());
2951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2952
2953 VkVertexInputBindingDescription input_binding;
2954 memset(&input_binding, 0, sizeof(input_binding));
2955
2956 VkVertexInputAttributeDescription input_attribs;
2957 memset(&input_attribs, 0, sizeof(input_attribs));
2958
2959 // Pick a really bad format for this purpose and make sure it should fail
2960 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2961 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2962 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002963 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002964 return;
2965 }
2966
2967 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002968 char const *vsSource =
2969 "#version 450\n"
2970 "\n"
2971 "out gl_PerVertex {\n"
2972 " vec4 gl_Position;\n"
2973 "};\n"
2974 "void main(){\n"
2975 " gl_Position = vec4(1);\n"
2976 "}\n";
2977 char const *fsSource =
2978 "#version 450\n"
2979 "\n"
2980 "layout(location=0) out vec4 color;\n"
2981 "void main(){\n"
2982 " color = vec4(1);\n"
2983 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002984
2985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2988
2989 VkPipelineObj pipe(m_device);
2990 pipe.AddColorAttachment();
2991 pipe.AddShader(&vs);
2992 pipe.AddShader(&fs);
2993
2994 pipe.AddVertexInputBindings(&input_binding, 1);
2995 pipe.AddVertexInputAttribs(&input_attribs, 1);
2996
2997 VkDescriptorSetObj descriptorSet(m_device);
2998 descriptorSet.AppendDummy();
2999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3000
3001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3002
3003 m_errorMonitor->VerifyFound();
3004}
3005
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003006TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003007 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3008 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003009
3010 VkMemoryPropertyFlags reqs = 0;
3011 VkImageCreateInfo image_create_info = {};
3012 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3013 image_create_info.pNext = NULL;
3014 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3015 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3016 image_create_info.extent.width = 256;
3017 image_create_info.extent.height = 256;
3018 image_create_info.extent.depth = 1;
3019 image_create_info.mipLevels = 1;
3020 image_create_info.arrayLayers = 1;
3021 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3022 image_create_info.flags = 0;
3023
3024 VkImageBlit blit_region = {};
3025 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3026 blit_region.srcSubresource.baseArrayLayer = 0;
3027 blit_region.srcSubresource.layerCount = 1;
3028 blit_region.srcSubresource.mipLevel = 0;
3029 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3030 blit_region.dstSubresource.baseArrayLayer = 0;
3031 blit_region.dstSubresource.layerCount = 1;
3032 blit_region.dstSubresource.mipLevel = 0;
3033
3034 // Create two images, the source with sampleCount = 2, and attempt to blit
3035 // between them
3036 {
3037 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003038 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003039 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003043 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003045 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003046 m_errorMonitor->SetDesiredFailureMsg(
3047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3048 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003049 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3050 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003051 m_errorMonitor->VerifyFound();
3052 m_commandBuffer->EndCommandBuffer();
3053 }
3054
3055 // Create two images, the dest with sampleCount = 4, and attempt to blit
3056 // between them
3057 {
3058 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003059 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003060 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003062 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003063 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003064 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003066 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003067 m_errorMonitor->SetDesiredFailureMsg(
3068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3069 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3071 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003072 m_errorMonitor->VerifyFound();
3073 m_commandBuffer->EndCommandBuffer();
3074 }
3075
3076 VkBufferImageCopy copy_region = {};
3077 copy_region.bufferRowLength = 128;
3078 copy_region.bufferImageHeight = 128;
3079 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3080 copy_region.imageSubresource.layerCount = 1;
3081 copy_region.imageExtent.height = 64;
3082 copy_region.imageExtent.width = 64;
3083 copy_region.imageExtent.depth = 1;
3084
3085 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3086 // buffer to image
3087 {
3088 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003089 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3090 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003094 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003095 m_errorMonitor->SetDesiredFailureMsg(
3096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3097 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003098 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3099 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 m_errorMonitor->VerifyFound();
3101 m_commandBuffer->EndCommandBuffer();
3102 }
3103
3104 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3105 // image to buffer
3106 {
3107 vk_testing::Buffer dst_buffer;
3108 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3109 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003113 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003114 m_errorMonitor->SetDesiredFailureMsg(
3115 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3116 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003118 dst_buffer.handle(), 1, &copy_region);
3119 m_errorMonitor->VerifyFound();
3120 m_commandBuffer->EndCommandBuffer();
3121 }
3122}
3123
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003124TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003125 ASSERT_NO_FATAL_FAILURE(InitState());
3126
3127 VkImageObj src_image(m_device);
3128 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3129 VkImageObj dst_image(m_device);
3130 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3131 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003132 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003133
3134 VkImageBlit blitRegion = {};
3135 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3136 blitRegion.srcSubresource.baseArrayLayer = 0;
3137 blitRegion.srcSubresource.layerCount = 1;
3138 blitRegion.srcSubresource.mipLevel = 0;
3139 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3140 blitRegion.dstSubresource.baseArrayLayer = 0;
3141 blitRegion.dstSubresource.layerCount = 1;
3142 blitRegion.dstSubresource.mipLevel = 0;
3143
Dave Houlton34df4cb2016-12-01 16:43:06 -07003144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3145
3146 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3147 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003148
3149 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003150 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003151 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3152 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003153
3154 m_errorMonitor->VerifyFound();
3155
Dave Houlton34df4cb2016-12-01 16:43:06 -07003156 // Test should generate 2 VU failures
3157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003159
3160 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003161 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3162 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003163
Dave Houlton34df4cb2016-12-01 16:43:06 -07003164 // TODO: Note that this only verifies that at least one of the VU enums was found
3165 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003166 m_errorMonitor->VerifyFound();
3167
Tony Barbour552f6c02016-12-21 14:34:07 -07003168 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003169}
3170
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003171TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3172 VkResult err;
3173 bool pass;
3174
3175 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3176 ASSERT_NO_FATAL_FAILURE(InitState());
3177
3178 // If w/d/h granularity is 1, test is not meaningful
3179 // TODO: When virtual device limits are available, create a set of limits for this test that
3180 // will always have a granularity of > 1 for w, h, and d
3181 auto index = m_device->graphics_queue_node_index_;
3182 auto queue_family_properties = m_device->phy().queue_properties();
3183
3184 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3185 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3186 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3187 return;
3188 }
3189
3190 // Create two images of different types and try to copy between them
3191 VkImage srcImage;
3192 VkImage dstImage;
3193 VkDeviceMemory srcMem;
3194 VkDeviceMemory destMem;
3195 VkMemoryRequirements memReqs;
3196
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003197 VkImageCreateInfo image_create_info = {};
3198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3199 image_create_info.pNext = NULL;
3200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3201 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3202 image_create_info.extent.width = 32;
3203 image_create_info.extent.height = 32;
3204 image_create_info.extent.depth = 1;
3205 image_create_info.mipLevels = 1;
3206 image_create_info.arrayLayers = 4;
3207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3209 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3210 image_create_info.flags = 0;
3211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003212 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003213 ASSERT_VK_SUCCESS(err);
3214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003216 ASSERT_VK_SUCCESS(err);
3217
3218 // Allocate memory
3219 VkMemoryAllocateInfo memAlloc = {};
3220 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3221 memAlloc.pNext = NULL;
3222 memAlloc.allocationSize = 0;
3223 memAlloc.memoryTypeIndex = 0;
3224
3225 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3226 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003228 ASSERT_TRUE(pass);
3229 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3230 ASSERT_VK_SUCCESS(err);
3231
3232 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3233 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003234 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003235 ASSERT_VK_SUCCESS(err);
3236 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3237 ASSERT_VK_SUCCESS(err);
3238
3239 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3240 ASSERT_VK_SUCCESS(err);
3241 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3242 ASSERT_VK_SUCCESS(err);
3243
Tony Barbour552f6c02016-12-21 14:34:07 -07003244 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003245 VkImageCopy copyRegion;
3246 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3247 copyRegion.srcSubresource.mipLevel = 0;
3248 copyRegion.srcSubresource.baseArrayLayer = 0;
3249 copyRegion.srcSubresource.layerCount = 1;
3250 copyRegion.srcOffset.x = 0;
3251 copyRegion.srcOffset.y = 0;
3252 copyRegion.srcOffset.z = 0;
3253 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3254 copyRegion.dstSubresource.mipLevel = 0;
3255 copyRegion.dstSubresource.baseArrayLayer = 0;
3256 copyRegion.dstSubresource.layerCount = 1;
3257 copyRegion.dstOffset.x = 0;
3258 copyRegion.dstOffset.y = 0;
3259 copyRegion.dstOffset.z = 0;
3260 copyRegion.extent.width = 1;
3261 copyRegion.extent.height = 1;
3262 copyRegion.extent.depth = 1;
3263
3264 // Introduce failure by setting srcOffset to a bad granularity value
3265 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3267 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003268 m_errorMonitor->VerifyFound();
3269
3270 // Introduce failure by setting extent to a bad granularity value
3271 copyRegion.srcOffset.y = 0;
3272 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3274 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 m_errorMonitor->VerifyFound();
3276
3277 // Now do some buffer/image copies
3278 vk_testing::Buffer buffer;
3279 VkMemoryPropertyFlags reqs = 0;
3280 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3281 VkBufferImageCopy region = {};
3282 region.bufferOffset = 0;
3283 region.bufferRowLength = 3;
3284 region.bufferImageHeight = 128;
3285 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3286 region.imageSubresource.layerCount = 1;
3287 region.imageExtent.height = 16;
3288 region.imageExtent.width = 16;
3289 region.imageExtent.depth = 1;
3290 region.imageOffset.x = 0;
3291 region.imageOffset.y = 0;
3292 region.imageOffset.z = 0;
3293
3294 // Introduce failure by setting bufferRowLength to a bad granularity value
3295 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3298 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003299 m_errorMonitor->VerifyFound();
3300 region.bufferRowLength = 128;
3301
3302 // Introduce failure by setting bufferOffset to a bad granularity value
3303 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3305 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3306 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003307 m_errorMonitor->VerifyFound();
3308 region.bufferOffset = 0;
3309
3310 // Introduce failure by setting bufferImageHeight to a bad granularity value
3311 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3314 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003315 m_errorMonitor->VerifyFound();
3316 region.bufferImageHeight = 128;
3317
3318 // Introduce failure by setting imageExtent to a bad granularity value
3319 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3321 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3322 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003323 m_errorMonitor->VerifyFound();
3324 region.imageExtent.width = 16;
3325
3326 // Introduce failure by setting imageOffset to a bad granularity value
3327 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3329 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3330 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003331 m_errorMonitor->VerifyFound();
3332
Tony Barbour552f6c02016-12-21 14:34:07 -07003333 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334
3335 vkDestroyImage(m_device->device(), srcImage, NULL);
3336 vkDestroyImage(m_device->device(), dstImage, NULL);
3337 vkFreeMemory(m_device->device(), srcMem, NULL);
3338 vkFreeMemory(m_device->device(), destMem, NULL);
3339}
3340
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003341TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003342 TEST_DESCRIPTION(
3343 "Submit command buffer created using one queue family and "
3344 "attempt to submit them on a queue created in a different "
3345 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003346
Cody Northropc31a84f2016-08-22 10:41:47 -06003347 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003348
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003349 // This test is meaningless unless we have multiple queue families
3350 auto queue_family_properties = m_device->phy().queue_properties();
3351 if (queue_family_properties.size() < 2) {
3352 return;
3353 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003355 // Get safe index of another queue family
3356 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3357 ASSERT_NO_FATAL_FAILURE(InitState());
3358 // Create a second queue using a different queue family
3359 VkQueue other_queue;
3360 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3361
3362 // Record an empty cmd buffer
3363 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3364 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3365 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3366 vkEndCommandBuffer(m_commandBuffer->handle());
3367
3368 // And submit on the wrong queue
3369 VkSubmitInfo submit_info = {};
3370 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3371 submit_info.commandBufferCount = 1;
3372 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003373 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003374
3375 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003376}
3377
Chris Forbes4c24a922016-11-16 08:59:10 +13003378TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3379 ASSERT_NO_FATAL_FAILURE(InitState());
3380
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003381 // There are no attachments, but refer to attachment 0.
3382 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003383 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003384 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003385 };
3386
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003387 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003388 VkRenderPass rp;
3389
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003390 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003392 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3393 m_errorMonitor->VerifyFound();
3394}
3395
Chris Forbesa58c4522016-09-28 15:19:39 +13003396TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3397 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3398 ASSERT_NO_FATAL_FAILURE(InitState());
3399
3400 // A renderpass with two subpasses, both writing the same attachment.
3401 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003402 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3403 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3404 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003405 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003406 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003407 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003408 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3409 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003410 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003411 VkSubpassDependency dep = {0,
3412 1,
3413 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3414 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3415 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3416 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3417 VK_DEPENDENCY_BY_REGION_BIT};
3418 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003419 VkRenderPass rp;
3420 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3421 ASSERT_VK_SUCCESS(err);
3422
3423 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003424 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003425 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3426
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003427 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003428 VkFramebuffer fb;
3429 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3430 ASSERT_VK_SUCCESS(err);
3431
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003432 char const *vsSource =
3433 "#version 450\n"
3434 "void main() { gl_Position = vec4(1); }\n";
3435 char const *fsSource =
3436 "#version 450\n"
3437 "layout(location=0) out vec4 color;\n"
3438 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003439
3440 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3441 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3442 VkPipelineObj pipe(m_device);
3443 pipe.AddColorAttachment();
3444 pipe.AddShader(&vs);
3445 pipe.AddShader(&fs);
3446 VkViewport view_port = {};
3447 m_viewports.push_back(view_port);
3448 pipe.SetViewport(m_viewports);
3449 VkRect2D rect = {};
3450 m_scissors.push_back(rect);
3451 pipe.SetScissor(m_scissors);
3452
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003454 VkPipelineLayout pl;
3455 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3456 ASSERT_VK_SUCCESS(err);
3457 pipe.CreateVKPipeline(pl, rp);
3458
Tony Barbour552f6c02016-12-21 14:34:07 -07003459 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003460
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3462 nullptr,
3463 rp,
3464 fb,
3465 {{
3466 0, 0,
3467 },
3468 {32, 32}},
3469 0,
3470 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003471
3472 // subtest 1: bind in the wrong subpass
3473 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3474 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003476 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3477 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3478 m_errorMonitor->VerifyFound();
3479
3480 vkCmdEndRenderPass(m_commandBuffer->handle());
3481
3482 // subtest 2: bind in correct subpass, then transition to next subpass
3483 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3484 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3485 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003487 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3488 m_errorMonitor->VerifyFound();
3489
3490 vkCmdEndRenderPass(m_commandBuffer->handle());
3491
Tony Barbour552f6c02016-12-21 14:34:07 -07003492 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003493
3494 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3495 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3496 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3497}
3498
Tony Barbour4e919972016-08-09 13:27:40 -06003499TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003500 TEST_DESCRIPTION(
3501 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3502 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003503 ASSERT_NO_FATAL_FAILURE(InitState());
3504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3507 "Cannot execute a render pass with renderArea "
3508 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003509
3510 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3511 m_renderPassBeginInfo.renderArea.extent.width = 257;
3512 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003513 m_commandBuffer->BeginCommandBuffer();
3514 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003515 m_errorMonitor->VerifyFound();
3516}
3517
3518TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003519 TEST_DESCRIPTION(
3520 "Generate INDEPENDENT_BLEND by disabling independent "
3521 "blend and then specifying different blend states for two "
3522 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003523 VkPhysicalDeviceFeatures features = {};
3524 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003525 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3528 "Invalid Pipeline CreateInfo: If independent blend feature not "
3529 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003530
Cody Northropc31a84f2016-08-22 10:41:47 -06003531 VkDescriptorSetObj descriptorSet(m_device);
3532 descriptorSet.AppendDummy();
3533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003534
Cody Northropc31a84f2016-08-22 10:41:47 -06003535 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003536 // Create a renderPass with two color attachments
3537 VkAttachmentReference attachments[2] = {};
3538 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3539 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3540
3541 VkSubpassDescription subpass = {};
3542 subpass.pColorAttachments = attachments;
3543 subpass.colorAttachmentCount = 2;
3544
3545 VkRenderPassCreateInfo rpci = {};
3546 rpci.subpassCount = 1;
3547 rpci.pSubpasses = &subpass;
3548 rpci.attachmentCount = 1;
3549
3550 VkAttachmentDescription attach_desc = {};
3551 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3552 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3553 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3554 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3555
3556 rpci.pAttachments = &attach_desc;
3557 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3558
3559 VkRenderPass renderpass;
3560 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003562 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003563
Cody Northropc31a84f2016-08-22 10:41:47 -06003564 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3565 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3566 att_state1.blendEnable = VK_TRUE;
3567 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3568 att_state2.blendEnable = VK_FALSE;
3569 pipeline.AddColorAttachment(0, &att_state1);
3570 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003571 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003572 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003573 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003574}
3575
Mike Weiblen40b160e2017-02-06 19:21:52 -07003576// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3577TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3578 TEST_DESCRIPTION(
3579 "Create a graphics pipeline that is incompatible with the requirements "
3580 "of its contained Renderpass/subpasses.");
3581 ASSERT_NO_FATAL_FAILURE(InitState());
3582
3583 VkDescriptorSetObj ds_obj(m_device);
3584 ds_obj.AppendDummy();
3585 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3586
3587 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3588
3589 VkPipelineColorBlendAttachmentState att_state1 = {};
3590 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3591 att_state1.blendEnable = VK_TRUE;
3592
3593 VkRenderpassObj rp_obj(m_device);
3594
3595 {
3596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3597 VkPipelineObj pipeline(m_device);
3598 pipeline.AddShader(&vs_obj);
3599 pipeline.AddColorAttachment(0, &att_state1);
3600
3601 VkGraphicsPipelineCreateInfo info = {};
3602 pipeline.InitGraphicsPipelineCreateInfo(&info);
3603 info.pColorBlendState = nullptr;
3604
3605 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3606 m_errorMonitor->VerifyFound();
3607 }
3608}
3609
Chris Forbes26ec2122016-11-29 08:58:33 +13003610#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003611TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3612 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3613 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003614 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3617 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003618
3619 // Create a renderPass with a single color attachment
3620 VkAttachmentReference attach = {};
3621 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3622 VkSubpassDescription subpass = {};
3623 VkRenderPassCreateInfo rpci = {};
3624 rpci.subpassCount = 1;
3625 rpci.pSubpasses = &subpass;
3626 rpci.attachmentCount = 1;
3627 VkAttachmentDescription attach_desc = {};
3628 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3629 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3630 rpci.pAttachments = &attach_desc;
3631 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3632 VkRenderPass rp;
3633 subpass.pDepthStencilAttachment = &attach;
3634 subpass.pColorAttachments = NULL;
3635 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3636 m_errorMonitor->VerifyFound();
3637}
Chris Forbes26ec2122016-11-29 08:58:33 +13003638#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003639
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003640TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003641 TEST_DESCRIPTION(
3642 "Create a framebuffer where a subpass has a preserve "
3643 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003644
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003649
3650 VkAttachmentReference color_attach = {};
3651 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3652 color_attach.attachment = 0;
3653 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3654 VkSubpassDescription subpass = {};
3655 subpass.colorAttachmentCount = 1;
3656 subpass.pColorAttachments = &color_attach;
3657 subpass.preserveAttachmentCount = 1;
3658 subpass.pPreserveAttachments = &preserve_attachment;
3659
3660 VkRenderPassCreateInfo rpci = {};
3661 rpci.subpassCount = 1;
3662 rpci.pSubpasses = &subpass;
3663 rpci.attachmentCount = 1;
3664 VkAttachmentDescription attach_desc = {};
3665 attach_desc.format = VK_FORMAT_UNDEFINED;
3666 rpci.pAttachments = &attach_desc;
3667 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3668 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003669 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003670
3671 m_errorMonitor->VerifyFound();
3672
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003673 if (result == VK_SUCCESS) {
3674 vkDestroyRenderPass(m_device->device(), rp, NULL);
3675 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003676}
3677
Chris Forbesc5389742016-06-29 11:49:23 +12003678TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003679 TEST_DESCRIPTION(
3680 "Ensure that CreateRenderPass produces a validation error "
3681 "when the source of a subpass multisample resolve "
3682 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003683
Chris Forbesc5389742016-06-29 11:49:23 +12003684 ASSERT_NO_FATAL_FAILURE(InitState());
3685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3687 "Subpass 0 requests multisample resolve from attachment 0 which has "
3688 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003689
3690 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3692 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3693 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3694 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3695 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3696 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003697 };
3698
3699 VkAttachmentReference color = {
3700 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3701 };
3702
3703 VkAttachmentReference resolve = {
3704 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3705 };
3706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003707 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003709 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003710
3711 VkRenderPass rp;
3712 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3713
3714 m_errorMonitor->VerifyFound();
3715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003716 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003717}
3718
3719TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003720 TEST_DESCRIPTION(
3721 "Ensure CreateRenderPass produces a validation error "
3722 "when a subpass multisample resolve operation is "
3723 "requested, and the destination of that resolve has "
3724 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003725
Chris Forbesc5389742016-06-29 11:49:23 +12003726 ASSERT_NO_FATAL_FAILURE(InitState());
3727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3729 "Subpass 0 requests multisample resolve into attachment 1, which "
3730 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003731
3732 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003733 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3734 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3735 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3736 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3737 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003739 };
3740
3741 VkAttachmentReference color = {
3742 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3743 };
3744
3745 VkAttachmentReference resolve = {
3746 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3747 };
3748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003749 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003751 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003752
3753 VkRenderPass rp;
3754 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3755
3756 m_errorMonitor->VerifyFound();
3757
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003758 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003759}
3760
Chris Forbes3f128ef2016-06-29 14:58:53 +12003761TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003762 TEST_DESCRIPTION(
3763 "Ensure CreateRenderPass produces a validation error "
3764 "when the color and depth attachments used by a subpass "
3765 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003766
Chris Forbes3f128ef2016-06-29 14:58:53 +12003767 ASSERT_NO_FATAL_FAILURE(InitState());
3768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3770 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003771
3772 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3774 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3775 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3776 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3777 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3778 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003779 };
3780
3781 VkAttachmentReference color[] = {
3782 {
3783 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3784 },
3785 {
3786 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3787 },
3788 };
3789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003790 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003793
3794 VkRenderPass rp;
3795 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3796
3797 m_errorMonitor->VerifyFound();
3798
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003799 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003800}
3801
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003802TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003803 TEST_DESCRIPTION(
3804 "Hit errors when attempting to create a framebuffer :\n"
3805 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3806 " 2. Use a color image as depthStencil attachment\n"
3807 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3808 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3809 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3810 " 6. Framebuffer attachment where dimensions don't match\n"
3811 " 7. Framebuffer attachment w/o identity swizzle\n"
3812 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003813
3814 ASSERT_NO_FATAL_FAILURE(InitState());
3815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3816
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3818 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3819 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003820
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003821 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003822 VkAttachmentReference attach = {};
3823 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3824 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003825 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003826 VkRenderPassCreateInfo rpci = {};
3827 rpci.subpassCount = 1;
3828 rpci.pSubpasses = &subpass;
3829 rpci.attachmentCount = 1;
3830 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003831 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003832 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003833 rpci.pAttachments = &attach_desc;
3834 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3835 VkRenderPass rp;
3836 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3837 ASSERT_VK_SUCCESS(err);
3838
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003839 VkImageView ivs[2];
3840 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3841 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003842 VkFramebufferCreateInfo fb_info = {};
3843 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3844 fb_info.pNext = NULL;
3845 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003846 // Set mis-matching attachmentCount
3847 fb_info.attachmentCount = 2;
3848 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003849 fb_info.width = 100;
3850 fb_info.height = 100;
3851 fb_info.layers = 1;
3852
3853 VkFramebuffer fb;
3854 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3855
3856 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003857 if (err == VK_SUCCESS) {
3858 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3859 }
3860 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003861
3862 // Create a renderPass with a depth-stencil attachment created with
3863 // IMAGE_USAGE_COLOR_ATTACHMENT
3864 // Add our color attachment to pDepthStencilAttachment
3865 subpass.pDepthStencilAttachment = &attach;
3866 subpass.pColorAttachments = NULL;
3867 VkRenderPass rp_ds;
3868 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3869 ASSERT_VK_SUCCESS(err);
3870 // Set correct attachment count, but attachment has COLOR usage bit set
3871 fb_info.attachmentCount = 1;
3872 fb_info.renderPass = rp_ds;
3873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003875 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3876
3877 m_errorMonitor->VerifyFound();
3878 if (err == VK_SUCCESS) {
3879 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3880 }
3881 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003882
3883 // Create new renderpass with alternate attachment format from fb
3884 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3885 subpass.pDepthStencilAttachment = NULL;
3886 subpass.pColorAttachments = &attach;
3887 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3888 ASSERT_VK_SUCCESS(err);
3889
3890 // Cause error due to mis-matched formats between rp & fb
3891 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3892 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3894 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3896
3897 m_errorMonitor->VerifyFound();
3898 if (err == VK_SUCCESS) {
3899 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3900 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003901 vkDestroyRenderPass(m_device->device(), rp, NULL);
3902
3903 // Create new renderpass with alternate sample count from fb
3904 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3905 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3906 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3907 ASSERT_VK_SUCCESS(err);
3908
3909 // Cause error due to mis-matched sample count between rp & fb
3910 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3912 " has VK_SAMPLE_COUNT_1_BIT samples "
3913 "that do not match the "
3914 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003915 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3916
3917 m_errorMonitor->VerifyFound();
3918 if (err == VK_SUCCESS) {
3919 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3920 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003921
3922 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003923
3924 // Create a custom imageView with non-1 mip levels
3925 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003926 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 -06003927 ASSERT_TRUE(image.initialized());
3928
3929 VkImageView view;
3930 VkImageViewCreateInfo ivci = {};
3931 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3932 ivci.image = image.handle();
3933 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3934 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3935 ivci.subresourceRange.layerCount = 1;
3936 ivci.subresourceRange.baseMipLevel = 0;
3937 // Set level count 2 (only 1 is allowed for FB attachment)
3938 ivci.subresourceRange.levelCount = 2;
3939 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3940 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3941 ASSERT_VK_SUCCESS(err);
3942 // Re-create renderpass to have matching sample count
3943 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3944 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3945 ASSERT_VK_SUCCESS(err);
3946
3947 fb_info.renderPass = rp;
3948 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003950 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3951
3952 m_errorMonitor->VerifyFound();
3953 if (err == VK_SUCCESS) {
3954 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3955 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003956 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003957 // Update view to original color buffer and grow FB dimensions too big
3958 fb_info.pAttachments = ivs;
3959 fb_info.height = 1024;
3960 fb_info.width = 1024;
3961 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3963 " Attachment dimensions must be at "
3964 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003965 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3966
3967 m_errorMonitor->VerifyFound();
3968 if (err == VK_SUCCESS) {
3969 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3970 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003971 // Create view attachment with non-identity swizzle
3972 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3973 ivci.image = image.handle();
3974 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3975 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3976 ivci.subresourceRange.layerCount = 1;
3977 ivci.subresourceRange.baseMipLevel = 0;
3978 ivci.subresourceRange.levelCount = 1;
3979 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3980 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3981 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3982 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3983 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3984 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3985 ASSERT_VK_SUCCESS(err);
3986
3987 fb_info.pAttachments = &view;
3988 fb_info.height = 100;
3989 fb_info.width = 100;
3990 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3992 " has non-identy swizzle. All "
3993 "framebuffer attachments must have "
3994 "been created with the identity "
3995 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003996 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3997
3998 m_errorMonitor->VerifyFound();
3999 if (err == VK_SUCCESS) {
4000 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4001 }
4002 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004003 // reset attachment to color attachment
4004 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004005
4006 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004007 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004008 fb_info.height = 100;
4009 fb_info.layers = 1;
4010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004011 m_errorMonitor->SetUnexpectedError(
4012 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4013 "Here are the respective dimensions for attachment");
4014
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004015 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 }
4021
4022 // Request fb that exceeds max height
4023 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004024 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004025 fb_info.layers = 1;
4026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004027 m_errorMonitor->SetUnexpectedError(
4028 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4029 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004030 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4031
4032 m_errorMonitor->VerifyFound();
4033 if (err == VK_SUCCESS) {
4034 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4035 }
4036
4037 // Request fb that exceeds max layers
4038 fb_info.width = 100;
4039 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004040 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004042 m_errorMonitor->SetUnexpectedError(
4043 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4044 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004045 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4046
4047 m_errorMonitor->VerifyFound();
4048 if (err == VK_SUCCESS) {
4049 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4050 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004051
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004052 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004053}
4054
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004055TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004056 TEST_DESCRIPTION(
4057 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4058 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004059
Cody Northropc31a84f2016-08-22 10:41:47 -06004060 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004061 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4063 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004064 m_errorMonitor->VerifyFound();
4065}
4066
4067TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004068 TEST_DESCRIPTION(
4069 "Run a simple draw calls to validate failure when Line Width dynamic "
4070 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004071
Cody Northropc31a84f2016-08-22 10:41:47 -06004072 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004073 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4075 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004076 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004077}
4078
4079TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004080 TEST_DESCRIPTION(
4081 "Run a simple draw calls to validate failure when Viewport dynamic "
4082 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004083
Cody Northropc31a84f2016-08-22 10:41:47 -06004084 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004085 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4087 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004088 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004089 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004090}
4091
4092TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004093 TEST_DESCRIPTION(
4094 "Run a simple draw calls to validate failure when Scissor dynamic "
4095 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004096
Cody Northropc31a84f2016-08-22 10:41:47 -06004097 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004098 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4100 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004101 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004102 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004103}
4104
Cortd713fe82016-07-27 09:51:27 -07004105TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004106 TEST_DESCRIPTION(
4107 "Run a simple draw calls to validate failure when Blend Constants "
4108 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004109
4110 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004111 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4113 "Dynamic blend constants state not set for this command buffer");
4114 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004115 m_errorMonitor->VerifyFound();
4116}
4117
4118TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004119 TEST_DESCRIPTION(
4120 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4121 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004122
4123 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004124 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004125 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004126 return;
4127 }
4128 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4130 "Dynamic depth bounds state not set for this command buffer");
4131 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004132 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004133}
4134
4135TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004136 TEST_DESCRIPTION(
4137 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4138 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004139
4140 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004141 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4143 "Dynamic stencil read mask state not set for this command buffer");
4144 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004145 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004146}
4147
4148TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004149 TEST_DESCRIPTION(
4150 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4151 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004152
4153 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004154 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4156 "Dynamic stencil write mask state not set for this command buffer");
4157 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004158 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004159}
4160
4161TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004162 TEST_DESCRIPTION(
4163 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4164 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004165
4166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004167 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4169 "Dynamic stencil reference state not set for this command buffer");
4170 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004171 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004172}
4173
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004174TEST_F(VkLayerTest, IndexBufferNotBound) {
4175 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004176
4177 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4179 "Index buffer object not bound to this command buffer when Indexed ");
4180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004181 m_errorMonitor->VerifyFound();
4182}
4183
Karl Schultz6addd812016-02-02 17:17:23 -07004184TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4186 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4187 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004188
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004189 ASSERT_NO_FATAL_FAILURE(InitState());
4190 ASSERT_NO_FATAL_FAILURE(InitViewport());
4191 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4192
Karl Schultz6addd812016-02-02 17:17:23 -07004193 // We luck out b/c by default the framework creates CB w/ the
4194 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004195 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004196 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004197 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004198
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004199 // Bypass framework since it does the waits automatically
4200 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004201 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004202 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4203 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004204 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004205 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004206 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004207 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004208 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004209 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004210 submit_info.pSignalSemaphores = NULL;
4211
Chris Forbes40028e22016-06-13 09:59:34 +12004212 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004213 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004214 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004215
Karl Schultz6addd812016-02-02 17:17:23 -07004216 // Cause validation error by re-submitting cmd buffer that should only be
4217 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004218 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004219 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004220
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004221 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004222}
4223
Karl Schultz6addd812016-02-02 17:17:23 -07004224TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004225 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004226 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004227
4228 ASSERT_NO_FATAL_FAILURE(InitState());
4229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004230
Karl Schultz6addd812016-02-02 17:17:23 -07004231 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4232 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004233 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004234 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004235 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004236
4237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4239 ds_pool_ci.pNext = NULL;
4240 ds_pool_ci.flags = 0;
4241 ds_pool_ci.maxSets = 1;
4242 ds_pool_ci.poolSizeCount = 1;
4243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004244
4245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004247 ASSERT_VK_SUCCESS(err);
4248
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004249 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4250 dsl_binding_samp.binding = 0;
4251 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4252 dsl_binding_samp.descriptorCount = 1;
4253 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4254 dsl_binding_samp.pImmutableSamplers = NULL;
4255
4256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4258 ds_layout_ci.pNext = NULL;
4259 ds_layout_ci.bindingCount = 1;
4260 ds_layout_ci.pBindings = &dsl_binding_samp;
4261
4262 VkDescriptorSetLayout ds_layout_samp;
4263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4264 ASSERT_VK_SUCCESS(err);
4265
4266 // Try to allocate 2 sets when pool only has 1 set
4267 VkDescriptorSet descriptor_sets[2];
4268 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4269 VkDescriptorSetAllocateInfo alloc_info = {};
4270 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4271 alloc_info.descriptorSetCount = 2;
4272 alloc_info.descriptorPool = ds_pool;
4273 alloc_info.pSetLayouts = set_layouts;
4274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4275 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4276 m_errorMonitor->VerifyFound();
4277
4278 alloc_info.descriptorSetCount = 1;
4279 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004280 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004281 dsl_binding.binding = 0;
4282 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4283 dsl_binding.descriptorCount = 1;
4284 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4285 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
Karl Schultz6addd812016-02-02 17:17:23 -07004287 ds_layout_ci.bindingCount = 1;
4288 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004289
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004290 VkDescriptorSetLayout ds_layout_ub;
4291 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004292 ASSERT_VK_SUCCESS(err);
4293
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004294 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004295 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004296 alloc_info.pSetLayouts = &ds_layout_ub;
4297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4298 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004299
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004300 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004301
Karl Schultz2825ab92016-12-02 08:23:14 -07004302 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004303 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004304 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004305}
4306
Karl Schultz6addd812016-02-02 17:17:23 -07004307TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4308 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004309
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004311
Tobin Ehlise735c692015-10-08 13:13:50 -06004312 ASSERT_NO_FATAL_FAILURE(InitState());
4313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004314
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004315 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004316 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4317 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004318
4319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4321 ds_pool_ci.pNext = NULL;
4322 ds_pool_ci.maxSets = 1;
4323 ds_pool_ci.poolSizeCount = 1;
4324 ds_pool_ci.flags = 0;
4325 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4326 // app can only call vkResetDescriptorPool on this pool.;
4327 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004328
4329 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004330 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004331 ASSERT_VK_SUCCESS(err);
4332
4333 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004334 dsl_binding.binding = 0;
4335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4336 dsl_binding.descriptorCount = 1;
4337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4338 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004339
4340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4342 ds_layout_ci.pNext = NULL;
4343 ds_layout_ci.bindingCount = 1;
4344 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004345
4346 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004348 ASSERT_VK_SUCCESS(err);
4349
4350 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004351 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004353 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004354 alloc_info.descriptorPool = ds_pool;
4355 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004357 ASSERT_VK_SUCCESS(err);
4358
4359 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004360 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004361
Chia-I Wuf7458c52015-10-26 21:10:41 +08004362 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4363 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004364}
4365
Karl Schultz6addd812016-02-02 17:17:23 -07004366TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004367 // Attempt to clear Descriptor Pool with bad object.
4368 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004369
4370 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004372 uint64_t fake_pool_handle = 0xbaad6001;
4373 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4374 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004375 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004376}
4377
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004378TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004379 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4380 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004381 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004382 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004383
4384 uint64_t fake_set_handle = 0xbaad6001;
4385 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004386 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004388
4389 ASSERT_NO_FATAL_FAILURE(InitState());
4390
4391 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4392 layout_bindings[0].binding = 0;
4393 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4394 layout_bindings[0].descriptorCount = 1;
4395 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4396 layout_bindings[0].pImmutableSamplers = NULL;
4397
4398 VkDescriptorSetLayout descriptor_set_layout;
4399 VkDescriptorSetLayoutCreateInfo dslci = {};
4400 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4401 dslci.pNext = NULL;
4402 dslci.bindingCount = 1;
4403 dslci.pBindings = layout_bindings;
4404 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004405 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004406
4407 VkPipelineLayout pipeline_layout;
4408 VkPipelineLayoutCreateInfo plci = {};
4409 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4410 plci.pNext = NULL;
4411 plci.setLayoutCount = 1;
4412 plci.pSetLayouts = &descriptor_set_layout;
4413 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004414 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004415
Tony Barbour552f6c02016-12-21 14:34:07 -07004416 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4418 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004419 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004420 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004421 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4422 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004423}
4424
Karl Schultz6addd812016-02-02 17:17:23 -07004425TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004426 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4427 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004428 uint64_t fake_layout_handle = 0xbaad6001;
4429 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004432 VkPipelineLayout pipeline_layout;
4433 VkPipelineLayoutCreateInfo plci = {};
4434 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4435 plci.pNext = NULL;
4436 plci.setLayoutCount = 1;
4437 plci.pSetLayouts = &bad_layout;
4438 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4439
4440 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004441}
4442
Mark Muellerd4914412016-06-13 17:52:06 -06004443TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004444 TEST_DESCRIPTION(
4445 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4446 "1) A uniform buffer update must have a valid buffer index."
4447 "2) When using an array of descriptors in a single WriteDescriptor,"
4448 " the descriptor types and stageflags must all be the same."
4449 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004450
Mike Weiblena6666382017-01-05 15:16:11 -07004451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004452
4453 ASSERT_NO_FATAL_FAILURE(InitState());
4454 VkDescriptorPoolSize ds_type_count[4] = {};
4455 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4456 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004457 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004458 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004459 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004460 ds_type_count[2].descriptorCount = 1;
4461 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4462 ds_type_count[3].descriptorCount = 1;
4463
4464 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4465 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4466 ds_pool_ci.maxSets = 1;
4467 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4468 ds_pool_ci.pPoolSizes = ds_type_count;
4469
4470 VkDescriptorPool ds_pool;
4471 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4472 ASSERT_VK_SUCCESS(err);
4473
Mark Muellerb9896722016-06-16 09:54:29 -06004474 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004475 layout_binding[0].binding = 0;
4476 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4477 layout_binding[0].descriptorCount = 1;
4478 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4479 layout_binding[0].pImmutableSamplers = NULL;
4480
4481 layout_binding[1].binding = 1;
4482 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4483 layout_binding[1].descriptorCount = 1;
4484 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4485 layout_binding[1].pImmutableSamplers = NULL;
4486
4487 VkSamplerCreateInfo sampler_ci = {};
4488 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4489 sampler_ci.pNext = NULL;
4490 sampler_ci.magFilter = VK_FILTER_NEAREST;
4491 sampler_ci.minFilter = VK_FILTER_NEAREST;
4492 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4493 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4494 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4495 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4496 sampler_ci.mipLodBias = 1.0;
4497 sampler_ci.anisotropyEnable = VK_FALSE;
4498 sampler_ci.maxAnisotropy = 1;
4499 sampler_ci.compareEnable = VK_FALSE;
4500 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4501 sampler_ci.minLod = 1.0;
4502 sampler_ci.maxLod = 1.0;
4503 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4504 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4505 VkSampler sampler;
4506
4507 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4508 ASSERT_VK_SUCCESS(err);
4509
4510 layout_binding[2].binding = 2;
4511 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4512 layout_binding[2].descriptorCount = 1;
4513 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4514 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4515
Mark Muellerd4914412016-06-13 17:52:06 -06004516 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4517 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4518 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4519 ds_layout_ci.pBindings = layout_binding;
4520 VkDescriptorSetLayout ds_layout;
4521 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4522 ASSERT_VK_SUCCESS(err);
4523
4524 VkDescriptorSetAllocateInfo alloc_info = {};
4525 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4526 alloc_info.descriptorSetCount = 1;
4527 alloc_info.descriptorPool = ds_pool;
4528 alloc_info.pSetLayouts = &ds_layout;
4529 VkDescriptorSet descriptorSet;
4530 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4531 ASSERT_VK_SUCCESS(err);
4532
4533 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4534 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4535 pipeline_layout_ci.pNext = NULL;
4536 pipeline_layout_ci.setLayoutCount = 1;
4537 pipeline_layout_ci.pSetLayouts = &ds_layout;
4538
4539 VkPipelineLayout pipeline_layout;
4540 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4541 ASSERT_VK_SUCCESS(err);
4542
Mark Mueller5c838ce2016-06-16 09:54:29 -06004543 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004544 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4545 descriptor_write.dstSet = descriptorSet;
4546 descriptor_write.dstBinding = 0;
4547 descriptor_write.descriptorCount = 1;
4548 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4549
Mark Mueller5c838ce2016-06-16 09:54:29 -06004550 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004551 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4552 m_errorMonitor->VerifyFound();
4553
4554 // Create a buffer to update the descriptor with
4555 uint32_t qfi = 0;
4556 VkBufferCreateInfo buffCI = {};
4557 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4558 buffCI.size = 1024;
4559 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4560 buffCI.queueFamilyIndexCount = 1;
4561 buffCI.pQueueFamilyIndices = &qfi;
4562
4563 VkBuffer dyub;
4564 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4565 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004566
Tony Barboure132c5f2016-12-12 11:50:20 -07004567 VkDeviceMemory mem;
4568 VkMemoryRequirements mem_reqs;
4569 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4570
4571 VkMemoryAllocateInfo mem_alloc_info = {};
4572 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4573 mem_alloc_info.allocationSize = mem_reqs.size;
4574 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4575 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4576 ASSERT_VK_SUCCESS(err);
4577
4578 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4579 ASSERT_VK_SUCCESS(err);
4580
4581 VkDescriptorBufferInfo buffInfo[2] = {};
4582 buffInfo[0].buffer = dyub;
4583 buffInfo[0].offset = 0;
4584 buffInfo[0].range = 1024;
4585 buffInfo[1].buffer = dyub;
4586 buffInfo[1].offset = 0;
4587 buffInfo[1].range = 1024;
4588 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004589 descriptor_write.descriptorCount = 2;
4590
Mark Mueller5c838ce2016-06-16 09:54:29 -06004591 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4594 m_errorMonitor->VerifyFound();
4595
Mark Mueller5c838ce2016-06-16 09:54:29 -06004596 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4597 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004598 descriptor_write.dstBinding = 1;
4599 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004600
Mark Mueller5c838ce2016-06-16 09:54:29 -06004601 // Make pImageInfo index non-null to avoid complaints of it missing
4602 VkDescriptorImageInfo imageInfo = {};
4603 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4604 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004606 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4607 m_errorMonitor->VerifyFound();
4608
Mark Muellerd4914412016-06-13 17:52:06 -06004609 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004610 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004611 vkDestroySampler(m_device->device(), sampler, NULL);
4612 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4613 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4614 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4615}
4616
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004617TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004618 TEST_DESCRIPTION(
4619 "Attempt to draw with a command buffer that is invalid "
4620 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004621 ASSERT_NO_FATAL_FAILURE(InitState());
4622
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004623 VkBuffer buffer;
4624 VkDeviceMemory mem;
4625 VkMemoryRequirements mem_reqs;
4626
4627 VkBufferCreateInfo buf_info = {};
4628 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004629 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004630 buf_info.size = 256;
4631 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4632 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4633 ASSERT_VK_SUCCESS(err);
4634
4635 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4636
4637 VkMemoryAllocateInfo alloc_info = {};
4638 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4639 alloc_info.allocationSize = 256;
4640 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004641 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 -06004642 if (!pass) {
4643 vkDestroyBuffer(m_device->device(), buffer, NULL);
4644 return;
4645 }
4646 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4647 ASSERT_VK_SUCCESS(err);
4648
4649 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4650 ASSERT_VK_SUCCESS(err);
4651
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004652 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004653 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004654 m_commandBuffer->EndCommandBuffer();
4655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004657 // Destroy buffer dependency prior to submit to cause ERROR
4658 vkDestroyBuffer(m_device->device(), buffer, NULL);
4659
4660 VkSubmitInfo submit_info = {};
4661 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4662 submit_info.commandBufferCount = 1;
4663 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004664 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004665 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4666
4667 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004668 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004669 vkFreeMemory(m_device->handle(), mem, NULL);
4670}
4671
Tobin Ehlisea413442016-09-28 10:23:59 -06004672TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4673 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4674
4675 ASSERT_NO_FATAL_FAILURE(InitState());
4676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4677
4678 VkDescriptorPoolSize ds_type_count;
4679 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4680 ds_type_count.descriptorCount = 1;
4681
4682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4684 ds_pool_ci.maxSets = 1;
4685 ds_pool_ci.poolSizeCount = 1;
4686 ds_pool_ci.pPoolSizes = &ds_type_count;
4687
4688 VkDescriptorPool ds_pool;
4689 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4690 ASSERT_VK_SUCCESS(err);
4691
4692 VkDescriptorSetLayoutBinding layout_binding;
4693 layout_binding.binding = 0;
4694 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4695 layout_binding.descriptorCount = 1;
4696 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4697 layout_binding.pImmutableSamplers = NULL;
4698
4699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4701 ds_layout_ci.bindingCount = 1;
4702 ds_layout_ci.pBindings = &layout_binding;
4703 VkDescriptorSetLayout ds_layout;
4704 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4705 ASSERT_VK_SUCCESS(err);
4706
4707 VkDescriptorSetAllocateInfo alloc_info = {};
4708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4709 alloc_info.descriptorSetCount = 1;
4710 alloc_info.descriptorPool = ds_pool;
4711 alloc_info.pSetLayouts = &ds_layout;
4712 VkDescriptorSet descriptor_set;
4713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4714 ASSERT_VK_SUCCESS(err);
4715
4716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4718 pipeline_layout_ci.pNext = NULL;
4719 pipeline_layout_ci.setLayoutCount = 1;
4720 pipeline_layout_ci.pSetLayouts = &ds_layout;
4721
4722 VkPipelineLayout pipeline_layout;
4723 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4724 ASSERT_VK_SUCCESS(err);
4725
4726 VkBuffer buffer;
4727 uint32_t queue_family_index = 0;
4728 VkBufferCreateInfo buffer_create_info = {};
4729 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4730 buffer_create_info.size = 1024;
4731 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4732 buffer_create_info.queueFamilyIndexCount = 1;
4733 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4734
4735 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4736 ASSERT_VK_SUCCESS(err);
4737
4738 VkMemoryRequirements memory_reqs;
4739 VkDeviceMemory buffer_memory;
4740
4741 VkMemoryAllocateInfo memory_info = {};
4742 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4743 memory_info.allocationSize = 0;
4744 memory_info.memoryTypeIndex = 0;
4745
4746 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4747 memory_info.allocationSize = memory_reqs.size;
4748 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4749 ASSERT_TRUE(pass);
4750
4751 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4752 ASSERT_VK_SUCCESS(err);
4753 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4754 ASSERT_VK_SUCCESS(err);
4755
4756 VkBufferView view;
4757 VkBufferViewCreateInfo bvci = {};
4758 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4759 bvci.buffer = buffer;
4760 bvci.format = VK_FORMAT_R8_UNORM;
4761 bvci.range = VK_WHOLE_SIZE;
4762
4763 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4764 ASSERT_VK_SUCCESS(err);
4765
4766 VkWriteDescriptorSet descriptor_write = {};
4767 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4768 descriptor_write.dstSet = descriptor_set;
4769 descriptor_write.dstBinding = 0;
4770 descriptor_write.descriptorCount = 1;
4771 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4772 descriptor_write.pTexelBufferView = &view;
4773
4774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4775
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004776 char const *vsSource =
4777 "#version 450\n"
4778 "\n"
4779 "out gl_PerVertex { \n"
4780 " vec4 gl_Position;\n"
4781 "};\n"
4782 "void main(){\n"
4783 " gl_Position = vec4(1);\n"
4784 "}\n";
4785 char const *fsSource =
4786 "#version 450\n"
4787 "\n"
4788 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4789 "layout(location=0) out vec4 x;\n"
4790 "void main(){\n"
4791 " x = imageLoad(s, 0);\n"
4792 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4795 VkPipelineObj pipe(m_device);
4796 pipe.AddShader(&vs);
4797 pipe.AddShader(&fs);
4798 pipe.AddColorAttachment();
4799 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4800
4801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4803
Tony Barbour552f6c02016-12-21 14:34:07 -07004804 m_commandBuffer->BeginCommandBuffer();
4805 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4806
Tobin Ehlisea413442016-09-28 10:23:59 -06004807 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4808 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4809 VkRect2D scissor = {{0, 0}, {16, 16}};
4810 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4811 // Bind pipeline to cmd buffer
4812 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4813 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4814 &descriptor_set, 0, nullptr);
4815 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004816 m_commandBuffer->EndRenderPass();
4817 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004818
4819 // Delete BufferView in order to invalidate cmd buffer
4820 vkDestroyBufferView(m_device->device(), view, NULL);
4821 // Now attempt submit of cmd buffer
4822 VkSubmitInfo submit_info = {};
4823 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4824 submit_info.commandBufferCount = 1;
4825 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4826 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4827 m_errorMonitor->VerifyFound();
4828
4829 // Clean-up
4830 vkDestroyBuffer(m_device->device(), buffer, NULL);
4831 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4835}
4836
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004837TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004838 TEST_DESCRIPTION(
4839 "Attempt to draw with a command buffer that is invalid "
4840 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004841 ASSERT_NO_FATAL_FAILURE(InitState());
4842
4843 VkImage image;
4844 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4845 VkImageCreateInfo image_create_info = {};
4846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4847 image_create_info.pNext = NULL;
4848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4849 image_create_info.format = tex_format;
4850 image_create_info.extent.width = 32;
4851 image_create_info.extent.height = 32;
4852 image_create_info.extent.depth = 1;
4853 image_create_info.mipLevels = 1;
4854 image_create_info.arrayLayers = 1;
4855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4856 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004857 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004858 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004860 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004861 // Have to bind memory to image before recording cmd in cmd buffer using it
4862 VkMemoryRequirements mem_reqs;
4863 VkDeviceMemory image_mem;
4864 bool pass;
4865 VkMemoryAllocateInfo mem_alloc = {};
4866 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4867 mem_alloc.pNext = NULL;
4868 mem_alloc.memoryTypeIndex = 0;
4869 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4870 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004872 ASSERT_TRUE(pass);
4873 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4874 ASSERT_VK_SUCCESS(err);
4875 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4876 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004877
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004878 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004879 VkClearColorValue ccv;
4880 ccv.float32[0] = 1.0f;
4881 ccv.float32[1] = 1.0f;
4882 ccv.float32[2] = 1.0f;
4883 ccv.float32[3] = 1.0f;
4884 VkImageSubresourceRange isr = {};
4885 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004886 isr.baseArrayLayer = 0;
4887 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004888 isr.layerCount = 1;
4889 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004890 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004891 m_commandBuffer->EndCommandBuffer();
4892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004894 // Destroy image dependency prior to submit to cause ERROR
4895 vkDestroyImage(m_device->device(), image, NULL);
4896
4897 VkSubmitInfo submit_info = {};
4898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4899 submit_info.commandBufferCount = 1;
4900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004901 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4903
4904 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004905 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004906}
4907
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004908TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004909 TEST_DESCRIPTION(
4910 "Attempt to draw with a command buffer that is invalid "
4911 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004912 VkFormatProperties format_properties;
4913 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004914 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4915 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004916 return;
4917 }
4918
4919 ASSERT_NO_FATAL_FAILURE(InitState());
4920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4921
4922 VkImageCreateInfo image_ci = {};
4923 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4924 image_ci.pNext = NULL;
4925 image_ci.imageType = VK_IMAGE_TYPE_2D;
4926 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4927 image_ci.extent.width = 32;
4928 image_ci.extent.height = 32;
4929 image_ci.extent.depth = 1;
4930 image_ci.mipLevels = 1;
4931 image_ci.arrayLayers = 1;
4932 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4933 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004934 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004935 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4936 image_ci.flags = 0;
4937 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004939
4940 VkMemoryRequirements memory_reqs;
4941 VkDeviceMemory image_memory;
4942 bool pass;
4943 VkMemoryAllocateInfo memory_info = {};
4944 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4945 memory_info.pNext = NULL;
4946 memory_info.allocationSize = 0;
4947 memory_info.memoryTypeIndex = 0;
4948 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4949 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004951 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004953 ASSERT_VK_SUCCESS(err);
4954 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4955 ASSERT_VK_SUCCESS(err);
4956
4957 VkImageViewCreateInfo ivci = {
4958 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4959 nullptr,
4960 0,
4961 image,
4962 VK_IMAGE_VIEW_TYPE_2D,
4963 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004965 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4966 };
4967 VkImageView view;
4968 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4969 ASSERT_VK_SUCCESS(err);
4970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004971 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004972 VkFramebuffer fb;
4973 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4974 ASSERT_VK_SUCCESS(err);
4975
4976 // Just use default renderpass with our framebuffer
4977 m_renderPassBeginInfo.framebuffer = fb;
4978 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004979 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004980 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004981 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4982 m_commandBuffer->EndRenderPass();
4983 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004984 // Destroy image attached to framebuffer to invalidate cmd buffer
4985 vkDestroyImage(m_device->device(), image, NULL);
4986 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004988 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004989 QueueCommandBuffer(false);
4990 m_errorMonitor->VerifyFound();
4991
4992 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4993 vkDestroyImageView(m_device->device(), view, nullptr);
4994 vkFreeMemory(m_device->device(), image_memory, nullptr);
4995}
4996
Tobin Ehlisb329f992016-10-12 13:20:29 -06004997TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4998 TEST_DESCRIPTION("Delete in-use framebuffer.");
4999 VkFormatProperties format_properties;
5000 VkResult err = VK_SUCCESS;
5001 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5002
5003 ASSERT_NO_FATAL_FAILURE(InitState());
5004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5005
5006 VkImageObj image(m_device);
5007 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5008 ASSERT_TRUE(image.initialized());
5009 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5010
5011 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5012 VkFramebuffer fb;
5013 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5014 ASSERT_VK_SUCCESS(err);
5015
5016 // Just use default renderpass with our framebuffer
5017 m_renderPassBeginInfo.framebuffer = fb;
5018 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005019 m_commandBuffer->BeginCommandBuffer();
5020 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5021 m_commandBuffer->EndRenderPass();
5022 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005023 // Submit cmd buffer to put it in-flight
5024 VkSubmitInfo submit_info = {};
5025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5026 submit_info.commandBufferCount = 1;
5027 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5028 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5029 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005031 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5032 m_errorMonitor->VerifyFound();
5033 // Wait for queue to complete so we can safely destroy everything
5034 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005035 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5036 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005037 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5038}
5039
Tobin Ehlis88becd72016-09-21 14:33:41 -06005040TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5041 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5042 VkFormatProperties format_properties;
5043 VkResult err = VK_SUCCESS;
5044 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005045
5046 ASSERT_NO_FATAL_FAILURE(InitState());
5047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5048
5049 VkImageCreateInfo image_ci = {};
5050 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5051 image_ci.pNext = NULL;
5052 image_ci.imageType = VK_IMAGE_TYPE_2D;
5053 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5054 image_ci.extent.width = 256;
5055 image_ci.extent.height = 256;
5056 image_ci.extent.depth = 1;
5057 image_ci.mipLevels = 1;
5058 image_ci.arrayLayers = 1;
5059 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5060 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005061 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005062 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5063 image_ci.flags = 0;
5064 VkImage image;
5065 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5066
5067 VkMemoryRequirements memory_reqs;
5068 VkDeviceMemory image_memory;
5069 bool pass;
5070 VkMemoryAllocateInfo memory_info = {};
5071 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5072 memory_info.pNext = NULL;
5073 memory_info.allocationSize = 0;
5074 memory_info.memoryTypeIndex = 0;
5075 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5076 memory_info.allocationSize = memory_reqs.size;
5077 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5078 ASSERT_TRUE(pass);
5079 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5080 ASSERT_VK_SUCCESS(err);
5081 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5082 ASSERT_VK_SUCCESS(err);
5083
5084 VkImageViewCreateInfo ivci = {
5085 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5086 nullptr,
5087 0,
5088 image,
5089 VK_IMAGE_VIEW_TYPE_2D,
5090 VK_FORMAT_B8G8R8A8_UNORM,
5091 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5092 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5093 };
5094 VkImageView view;
5095 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5096 ASSERT_VK_SUCCESS(err);
5097
5098 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5099 VkFramebuffer fb;
5100 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5101 ASSERT_VK_SUCCESS(err);
5102
5103 // Just use default renderpass with our framebuffer
5104 m_renderPassBeginInfo.framebuffer = fb;
5105 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005106 m_commandBuffer->BeginCommandBuffer();
5107 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5108 m_commandBuffer->EndRenderPass();
5109 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005110 // Submit cmd buffer to put it (and attached imageView) in-flight
5111 VkSubmitInfo submit_info = {};
5112 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5113 submit_info.commandBufferCount = 1;
5114 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5115 // Submit cmd buffer to put framebuffer and children in-flight
5116 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5117 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005119 vkDestroyImage(m_device->device(), image, NULL);
5120 m_errorMonitor->VerifyFound();
5121 // Wait for queue to complete so we can safely destroy image and other objects
5122 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005123 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5124 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005125 vkDestroyImage(m_device->device(), image, NULL);
5126 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5127 vkDestroyImageView(m_device->device(), view, nullptr);
5128 vkFreeMemory(m_device->device(), image_memory, nullptr);
5129}
5130
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005131TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5132 TEST_DESCRIPTION("Delete in-use renderPass.");
5133
5134 ASSERT_NO_FATAL_FAILURE(InitState());
5135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5136
5137 // Create simple renderpass
5138 VkAttachmentReference attach = {};
5139 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5140 VkSubpassDescription subpass = {};
5141 subpass.pColorAttachments = &attach;
5142 VkRenderPassCreateInfo rpci = {};
5143 rpci.subpassCount = 1;
5144 rpci.pSubpasses = &subpass;
5145 rpci.attachmentCount = 1;
5146 VkAttachmentDescription attach_desc = {};
5147 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5148 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5149 rpci.pAttachments = &attach_desc;
5150 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5151 VkRenderPass rp;
5152 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5153 ASSERT_VK_SUCCESS(err);
5154
5155 // Create a pipeline that uses the given renderpass
5156 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5157 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5158
5159 VkPipelineLayout pipeline_layout;
5160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5161 ASSERT_VK_SUCCESS(err);
5162
5163 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5164 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5165 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005166 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005167 vp_state_ci.pViewports = &vp;
5168 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005169 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005170 vp_state_ci.pScissors = &scissors;
5171
5172 VkPipelineShaderStageCreateInfo shaderStages[2];
5173 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5174
5175 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005176 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 -06005177 // but add it to be able to run on more devices
5178 shaderStages[0] = vs.GetStageCreateInfo();
5179 shaderStages[1] = fs.GetStageCreateInfo();
5180
5181 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5182 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5183
5184 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5185 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5186 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5187
5188 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5189 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5190 rs_ci.rasterizerDiscardEnable = true;
5191 rs_ci.lineWidth = 1.0f;
5192
5193 VkPipelineColorBlendAttachmentState att = {};
5194 att.blendEnable = VK_FALSE;
5195 att.colorWriteMask = 0xf;
5196
5197 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5198 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5199 cb_ci.attachmentCount = 1;
5200 cb_ci.pAttachments = &att;
5201
5202 VkGraphicsPipelineCreateInfo gp_ci = {};
5203 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5204 gp_ci.stageCount = 2;
5205 gp_ci.pStages = shaderStages;
5206 gp_ci.pVertexInputState = &vi_ci;
5207 gp_ci.pInputAssemblyState = &ia_ci;
5208 gp_ci.pViewportState = &vp_state_ci;
5209 gp_ci.pRasterizationState = &rs_ci;
5210 gp_ci.pColorBlendState = &cb_ci;
5211 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5212 gp_ci.layout = pipeline_layout;
5213 gp_ci.renderPass = rp;
5214
5215 VkPipelineCacheCreateInfo pc_ci = {};
5216 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5217
5218 VkPipeline pipeline;
5219 VkPipelineCache pipe_cache;
5220 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5221 ASSERT_VK_SUCCESS(err);
5222
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005223 m_errorMonitor->SetUnexpectedError(
5224 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5225 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005226 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5227 ASSERT_VK_SUCCESS(err);
5228 // Bind pipeline to cmd buffer, will also bind renderpass
5229 m_commandBuffer->BeginCommandBuffer();
5230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5231 m_commandBuffer->EndCommandBuffer();
5232
5233 VkSubmitInfo submit_info = {};
5234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5235 submit_info.commandBufferCount = 1;
5236 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5238
5239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5240 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5241 m_errorMonitor->VerifyFound();
5242
5243 // Wait for queue to complete so we can safely destroy everything
5244 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005245 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5246 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005247 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5248 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5249 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5250 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5251}
5252
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005253TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005254 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005255 ASSERT_NO_FATAL_FAILURE(InitState());
5256
5257 VkImage image;
5258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5259 VkImageCreateInfo image_create_info = {};
5260 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5261 image_create_info.pNext = NULL;
5262 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5263 image_create_info.format = tex_format;
5264 image_create_info.extent.width = 32;
5265 image_create_info.extent.height = 32;
5266 image_create_info.extent.depth = 1;
5267 image_create_info.mipLevels = 1;
5268 image_create_info.arrayLayers = 1;
5269 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5270 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005271 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005272 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005273 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005274 ASSERT_VK_SUCCESS(err);
5275 // Have to bind memory to image before recording cmd in cmd buffer using it
5276 VkMemoryRequirements mem_reqs;
5277 VkDeviceMemory image_mem;
5278 bool pass;
5279 VkMemoryAllocateInfo mem_alloc = {};
5280 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5281 mem_alloc.pNext = NULL;
5282 mem_alloc.memoryTypeIndex = 0;
5283 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5284 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005285 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005286 ASSERT_TRUE(pass);
5287 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5288 ASSERT_VK_SUCCESS(err);
5289
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005290 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005292 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005293
5294 m_commandBuffer->BeginCommandBuffer();
5295 VkClearColorValue ccv;
5296 ccv.float32[0] = 1.0f;
5297 ccv.float32[1] = 1.0f;
5298 ccv.float32[2] = 1.0f;
5299 ccv.float32[3] = 1.0f;
5300 VkImageSubresourceRange isr = {};
5301 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5302 isr.baseArrayLayer = 0;
5303 isr.baseMipLevel = 0;
5304 isr.layerCount = 1;
5305 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005307 m_commandBuffer->EndCommandBuffer();
5308
5309 m_errorMonitor->VerifyFound();
5310 vkDestroyImage(m_device->device(), image, NULL);
5311 vkFreeMemory(m_device->device(), image_mem, nullptr);
5312}
5313
5314TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005315 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005316 ASSERT_NO_FATAL_FAILURE(InitState());
5317
5318 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005319 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 -06005320 VK_IMAGE_TILING_OPTIMAL, 0);
5321 ASSERT_TRUE(image.initialized());
5322
5323 VkBuffer buffer;
5324 VkDeviceMemory mem;
5325 VkMemoryRequirements mem_reqs;
5326
5327 VkBufferCreateInfo buf_info = {};
5328 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005329 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005330 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005331 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5332 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5333 ASSERT_VK_SUCCESS(err);
5334
5335 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5336
5337 VkMemoryAllocateInfo alloc_info = {};
5338 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005339 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005340 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005341 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 -06005342 if (!pass) {
5343 vkDestroyBuffer(m_device->device(), buffer, NULL);
5344 return;
5345 }
5346 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5347 ASSERT_VK_SUCCESS(err);
5348
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005349 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005351 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005352 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005353 region.bufferRowLength = 16;
5354 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005355 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5356
5357 region.imageSubresource.layerCount = 1;
5358 region.imageExtent.height = 4;
5359 region.imageExtent.width = 4;
5360 region.imageExtent.depth = 1;
5361 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005362 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5363 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005364 m_commandBuffer->EndCommandBuffer();
5365
5366 m_errorMonitor->VerifyFound();
5367
5368 vkDestroyBuffer(m_device->device(), buffer, NULL);
5369 vkFreeMemory(m_device->handle(), mem, NULL);
5370}
5371
Tobin Ehlis85940f52016-07-07 16:57:21 -06005372TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005373 TEST_DESCRIPTION(
5374 "Attempt to draw with a command buffer that is invalid "
5375 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005376 ASSERT_NO_FATAL_FAILURE(InitState());
5377
5378 VkEvent event;
5379 VkEventCreateInfo evci = {};
5380 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5381 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5382 ASSERT_VK_SUCCESS(result);
5383
5384 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005385 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005386 m_commandBuffer->EndCommandBuffer();
5387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005389 // Destroy event dependency prior to submit to cause ERROR
5390 vkDestroyEvent(m_device->device(), event, NULL);
5391
5392 VkSubmitInfo submit_info = {};
5393 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5394 submit_info.commandBufferCount = 1;
5395 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005396 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005397 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5398
5399 m_errorMonitor->VerifyFound();
5400}
5401
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005402TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005403 TEST_DESCRIPTION(
5404 "Attempt to draw with a command buffer that is invalid "
5405 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005406 ASSERT_NO_FATAL_FAILURE(InitState());
5407
5408 VkQueryPool query_pool;
5409 VkQueryPoolCreateInfo qpci{};
5410 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5411 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5412 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005414 ASSERT_VK_SUCCESS(result);
5415
5416 m_commandBuffer->BeginCommandBuffer();
5417 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5418 m_commandBuffer->EndCommandBuffer();
5419
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005421 // Destroy query pool dependency prior to submit to cause ERROR
5422 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5423
5424 VkSubmitInfo submit_info = {};
5425 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5426 submit_info.commandBufferCount = 1;
5427 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005428 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005429 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5430
5431 m_errorMonitor->VerifyFound();
5432}
5433
Tobin Ehlis24130d92016-07-08 15:50:53 -06005434TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005435 TEST_DESCRIPTION(
5436 "Attempt to draw with a command buffer that is invalid "
5437 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005438 ASSERT_NO_FATAL_FAILURE(InitState());
5439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5440
5441 VkResult err;
5442
5443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5445
5446 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005448 ASSERT_VK_SUCCESS(err);
5449
5450 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5451 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5452 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005453 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005454 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005455 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005456 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005457 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005458
5459 VkPipelineShaderStageCreateInfo shaderStages[2];
5460 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005462 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005463 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 -06005464 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005465 shaderStages[0] = vs.GetStageCreateInfo();
5466 shaderStages[1] = fs.GetStageCreateInfo();
5467
5468 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5469 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5470
5471 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5472 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5473 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5474
5475 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5476 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005477 rs_ci.rasterizerDiscardEnable = true;
5478 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005479
5480 VkPipelineColorBlendAttachmentState att = {};
5481 att.blendEnable = VK_FALSE;
5482 att.colorWriteMask = 0xf;
5483
5484 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5485 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5486 cb_ci.attachmentCount = 1;
5487 cb_ci.pAttachments = &att;
5488
5489 VkGraphicsPipelineCreateInfo gp_ci = {};
5490 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5491 gp_ci.stageCount = 2;
5492 gp_ci.pStages = shaderStages;
5493 gp_ci.pVertexInputState = &vi_ci;
5494 gp_ci.pInputAssemblyState = &ia_ci;
5495 gp_ci.pViewportState = &vp_state_ci;
5496 gp_ci.pRasterizationState = &rs_ci;
5497 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005498 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5499 gp_ci.layout = pipeline_layout;
5500 gp_ci.renderPass = renderPass();
5501
5502 VkPipelineCacheCreateInfo pc_ci = {};
5503 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5504
5505 VkPipeline pipeline;
5506 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005508 ASSERT_VK_SUCCESS(err);
5509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 ASSERT_VK_SUCCESS(err);
5512
5513 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005515 m_commandBuffer->EndCommandBuffer();
5516 // Now destroy pipeline in order to cause error when submitting
5517 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005520
5521 VkSubmitInfo submit_info = {};
5522 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5523 submit_info.commandBufferCount = 1;
5524 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005525 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5527
5528 m_errorMonitor->VerifyFound();
5529 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5530 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5531}
5532
Tobin Ehlis31289162016-08-17 14:57:58 -06005533TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005534 TEST_DESCRIPTION(
5535 "Attempt to draw with a command buffer that is invalid "
5536 "due to a bound descriptor set with a buffer dependency "
5537 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005538 ASSERT_NO_FATAL_FAILURE(InitState());
5539 ASSERT_NO_FATAL_FAILURE(InitViewport());
5540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5541
5542 VkDescriptorPoolSize ds_type_count = {};
5543 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5544 ds_type_count.descriptorCount = 1;
5545
5546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5548 ds_pool_ci.pNext = NULL;
5549 ds_pool_ci.maxSets = 1;
5550 ds_pool_ci.poolSizeCount = 1;
5551 ds_pool_ci.pPoolSizes = &ds_type_count;
5552
5553 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005554 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005555 ASSERT_VK_SUCCESS(err);
5556
5557 VkDescriptorSetLayoutBinding dsl_binding = {};
5558 dsl_binding.binding = 0;
5559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5560 dsl_binding.descriptorCount = 1;
5561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5562 dsl_binding.pImmutableSamplers = NULL;
5563
5564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5566 ds_layout_ci.pNext = NULL;
5567 ds_layout_ci.bindingCount = 1;
5568 ds_layout_ci.pBindings = &dsl_binding;
5569 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005571 ASSERT_VK_SUCCESS(err);
5572
5573 VkDescriptorSet descriptorSet;
5574 VkDescriptorSetAllocateInfo alloc_info = {};
5575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5576 alloc_info.descriptorSetCount = 1;
5577 alloc_info.descriptorPool = ds_pool;
5578 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005580 ASSERT_VK_SUCCESS(err);
5581
5582 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5583 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5584 pipeline_layout_ci.pNext = NULL;
5585 pipeline_layout_ci.setLayoutCount = 1;
5586 pipeline_layout_ci.pSetLayouts = &ds_layout;
5587
5588 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005589 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_VK_SUCCESS(err);
5591
5592 // Create a buffer to update the descriptor with
5593 uint32_t qfi = 0;
5594 VkBufferCreateInfo buffCI = {};
5595 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5596 buffCI.size = 1024;
5597 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5598 buffCI.queueFamilyIndexCount = 1;
5599 buffCI.pQueueFamilyIndices = &qfi;
5600
5601 VkBuffer buffer;
5602 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5603 ASSERT_VK_SUCCESS(err);
5604 // Allocate memory and bind to buffer so we can make it to the appropriate
5605 // error
5606 VkMemoryAllocateInfo mem_alloc = {};
5607 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5608 mem_alloc.pNext = NULL;
5609 mem_alloc.allocationSize = 1024;
5610 mem_alloc.memoryTypeIndex = 0;
5611
5612 VkMemoryRequirements memReqs;
5613 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 if (!pass) {
5616 vkDestroyBuffer(m_device->device(), buffer, NULL);
5617 return;
5618 }
5619
5620 VkDeviceMemory mem;
5621 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5622 ASSERT_VK_SUCCESS(err);
5623 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5624 ASSERT_VK_SUCCESS(err);
5625 // Correctly update descriptor to avoid "NOT_UPDATED" error
5626 VkDescriptorBufferInfo buffInfo = {};
5627 buffInfo.buffer = buffer;
5628 buffInfo.offset = 0;
5629 buffInfo.range = 1024;
5630
5631 VkWriteDescriptorSet descriptor_write;
5632 memset(&descriptor_write, 0, sizeof(descriptor_write));
5633 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5634 descriptor_write.dstSet = descriptorSet;
5635 descriptor_write.dstBinding = 0;
5636 descriptor_write.descriptorCount = 1;
5637 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5638 descriptor_write.pBufferInfo = &buffInfo;
5639
5640 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5641
5642 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005643 char const *vsSource =
5644 "#version 450\n"
5645 "\n"
5646 "out gl_PerVertex { \n"
5647 " vec4 gl_Position;\n"
5648 "};\n"
5649 "void main(){\n"
5650 " gl_Position = vec4(1);\n"
5651 "}\n";
5652 char const *fsSource =
5653 "#version 450\n"
5654 "\n"
5655 "layout(location=0) out vec4 x;\n"
5656 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5657 "void main(){\n"
5658 " x = vec4(bar.y);\n"
5659 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5662 VkPipelineObj pipe(m_device);
5663 pipe.AddShader(&vs);
5664 pipe.AddShader(&fs);
5665 pipe.AddColorAttachment();
5666 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5667
Tony Barbour552f6c02016-12-21 14:34:07 -07005668 m_commandBuffer->BeginCommandBuffer();
5669 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5671 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5672 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005673
5674 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5675 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5676
Tobin Ehlis31289162016-08-17 14:57:58 -06005677 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005678 m_commandBuffer->EndRenderPass();
5679 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005681 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5682 vkDestroyBuffer(m_device->device(), buffer, NULL);
5683 // Attempt to submit cmd buffer
5684 VkSubmitInfo submit_info = {};
5685 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5686 submit_info.commandBufferCount = 1;
5687 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005688 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005689 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5690 m_errorMonitor->VerifyFound();
5691 // Cleanup
5692 vkFreeMemory(m_device->device(), mem, NULL);
5693
5694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5697}
5698
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005699TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005700 TEST_DESCRIPTION(
5701 "Attempt to draw with a command buffer that is invalid "
5702 "due to a bound descriptor sets with a combined image "
5703 "sampler having their image, sampler, and descriptor set "
5704 "each respectively destroyed and then attempting to "
5705 "submit associated cmd buffers. Attempt to destroy a "
5706 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005707 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005708 ASSERT_NO_FATAL_FAILURE(InitViewport());
5709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5710
5711 VkDescriptorPoolSize ds_type_count = {};
5712 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5713 ds_type_count.descriptorCount = 1;
5714
5715 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5716 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5717 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005718 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005719 ds_pool_ci.maxSets = 1;
5720 ds_pool_ci.poolSizeCount = 1;
5721 ds_pool_ci.pPoolSizes = &ds_type_count;
5722
5723 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005725 ASSERT_VK_SUCCESS(err);
5726
5727 VkDescriptorSetLayoutBinding dsl_binding = {};
5728 dsl_binding.binding = 0;
5729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5730 dsl_binding.descriptorCount = 1;
5731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5732 dsl_binding.pImmutableSamplers = NULL;
5733
5734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5736 ds_layout_ci.pNext = NULL;
5737 ds_layout_ci.bindingCount = 1;
5738 ds_layout_ci.pBindings = &dsl_binding;
5739 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005740 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005741 ASSERT_VK_SUCCESS(err);
5742
5743 VkDescriptorSet descriptorSet;
5744 VkDescriptorSetAllocateInfo alloc_info = {};
5745 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5746 alloc_info.descriptorSetCount = 1;
5747 alloc_info.descriptorPool = ds_pool;
5748 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005749 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005750 ASSERT_VK_SUCCESS(err);
5751
5752 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5753 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5754 pipeline_layout_ci.pNext = NULL;
5755 pipeline_layout_ci.setLayoutCount = 1;
5756 pipeline_layout_ci.pSetLayouts = &ds_layout;
5757
5758 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005759 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005760 ASSERT_VK_SUCCESS(err);
5761
5762 // Create images to update the descriptor with
5763 VkImage image;
5764 VkImage image2;
5765 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5766 const int32_t tex_width = 32;
5767 const int32_t tex_height = 32;
5768 VkImageCreateInfo image_create_info = {};
5769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5770 image_create_info.pNext = NULL;
5771 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5772 image_create_info.format = tex_format;
5773 image_create_info.extent.width = tex_width;
5774 image_create_info.extent.height = tex_height;
5775 image_create_info.extent.depth = 1;
5776 image_create_info.mipLevels = 1;
5777 image_create_info.arrayLayers = 1;
5778 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5779 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5780 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5781 image_create_info.flags = 0;
5782 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5783 ASSERT_VK_SUCCESS(err);
5784 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5785 ASSERT_VK_SUCCESS(err);
5786
5787 VkMemoryRequirements memory_reqs;
5788 VkDeviceMemory image_memory;
5789 bool pass;
5790 VkMemoryAllocateInfo memory_info = {};
5791 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5792 memory_info.pNext = NULL;
5793 memory_info.allocationSize = 0;
5794 memory_info.memoryTypeIndex = 0;
5795 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5796 // Allocate enough memory for both images
5797 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005798 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005799 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005801 ASSERT_VK_SUCCESS(err);
5802 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5803 ASSERT_VK_SUCCESS(err);
5804 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005805 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005806 ASSERT_VK_SUCCESS(err);
5807
5808 VkImageViewCreateInfo image_view_create_info = {};
5809 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5810 image_view_create_info.image = image;
5811 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5812 image_view_create_info.format = tex_format;
5813 image_view_create_info.subresourceRange.layerCount = 1;
5814 image_view_create_info.subresourceRange.baseMipLevel = 0;
5815 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005816 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005817
5818 VkImageView view;
5819 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005820 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005821 ASSERT_VK_SUCCESS(err);
5822 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005823 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005824 ASSERT_VK_SUCCESS(err);
5825 // Create Samplers
5826 VkSamplerCreateInfo sampler_ci = {};
5827 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5828 sampler_ci.pNext = NULL;
5829 sampler_ci.magFilter = VK_FILTER_NEAREST;
5830 sampler_ci.minFilter = VK_FILTER_NEAREST;
5831 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5832 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5833 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5834 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5835 sampler_ci.mipLodBias = 1.0;
5836 sampler_ci.anisotropyEnable = VK_FALSE;
5837 sampler_ci.maxAnisotropy = 1;
5838 sampler_ci.compareEnable = VK_FALSE;
5839 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5840 sampler_ci.minLod = 1.0;
5841 sampler_ci.maxLod = 1.0;
5842 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5843 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5844 VkSampler sampler;
5845 VkSampler sampler2;
5846 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5847 ASSERT_VK_SUCCESS(err);
5848 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5849 ASSERT_VK_SUCCESS(err);
5850 // Update descriptor with image and sampler
5851 VkDescriptorImageInfo img_info = {};
5852 img_info.sampler = sampler;
5853 img_info.imageView = view;
5854 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5855
5856 VkWriteDescriptorSet descriptor_write;
5857 memset(&descriptor_write, 0, sizeof(descriptor_write));
5858 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5859 descriptor_write.dstSet = descriptorSet;
5860 descriptor_write.dstBinding = 0;
5861 descriptor_write.descriptorCount = 1;
5862 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5863 descriptor_write.pImageInfo = &img_info;
5864
5865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5866
5867 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005868 char const *vsSource =
5869 "#version 450\n"
5870 "\n"
5871 "out gl_PerVertex { \n"
5872 " vec4 gl_Position;\n"
5873 "};\n"
5874 "void main(){\n"
5875 " gl_Position = vec4(1);\n"
5876 "}\n";
5877 char const *fsSource =
5878 "#version 450\n"
5879 "\n"
5880 "layout(set=0, binding=0) uniform sampler2D s;\n"
5881 "layout(location=0) out vec4 x;\n"
5882 "void main(){\n"
5883 " x = texture(s, vec2(1));\n"
5884 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5887 VkPipelineObj pipe(m_device);
5888 pipe.AddShader(&vs);
5889 pipe.AddShader(&fs);
5890 pipe.AddColorAttachment();
5891 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5892
5893 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005895 m_commandBuffer->BeginCommandBuffer();
5896 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005897 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5899 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005900 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5901 VkRect2D scissor = {{0, 0}, {16, 16}};
5902 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5903 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005904 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005905 m_commandBuffer->EndRenderPass();
5906 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005907 // Destroy sampler invalidates the cmd buffer, causing error on submit
5908 vkDestroySampler(m_device->device(), sampler, NULL);
5909 // Attempt to submit cmd buffer
5910 VkSubmitInfo submit_info = {};
5911 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5912 submit_info.commandBufferCount = 1;
5913 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005914 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005915 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5916 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005917
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005918 // Now re-update descriptor with valid sampler and delete image
5919 img_info.sampler = sampler2;
5920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005921
5922 VkCommandBufferBeginInfo info = {};
5923 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5924 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005927 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005929 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5930 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5931 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005932 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5933 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005934 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005935 m_commandBuffer->EndRenderPass();
5936 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005937 // Destroy image invalidates the cmd buffer, causing error on submit
5938 vkDestroyImage(m_device->device(), image, NULL);
5939 // Attempt to submit cmd buffer
5940 submit_info = {};
5941 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5942 submit_info.commandBufferCount = 1;
5943 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005944 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005945 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5946 m_errorMonitor->VerifyFound();
5947 // Now update descriptor to be valid, but then free descriptor
5948 img_info.imageView = view2;
5949 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005950 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005951 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005952 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5953 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5954 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005955 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5956 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005957 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005958 m_commandBuffer->EndRenderPass();
5959 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005961
5962 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005964 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005965 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005966
5967 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005968 // 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 -07005969 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005970 m_errorMonitor->SetUnexpectedError(
5971 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5972 "either be a valid handle or VK_NULL_HANDLE");
5973 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005974 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5975
5976 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005977 submit_info = {};
5978 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5979 submit_info.commandBufferCount = 1;
5980 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005982 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005983 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5984 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005985
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005986 // Cleanup
5987 vkFreeMemory(m_device->device(), image_memory, NULL);
5988 vkDestroySampler(m_device->device(), sampler2, NULL);
5989 vkDestroyImage(m_device->device(), image2, NULL);
5990 vkDestroyImageView(m_device->device(), view, NULL);
5991 vkDestroyImageView(m_device->device(), view2, NULL);
5992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5995}
5996
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005997TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5998 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5999 ASSERT_NO_FATAL_FAILURE(InitState());
6000 ASSERT_NO_FATAL_FAILURE(InitViewport());
6001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6002
6003 VkDescriptorPoolSize ds_type_count = {};
6004 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6005 ds_type_count.descriptorCount = 1;
6006
6007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6009 ds_pool_ci.pNext = NULL;
6010 ds_pool_ci.maxSets = 1;
6011 ds_pool_ci.poolSizeCount = 1;
6012 ds_pool_ci.pPoolSizes = &ds_type_count;
6013
6014 VkDescriptorPool ds_pool;
6015 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6016 ASSERT_VK_SUCCESS(err);
6017
6018 VkDescriptorSetLayoutBinding dsl_binding = {};
6019 dsl_binding.binding = 0;
6020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6021 dsl_binding.descriptorCount = 1;
6022 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6023 dsl_binding.pImmutableSamplers = NULL;
6024
6025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6026 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6027 ds_layout_ci.pNext = NULL;
6028 ds_layout_ci.bindingCount = 1;
6029 ds_layout_ci.pBindings = &dsl_binding;
6030 VkDescriptorSetLayout ds_layout;
6031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6032 ASSERT_VK_SUCCESS(err);
6033
6034 VkDescriptorSet descriptor_set;
6035 VkDescriptorSetAllocateInfo alloc_info = {};
6036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6037 alloc_info.descriptorSetCount = 1;
6038 alloc_info.descriptorPool = ds_pool;
6039 alloc_info.pSetLayouts = &ds_layout;
6040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6041 ASSERT_VK_SUCCESS(err);
6042
6043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6045 pipeline_layout_ci.pNext = NULL;
6046 pipeline_layout_ci.setLayoutCount = 1;
6047 pipeline_layout_ci.pSetLayouts = &ds_layout;
6048
6049 VkPipelineLayout pipeline_layout;
6050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6051 ASSERT_VK_SUCCESS(err);
6052
6053 // Create image to update the descriptor with
6054 VkImageObj image(m_device);
6055 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6056 ASSERT_TRUE(image.initialized());
6057
6058 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6059 // Create Sampler
6060 VkSamplerCreateInfo sampler_ci = {};
6061 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6062 sampler_ci.pNext = NULL;
6063 sampler_ci.magFilter = VK_FILTER_NEAREST;
6064 sampler_ci.minFilter = VK_FILTER_NEAREST;
6065 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6066 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6067 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6068 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6069 sampler_ci.mipLodBias = 1.0;
6070 sampler_ci.anisotropyEnable = VK_FALSE;
6071 sampler_ci.maxAnisotropy = 1;
6072 sampler_ci.compareEnable = VK_FALSE;
6073 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6074 sampler_ci.minLod = 1.0;
6075 sampler_ci.maxLod = 1.0;
6076 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6077 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6078 VkSampler sampler;
6079 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6080 ASSERT_VK_SUCCESS(err);
6081 // Update descriptor with image and sampler
6082 VkDescriptorImageInfo img_info = {};
6083 img_info.sampler = sampler;
6084 img_info.imageView = view;
6085 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6086
6087 VkWriteDescriptorSet descriptor_write;
6088 memset(&descriptor_write, 0, sizeof(descriptor_write));
6089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6090 descriptor_write.dstSet = descriptor_set;
6091 descriptor_write.dstBinding = 0;
6092 descriptor_write.descriptorCount = 1;
6093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6094 descriptor_write.pImageInfo = &img_info;
6095
6096 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6097
6098 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006099 char const *vsSource =
6100 "#version 450\n"
6101 "\n"
6102 "out gl_PerVertex { \n"
6103 " vec4 gl_Position;\n"
6104 "};\n"
6105 "void main(){\n"
6106 " gl_Position = vec4(1);\n"
6107 "}\n";
6108 char const *fsSource =
6109 "#version 450\n"
6110 "\n"
6111 "layout(set=0, binding=0) uniform sampler2D s;\n"
6112 "layout(location=0) out vec4 x;\n"
6113 "void main(){\n"
6114 " x = texture(s, vec2(1));\n"
6115 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006116 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6117 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6118 VkPipelineObj pipe(m_device);
6119 pipe.AddShader(&vs);
6120 pipe.AddShader(&fs);
6121 pipe.AddColorAttachment();
6122 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6123
Tony Barbour552f6c02016-12-21 14:34:07 -07006124 m_commandBuffer->BeginCommandBuffer();
6125 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006126 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6127 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6128 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006129
6130 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6131 VkRect2D scissor = {{0, 0}, {16, 16}};
6132 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6133 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6134
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006135 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006136 m_commandBuffer->EndRenderPass();
6137 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006138 // Submit cmd buffer to put pool in-flight
6139 VkSubmitInfo submit_info = {};
6140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6141 submit_info.commandBufferCount = 1;
6142 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6144 // Destroy pool while in-flight, causing error
6145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6147 m_errorMonitor->VerifyFound();
6148 vkQueueWaitIdle(m_device->m_queue);
6149 // Cleanup
6150 vkDestroySampler(m_device->device(), sampler, NULL);
6151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006153 m_errorMonitor->SetUnexpectedError(
6154 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6155 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006156 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006157 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006158}
6159
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006160TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6161 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6162 ASSERT_NO_FATAL_FAILURE(InitState());
6163 ASSERT_NO_FATAL_FAILURE(InitViewport());
6164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6165
6166 VkDescriptorPoolSize ds_type_count = {};
6167 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6168 ds_type_count.descriptorCount = 1;
6169
6170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6172 ds_pool_ci.pNext = NULL;
6173 ds_pool_ci.maxSets = 1;
6174 ds_pool_ci.poolSizeCount = 1;
6175 ds_pool_ci.pPoolSizes = &ds_type_count;
6176
6177 VkDescriptorPool ds_pool;
6178 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6179 ASSERT_VK_SUCCESS(err);
6180
6181 VkDescriptorSetLayoutBinding dsl_binding = {};
6182 dsl_binding.binding = 0;
6183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6184 dsl_binding.descriptorCount = 1;
6185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6186 dsl_binding.pImmutableSamplers = NULL;
6187
6188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6189 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6190 ds_layout_ci.pNext = NULL;
6191 ds_layout_ci.bindingCount = 1;
6192 ds_layout_ci.pBindings = &dsl_binding;
6193 VkDescriptorSetLayout ds_layout;
6194 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6195 ASSERT_VK_SUCCESS(err);
6196
6197 VkDescriptorSet descriptorSet;
6198 VkDescriptorSetAllocateInfo alloc_info = {};
6199 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6200 alloc_info.descriptorSetCount = 1;
6201 alloc_info.descriptorPool = ds_pool;
6202 alloc_info.pSetLayouts = &ds_layout;
6203 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6204 ASSERT_VK_SUCCESS(err);
6205
6206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6207 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6208 pipeline_layout_ci.pNext = NULL;
6209 pipeline_layout_ci.setLayoutCount = 1;
6210 pipeline_layout_ci.pSetLayouts = &ds_layout;
6211
6212 VkPipelineLayout pipeline_layout;
6213 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6214 ASSERT_VK_SUCCESS(err);
6215
6216 // Create images to update the descriptor with
6217 VkImage image;
6218 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6219 const int32_t tex_width = 32;
6220 const int32_t tex_height = 32;
6221 VkImageCreateInfo image_create_info = {};
6222 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6223 image_create_info.pNext = NULL;
6224 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6225 image_create_info.format = tex_format;
6226 image_create_info.extent.width = tex_width;
6227 image_create_info.extent.height = tex_height;
6228 image_create_info.extent.depth = 1;
6229 image_create_info.mipLevels = 1;
6230 image_create_info.arrayLayers = 1;
6231 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6232 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6233 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6234 image_create_info.flags = 0;
6235 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6236 ASSERT_VK_SUCCESS(err);
6237 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6238 VkMemoryRequirements memory_reqs;
6239 VkDeviceMemory image_memory;
6240 bool pass;
6241 VkMemoryAllocateInfo memory_info = {};
6242 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6243 memory_info.pNext = NULL;
6244 memory_info.allocationSize = 0;
6245 memory_info.memoryTypeIndex = 0;
6246 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6247 // Allocate enough memory for image
6248 memory_info.allocationSize = memory_reqs.size;
6249 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6250 ASSERT_TRUE(pass);
6251 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6252 ASSERT_VK_SUCCESS(err);
6253 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6254 ASSERT_VK_SUCCESS(err);
6255
6256 VkImageViewCreateInfo image_view_create_info = {};
6257 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6258 image_view_create_info.image = image;
6259 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6260 image_view_create_info.format = tex_format;
6261 image_view_create_info.subresourceRange.layerCount = 1;
6262 image_view_create_info.subresourceRange.baseMipLevel = 0;
6263 image_view_create_info.subresourceRange.levelCount = 1;
6264 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6265
6266 VkImageView view;
6267 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6268 ASSERT_VK_SUCCESS(err);
6269 // Create Samplers
6270 VkSamplerCreateInfo sampler_ci = {};
6271 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6272 sampler_ci.pNext = NULL;
6273 sampler_ci.magFilter = VK_FILTER_NEAREST;
6274 sampler_ci.minFilter = VK_FILTER_NEAREST;
6275 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6276 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6277 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6278 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6279 sampler_ci.mipLodBias = 1.0;
6280 sampler_ci.anisotropyEnable = VK_FALSE;
6281 sampler_ci.maxAnisotropy = 1;
6282 sampler_ci.compareEnable = VK_FALSE;
6283 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6284 sampler_ci.minLod = 1.0;
6285 sampler_ci.maxLod = 1.0;
6286 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6287 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6288 VkSampler sampler;
6289 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6290 ASSERT_VK_SUCCESS(err);
6291 // Update descriptor with image and sampler
6292 VkDescriptorImageInfo img_info = {};
6293 img_info.sampler = sampler;
6294 img_info.imageView = view;
6295 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6296
6297 VkWriteDescriptorSet descriptor_write;
6298 memset(&descriptor_write, 0, sizeof(descriptor_write));
6299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6300 descriptor_write.dstSet = descriptorSet;
6301 descriptor_write.dstBinding = 0;
6302 descriptor_write.descriptorCount = 1;
6303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6304 descriptor_write.pImageInfo = &img_info;
6305 // Break memory binding and attempt update
6306 vkFreeMemory(m_device->device(), image_memory, nullptr);
6307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006308 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6310 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6311 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6312 m_errorMonitor->VerifyFound();
6313 // Cleanup
6314 vkDestroyImage(m_device->device(), image, NULL);
6315 vkDestroySampler(m_device->device(), sampler, NULL);
6316 vkDestroyImageView(m_device->device(), view, NULL);
6317 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6319 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6320}
6321
Karl Schultz6addd812016-02-02 17:17:23 -07006322TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006323 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6324 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006325 // Create a valid cmd buffer
6326 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006327 uint64_t fake_pipeline_handle = 0xbaad6001;
6328 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006329 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6331
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006333 m_commandBuffer->BeginCommandBuffer();
6334 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006335 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006336 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006337
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006338 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006339 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 -06006340 Draw(1, 0, 0, 0);
6341 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006342
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006343 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 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 -07006345 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006346 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6347 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006348}
6349
Karl Schultz6addd812016-02-02 17:17:23 -07006350TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006351 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006352 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006353
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006355
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006356 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006357 ASSERT_NO_FATAL_FAILURE(InitViewport());
6358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006359 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006360 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006362
6363 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006364 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6365 ds_pool_ci.pNext = NULL;
6366 ds_pool_ci.maxSets = 1;
6367 ds_pool_ci.poolSizeCount = 1;
6368 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006369
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006370 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006371 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006372 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006373
Tony Barboureb254902015-07-15 12:50:33 -06006374 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006375 dsl_binding.binding = 0;
6376 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6377 dsl_binding.descriptorCount = 1;
6378 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6379 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006380
Tony Barboureb254902015-07-15 12:50:33 -06006381 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6383 ds_layout_ci.pNext = NULL;
6384 ds_layout_ci.bindingCount = 1;
6385 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006386 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006387 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006388 ASSERT_VK_SUCCESS(err);
6389
6390 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006391 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006392 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006393 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006394 alloc_info.descriptorPool = ds_pool;
6395 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006397 ASSERT_VK_SUCCESS(err);
6398
Tony Barboureb254902015-07-15 12:50:33 -06006399 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006400 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6401 pipeline_layout_ci.pNext = NULL;
6402 pipeline_layout_ci.setLayoutCount = 1;
6403 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
6405 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006407 ASSERT_VK_SUCCESS(err);
6408
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006410 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006411 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006412 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006413
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006414 VkPipelineObj pipe(m_device);
6415 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006416 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006417 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006419
Tony Barbour552f6c02016-12-21 14:34:07 -07006420 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6423 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006424
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006425 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006426
Chia-I Wuf7458c52015-10-26 21:10:41 +08006427 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006430}
6431
Karl Schultz6addd812016-02-02 17:17:23 -07006432TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006433 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006434 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006437
6438 ASSERT_NO_FATAL_FAILURE(InitState());
6439 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006440 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6441 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006442
6443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6445 ds_pool_ci.pNext = NULL;
6446 ds_pool_ci.maxSets = 1;
6447 ds_pool_ci.poolSizeCount = 1;
6448 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006449
6450 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006451 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006452 ASSERT_VK_SUCCESS(err);
6453
6454 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006455 dsl_binding.binding = 0;
6456 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6457 dsl_binding.descriptorCount = 1;
6458 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6459 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006460
6461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6463 ds_layout_ci.pNext = NULL;
6464 ds_layout_ci.bindingCount = 1;
6465 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006468 ASSERT_VK_SUCCESS(err);
6469
6470 VkDescriptorSet descriptorSet;
6471 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006473 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006474 alloc_info.descriptorPool = ds_pool;
6475 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006476 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006477 ASSERT_VK_SUCCESS(err);
6478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006479 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006480 VkWriteDescriptorSet descriptor_write;
6481 memset(&descriptor_write, 0, sizeof(descriptor_write));
6482 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6483 descriptor_write.dstSet = descriptorSet;
6484 descriptor_write.dstBinding = 0;
6485 descriptor_write.descriptorCount = 1;
6486 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6487 descriptor_write.pTexelBufferView = &view;
6488
6489 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6490
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006491 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006492
6493 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6494 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6495}
6496
Mark Youngd339ba32016-05-30 13:28:35 -06006497TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006498 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 -06006499
6500 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006502 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006503
6504 ASSERT_NO_FATAL_FAILURE(InitState());
6505
6506 // Create a buffer with no bound memory and then attempt to create
6507 // a buffer view.
6508 VkBufferCreateInfo buff_ci = {};
6509 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006510 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006511 buff_ci.size = 256;
6512 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6513 VkBuffer buffer;
6514 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6515 ASSERT_VK_SUCCESS(err);
6516
6517 VkBufferViewCreateInfo buff_view_ci = {};
6518 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6519 buff_view_ci.buffer = buffer;
6520 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6521 buff_view_ci.range = VK_WHOLE_SIZE;
6522 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006523 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006524
6525 m_errorMonitor->VerifyFound();
6526 vkDestroyBuffer(m_device->device(), buffer, NULL);
6527 // If last error is success, it still created the view, so delete it.
6528 if (err == VK_SUCCESS) {
6529 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6530 }
6531}
6532
Karl Schultz6addd812016-02-02 17:17:23 -07006533TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6534 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6535 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006536 // 1. No dynamicOffset supplied
6537 // 2. Too many dynamicOffsets supplied
6538 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006539 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6541 " requires 1 dynamicOffsets, but only "
6542 "0 dynamicOffsets are left in "
6543 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006544
6545 ASSERT_NO_FATAL_FAILURE(InitState());
6546 ASSERT_NO_FATAL_FAILURE(InitViewport());
6547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6548
6549 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006550 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6551 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006552
6553 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006554 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6555 ds_pool_ci.pNext = NULL;
6556 ds_pool_ci.maxSets = 1;
6557 ds_pool_ci.poolSizeCount = 1;
6558 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006559
6560 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006561 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006562 ASSERT_VK_SUCCESS(err);
6563
6564 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006565 dsl_binding.binding = 0;
6566 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6567 dsl_binding.descriptorCount = 1;
6568 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6569 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006570
6571 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006572 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6573 ds_layout_ci.pNext = NULL;
6574 ds_layout_ci.bindingCount = 1;
6575 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006576 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006578 ASSERT_VK_SUCCESS(err);
6579
6580 VkDescriptorSet descriptorSet;
6581 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006583 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006584 alloc_info.descriptorPool = ds_pool;
6585 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006587 ASSERT_VK_SUCCESS(err);
6588
6589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6591 pipeline_layout_ci.pNext = NULL;
6592 pipeline_layout_ci.setLayoutCount = 1;
6593 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006594
6595 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006597 ASSERT_VK_SUCCESS(err);
6598
6599 // Create a buffer to update the descriptor with
6600 uint32_t qfi = 0;
6601 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006602 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6603 buffCI.size = 1024;
6604 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6605 buffCI.queueFamilyIndexCount = 1;
6606 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006607
6608 VkBuffer dyub;
6609 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6610 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006611 // Allocate memory and bind to buffer so we can make it to the appropriate
6612 // error
6613 VkMemoryAllocateInfo mem_alloc = {};
6614 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6615 mem_alloc.pNext = NULL;
6616 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006617 mem_alloc.memoryTypeIndex = 0;
6618
6619 VkMemoryRequirements memReqs;
6620 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006622 if (!pass) {
6623 vkDestroyBuffer(m_device->device(), dyub, NULL);
6624 return;
6625 }
6626
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006627 VkDeviceMemory mem;
6628 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6629 ASSERT_VK_SUCCESS(err);
6630 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006632 // Correctly update descriptor to avoid "NOT_UPDATED" error
6633 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006634 buffInfo.buffer = dyub;
6635 buffInfo.offset = 0;
6636 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006637
6638 VkWriteDescriptorSet descriptor_write;
6639 memset(&descriptor_write, 0, sizeof(descriptor_write));
6640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6641 descriptor_write.dstSet = descriptorSet;
6642 descriptor_write.dstBinding = 0;
6643 descriptor_write.descriptorCount = 1;
6644 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6645 descriptor_write.pBufferInfo = &buffInfo;
6646
6647 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6648
Tony Barbour552f6c02016-12-21 14:34:07 -07006649 m_commandBuffer->BeginCommandBuffer();
6650 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6652 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006653 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006654 uint32_t pDynOff[2] = {512, 756};
6655 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6657 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6658 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6659 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006660 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006661 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6663 " dynamic offset 512 combined with "
6664 "offset 0 and range 1024 that "
6665 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006666 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006667 char const *vsSource =
6668 "#version 450\n"
6669 "\n"
6670 "out gl_PerVertex { \n"
6671 " vec4 gl_Position;\n"
6672 "};\n"
6673 "void main(){\n"
6674 " gl_Position = vec4(1);\n"
6675 "}\n";
6676 char const *fsSource =
6677 "#version 450\n"
6678 "\n"
6679 "layout(location=0) out vec4 x;\n"
6680 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6681 "void main(){\n"
6682 " x = vec4(bar.y);\n"
6683 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006684 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6685 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6686 VkPipelineObj pipe(m_device);
6687 pipe.AddShader(&vs);
6688 pipe.AddShader(&fs);
6689 pipe.AddColorAttachment();
6690 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6691
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006692 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6693 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6694 VkRect2D scissor = {{0, 0}, {16, 16}};
6695 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6696
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006698 // This update should succeed, but offset size of 512 will overstep buffer
6699 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6701 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006702 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006703 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006704
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006705 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006706 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006707
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006708 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006710 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6711}
6712
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006713TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006714 TEST_DESCRIPTION(
6715 "Attempt to update a descriptor with a non-sparse buffer "
6716 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006717 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006719 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6721 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006722
6723 ASSERT_NO_FATAL_FAILURE(InitState());
6724 ASSERT_NO_FATAL_FAILURE(InitViewport());
6725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6726
6727 VkDescriptorPoolSize ds_type_count = {};
6728 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6729 ds_type_count.descriptorCount = 1;
6730
6731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6733 ds_pool_ci.pNext = NULL;
6734 ds_pool_ci.maxSets = 1;
6735 ds_pool_ci.poolSizeCount = 1;
6736 ds_pool_ci.pPoolSizes = &ds_type_count;
6737
6738 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006740 ASSERT_VK_SUCCESS(err);
6741
6742 VkDescriptorSetLayoutBinding dsl_binding = {};
6743 dsl_binding.binding = 0;
6744 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6745 dsl_binding.descriptorCount = 1;
6746 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6747 dsl_binding.pImmutableSamplers = NULL;
6748
6749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6751 ds_layout_ci.pNext = NULL;
6752 ds_layout_ci.bindingCount = 1;
6753 ds_layout_ci.pBindings = &dsl_binding;
6754 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006756 ASSERT_VK_SUCCESS(err);
6757
6758 VkDescriptorSet descriptorSet;
6759 VkDescriptorSetAllocateInfo alloc_info = {};
6760 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6761 alloc_info.descriptorSetCount = 1;
6762 alloc_info.descriptorPool = ds_pool;
6763 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006764 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006765 ASSERT_VK_SUCCESS(err);
6766
6767 // Create a buffer to update the descriptor with
6768 uint32_t qfi = 0;
6769 VkBufferCreateInfo buffCI = {};
6770 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6771 buffCI.size = 1024;
6772 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6773 buffCI.queueFamilyIndexCount = 1;
6774 buffCI.pQueueFamilyIndices = &qfi;
6775
6776 VkBuffer dyub;
6777 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6778 ASSERT_VK_SUCCESS(err);
6779
6780 // Attempt to update descriptor without binding memory to it
6781 VkDescriptorBufferInfo buffInfo = {};
6782 buffInfo.buffer = dyub;
6783 buffInfo.offset = 0;
6784 buffInfo.range = 1024;
6785
6786 VkWriteDescriptorSet descriptor_write;
6787 memset(&descriptor_write, 0, sizeof(descriptor_write));
6788 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6789 descriptor_write.dstSet = descriptorSet;
6790 descriptor_write.dstBinding = 0;
6791 descriptor_write.descriptorCount = 1;
6792 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6793 descriptor_write.pBufferInfo = &buffInfo;
6794
6795 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6796 m_errorMonitor->VerifyFound();
6797
6798 vkDestroyBuffer(m_device->device(), dyub, NULL);
6799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6801}
6802
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006803TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006804 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006805 ASSERT_NO_FATAL_FAILURE(InitState());
6806 ASSERT_NO_FATAL_FAILURE(InitViewport());
6807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6808
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006809 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006810 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006811 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6812 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6813 pipeline_layout_ci.pushConstantRangeCount = 1;
6814 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6815
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006816 //
6817 // Check for invalid push constant ranges in pipeline layouts.
6818 //
6819 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006820 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006821 char const *msg;
6822 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006823
Karl Schultzc81037d2016-05-12 08:11:23 -06006824 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6825 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6826 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6827 "vkCreatePipelineLayout() call has push constants index 0 with "
6828 "size 0."},
6829 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6830 "vkCreatePipelineLayout() call has push constants index 0 with "
6831 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006832 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006833 "vkCreatePipelineLayout() call has push constants index 0 with "
6834 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006835 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006836 "vkCreatePipelineLayout() call has push constants index 0 with "
6837 "size 0."},
6838 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6839 "vkCreatePipelineLayout() call has push constants index 0 with "
6840 "offset 1. Offset must"},
6841 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6842 "vkCreatePipelineLayout() call has push constants index 0 "
6843 "with offset "},
6844 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6845 "vkCreatePipelineLayout() call has push constants "
6846 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006847 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006848 "vkCreatePipelineLayout() call has push constants index 0 "
6849 "with offset "},
6850 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6851 "vkCreatePipelineLayout() call has push "
6852 "constants index 0 with offset "},
6853 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6854 "vkCreatePipelineLayout() call has push "
6855 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006856 }};
6857
6858 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006859 for (const auto &iter : range_tests) {
6860 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6862 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006863 m_errorMonitor->VerifyFound();
6864 if (VK_SUCCESS == err) {
6865 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6866 }
6867 }
6868
6869 // Check for invalid stage flag
6870 pc_range.offset = 0;
6871 pc_range.size = 16;
6872 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006873 m_errorMonitor->SetDesiredFailureMsg(
6874 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6875 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006876 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006877 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006878 if (VK_SUCCESS == err) {
6879 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6880 }
6881
6882 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006883 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006884 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006885 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006886 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006887 };
6888
Karl Schultzc81037d2016-05-12 08:11:23 -06006889 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006890 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6891 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6892 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6893 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6894 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006895 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6896 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6897 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6898 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6899 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6900 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6901 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6902 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6903 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6904 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006905 {
6906 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6907 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6908 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6909 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6910 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006911 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006912 },
6913 {
6914 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6915 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6916 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6917 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6918 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006919 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006920 },
6921 {
6922 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6923 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6924 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6925 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6926 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006927 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006928 },
6929 {
6930 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6931 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6932 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6933 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6934 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006935 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6936 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6937 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6938 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006939 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006940
Karl Schultzc81037d2016-05-12 08:11:23 -06006941 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006943 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006945 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006946 m_errorMonitor->VerifyFound();
6947 if (VK_SUCCESS == err) {
6948 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6949 }
6950 }
6951
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006952 //
6953 // CmdPushConstants tests
6954 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006955 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006956
6957 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006958 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6959 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006960 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006961 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6962 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006963 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006964 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6965 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006966 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006967 "vkCmdPushConstants() call has push constants with offset 1. "
6968 "Offset must be a multiple of 4."},
6969 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6970 "vkCmdPushConstants() call has push constants with offset 1. "
6971 "Offset must be a multiple of 4."},
6972 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6973 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6974 "0x1 not within flag-matching ranges in pipeline layout"},
6975 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6976 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6977 "0x1 not within flag-matching ranges in pipeline layout"},
6978 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6979 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6980 "0x1 not within flag-matching ranges in pipeline layout"},
6981 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6982 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6983 "0x1 not within flag-matching ranges in pipeline layout"},
6984 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6985 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6986 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006988 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6989 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006990 }};
6991
Tony Barbour552f6c02016-12-21 14:34:07 -07006992 m_commandBuffer->BeginCommandBuffer();
6993 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006994
6995 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006996 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006997 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006998 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006999 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007000 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007002 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007003 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7005 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007006 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007007 m_errorMonitor->VerifyFound();
7008 }
7009
7010 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007012 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007013 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06007014 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007015
Karl Schultzc81037d2016-05-12 08:11:23 -06007016 // overlapping range tests with cmd
7017 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
7018 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7019 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7020 "0x1 not within flag-matching ranges in pipeline layout"},
7021 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
7022 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
7023 "0x1 not within flag-matching ranges in pipeline layout"},
7024 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
7025 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7026 "0x1 not within flag-matching ranges in pipeline layout"},
7027 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007028 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007029 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007030 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7031 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007032 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007033 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007034 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007035 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007037 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7039 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007040 iter.range.size, dummy_values);
7041 m_errorMonitor->VerifyFound();
7042 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7044
Tony Barbour552f6c02016-12-21 14:34:07 -07007045 m_commandBuffer->EndRenderPass();
7046 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007047}
7048
Karl Schultz6addd812016-02-02 17:17:23 -07007049TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007050 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007051 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007052
7053 ASSERT_NO_FATAL_FAILURE(InitState());
7054 ASSERT_NO_FATAL_FAILURE(InitViewport());
7055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7056
7057 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7058 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7060 ds_type_count[0].descriptorCount = 10;
7061 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7062 ds_type_count[1].descriptorCount = 2;
7063 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7064 ds_type_count[2].descriptorCount = 2;
7065 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7066 ds_type_count[3].descriptorCount = 5;
7067 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7068 // type
7069 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7070 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7071 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007072
7073 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007074 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7075 ds_pool_ci.pNext = NULL;
7076 ds_pool_ci.maxSets = 5;
7077 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7078 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007079
7080 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007081 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007082 ASSERT_VK_SUCCESS(err);
7083
7084 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7085 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 dsl_binding[0].binding = 0;
7087 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7088 dsl_binding[0].descriptorCount = 5;
7089 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7090 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007091
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007092 // Create layout identical to set0 layout but w/ different stageFlags
7093 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.binding = 0;
7095 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7096 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007097 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7098 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007099 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7102 ds_layout_ci.pNext = NULL;
7103 ds_layout_ci.bindingCount = 1;
7104 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 static const uint32_t NUM_LAYOUTS = 4;
7106 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007107 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007108 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7109 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007111 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007112 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007115 dsl_binding[0].binding = 0;
7116 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007117 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007118 dsl_binding[1].binding = 1;
7119 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7120 dsl_binding[1].descriptorCount = 2;
7121 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7122 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007123 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007124 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007126 ASSERT_VK_SUCCESS(err);
7127 dsl_binding[0].binding = 0;
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007130 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007132 ASSERT_VK_SUCCESS(err);
7133 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007134 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 ASSERT_VK_SUCCESS(err);
7137
7138 static const uint32_t NUM_SETS = 4;
7139 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7140 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007142 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007143 alloc_info.descriptorPool = ds_pool;
7144 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007147 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007148 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007149 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007151 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007152
7153 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7155 pipeline_layout_ci.pNext = NULL;
7156 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7157 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007158
7159 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007161 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007162 // Create pipelineLayout with only one setLayout
7163 pipeline_layout_ci.setLayoutCount = 1;
7164 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 2 descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7169 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7173 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7174 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout with UB type, but stageFlags for FS only
7178 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7179 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007181 ASSERT_VK_SUCCESS(err);
7182 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7183 VkDescriptorSetLayout pl_bad_s0[2] = {};
7184 pl_bad_s0[0] = ds_layout_fs_only;
7185 pl_bad_s0[1] = ds_layout[1];
7186 pipeline_layout_ci.setLayoutCount = 2;
7187 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7188 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007189 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007191
Tobin Ehlis88452832015-12-03 09:40:56 -07007192 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007193 char const *vsSource =
7194 "#version 450\n"
7195 "\n"
7196 "out gl_PerVertex {\n"
7197 " vec4 gl_Position;\n"
7198 "};\n"
7199 "void main(){\n"
7200 " gl_Position = vec4(1);\n"
7201 "}\n";
7202 char const *fsSource =
7203 "#version 450\n"
7204 "\n"
7205 "layout(location=0) out vec4 x;\n"
7206 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7207 "void main(){\n"
7208 " x = vec4(bar.y);\n"
7209 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212 VkPipelineObj pipe(m_device);
7213 pipe.AddShader(&vs);
7214 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215 pipe.AddColorAttachment();
7216 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007217
Tony Barbour552f6c02016-12-21 14:34:07 -07007218 m_commandBuffer->BeginCommandBuffer();
7219 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007222 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7223 // of PSO
7224 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7225 // cmd_pipeline.c
7226 // due to the fact that cmd_alloc_dset_data() has not been called in
7227 // cmd_bind_graphics_pipeline()
7228 // TODO : Want to cause various binding incompatibility issues here to test
7229 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007230 // First cause various verify_layout_compatibility() fails
7231 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007232 // verify_set_layout_compatibility fail cases:
7233 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7236 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007237 m_errorMonitor->VerifyFound();
7238
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007239 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
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(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007246 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7247 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 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 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7254 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7257 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007258 m_errorMonitor->VerifyFound();
7259
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007260 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7261 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7263 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7264 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7265 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007266 m_errorMonitor->VerifyFound();
7267
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007268 // Cause INFO messages due to disturbing previously bound Sets
7269 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7271 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007272 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7275 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007276 m_errorMonitor->VerifyFound();
7277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7279 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007280 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7282 " newly bound as set #0 so set #1 and "
7283 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7285 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007286 m_errorMonitor->VerifyFound();
7287
Tobin Ehlis10fad692016-07-07 12:00:36 -06007288 // Now that we're done actively using the pipelineLayout that gfx pipeline
7289 // was created with, we should be able to delete it. Do that now to verify
7290 // that validation obeys pipelineLayout lifetime
7291 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7292
Tobin Ehlis88452832015-12-03 09:40:56 -07007293 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007294 // 1. Error due to not binding required set (we actually use same code as
7295 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7297 &descriptorSet[0], 0, NULL);
7298 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7299 &descriptorSet[1], 0, NULL);
7300 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 -07007301
7302 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7303 VkRect2D scissor = {{0, 0}, {16, 16}};
7304 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7305 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7306
Tobin Ehlis88452832015-12-03 09:40:56 -07007307 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007308 m_errorMonitor->VerifyFound();
7309
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007310 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007311 // 2. Error due to bound set not being compatible with PSO's
7312 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7314 &descriptorSet[0], 0, NULL);
7315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007316 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007317 m_errorMonitor->VerifyFound();
7318
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007319 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007320 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7322 }
7323 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7325 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7326}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007327
Karl Schultz6addd812016-02-02 17:17:23 -07007328TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7330 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007331
7332 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007333 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007334 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007335 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007336
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007337 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007338}
7339
Karl Schultz6addd812016-02-02 17:17:23 -07007340TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7341 VkResult err;
7342 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007343
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007345
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007346 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007347
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007348 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007349 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007350 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007351 cmd.commandPool = m_commandPool;
7352 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007353 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007354
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007355 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007356 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007357
7358 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007359 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007360 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7361
7362 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007363 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007364 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 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 -07007366 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007367
7368 // The error should be caught by validation of the BeginCommandBuffer call
7369 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7370
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007371 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007372 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007373}
7374
Karl Schultz6addd812016-02-02 17:17:23 -07007375TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376 // Cause error due to Begin while recording CB
7377 // Then cause 2 errors for attempting to reset CB w/o having
7378 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7379 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007381
7382 ASSERT_NO_FATAL_FAILURE(InitState());
7383
7384 // Calls AllocateCommandBuffers
7385 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7386
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007387 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007388 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007389 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7390 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007391 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7392 cmd_buf_info.pNext = NULL;
7393 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007394 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007395
7396 // Begin CB to transition to recording state
7397 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7398 // Can't re-begin. This should trigger error
7399 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007400 m_errorMonitor->VerifyFound();
7401
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007403 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Reset attempt will trigger error due to incorrect CommandPool state
7405 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007406 m_errorMonitor->VerifyFound();
7407
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409 // Transition CB to RECORDED state
7410 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7411 // Now attempting to Begin will implicitly reset, which triggers error
7412 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007413 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007414}
7415
Karl Schultz6addd812016-02-02 17:17:23 -07007416TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007417 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007418 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007419
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7421 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007422
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007423 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007425
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007427 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7428 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007429
7430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7432 ds_pool_ci.pNext = NULL;
7433 ds_pool_ci.maxSets = 1;
7434 ds_pool_ci.poolSizeCount = 1;
7435 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007436
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007437 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007439 ASSERT_VK_SUCCESS(err);
7440
Tony Barboureb254902015-07-15 12:50:33 -06007441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007442 dsl_binding.binding = 0;
7443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7444 dsl_binding.descriptorCount = 1;
7445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007447
Tony Barboureb254902015-07-15 12:50:33 -06007448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7450 ds_layout_ci.pNext = NULL;
7451 ds_layout_ci.bindingCount = 1;
7452 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007453
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007454 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007456 ASSERT_VK_SUCCESS(err);
7457
7458 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007459 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007460 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007461 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007462 alloc_info.descriptorPool = ds_pool;
7463 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007464 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007465 ASSERT_VK_SUCCESS(err);
7466
Tony Barboureb254902015-07-15 12:50:33 -06007467 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007468 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7469 pipeline_layout_ci.setLayoutCount = 1;
7470 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007471
7472 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007474 ASSERT_VK_SUCCESS(err);
7475
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007476 VkViewport vp = {}; // Just need dummy vp to point to
7477 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007478
7479 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007480 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7481 vp_state_ci.scissorCount = 1;
7482 vp_state_ci.pScissors = &sc;
7483 vp_state_ci.viewportCount = 1;
7484 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007486 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7487 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7488 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7489 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7490 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7491 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007492 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007493 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007494 rs_state_ci.lineWidth = 1.0f;
7495
7496 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7497 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7498 vi_ci.pNext = nullptr;
7499 vi_ci.vertexBindingDescriptionCount = 0;
7500 vi_ci.pVertexBindingDescriptions = nullptr;
7501 vi_ci.vertexAttributeDescriptionCount = 0;
7502 vi_ci.pVertexAttributeDescriptions = nullptr;
7503
7504 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7505 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7506 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7507
7508 VkPipelineShaderStageCreateInfo shaderStages[2];
7509 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7510
7511 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7512 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007513 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007514 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007515
Tony Barboureb254902015-07-15 12:50:33 -06007516 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007517 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7518 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007519 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007520 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7521 gp_ci.layout = pipeline_layout;
7522 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007523 gp_ci.pVertexInputState = &vi_ci;
7524 gp_ci.pInputAssemblyState = &ia_ci;
7525
7526 gp_ci.stageCount = 1;
7527 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007528
7529 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007530 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7531 pc_ci.initialDataSize = 0;
7532 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007533
7534 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007535 VkPipelineCache pipelineCache;
7536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007537 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007538 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007539 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007540 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007541
Chia-I Wuf7458c52015-10-26 21:10:41 +08007542 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7543 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007546}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007547
Tobin Ehlis912df022015-09-17 08:46:18 -06007548/*// TODO : This test should be good, but needs Tess support in compiler to run
7549TEST_F(VkLayerTest, InvalidPatchControlPoints)
7550{
7551 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007552 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007553
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007555 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7556primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007557
Tobin Ehlis912df022015-09-17 08:46:18 -06007558 ASSERT_NO_FATAL_FAILURE(InitState());
7559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007560
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007561 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007563 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564
7565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7567 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007568 ds_pool_ci.poolSizeCount = 1;
7569 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007570
7571 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007572 err = vkCreateDescriptorPool(m_device->device(),
7573VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007574 ASSERT_VK_SUCCESS(err);
7575
7576 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007577 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007579 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007580 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7581 dsl_binding.pImmutableSamplers = NULL;
7582
7583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007584 ds_layout_ci.sType =
7585VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007586 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007587 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007588 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007589
7590 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7592&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007596 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7597VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 ASSERT_VK_SUCCESS(err);
7599
7600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007601 pipeline_layout_ci.sType =
7602VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007603 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007604 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 pipeline_layout_ci.pSetLayouts = &ds_layout;
7606
7607 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7609&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007610 ASSERT_VK_SUCCESS(err);
7611
7612 VkPipelineShaderStageCreateInfo shaderStages[3];
7613 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7614
Karl Schultz6addd812016-02-02 17:17:23 -07007615 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7616this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007617 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007618 VkShaderObj
7619tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7620this);
7621 VkShaderObj
7622te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7623this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007624
Karl Schultz6addd812016-02-02 17:17:23 -07007625 shaderStages[0].sType =
7626VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007627 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007628 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007629 shaderStages[1].sType =
7630VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007631 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007632 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007633 shaderStages[2].sType =
7634VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007635 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007636 shaderStages[2].shader = te.handle();
7637
7638 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007639 iaCI.sType =
7640VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007641 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007642
7643 VkPipelineTessellationStateCreateInfo tsCI = {};
7644 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7645 tsCI.patchControlPoints = 0; // This will cause an error
7646
7647 VkGraphicsPipelineCreateInfo gp_ci = {};
7648 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7649 gp_ci.pNext = NULL;
7650 gp_ci.stageCount = 3;
7651 gp_ci.pStages = shaderStages;
7652 gp_ci.pVertexInputState = NULL;
7653 gp_ci.pInputAssemblyState = &iaCI;
7654 gp_ci.pTessellationState = &tsCI;
7655 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007656 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007657 gp_ci.pMultisampleState = NULL;
7658 gp_ci.pDepthStencilState = NULL;
7659 gp_ci.pColorBlendState = NULL;
7660 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7661 gp_ci.layout = pipeline_layout;
7662 gp_ci.renderPass = renderPass();
7663
7664 VkPipelineCacheCreateInfo pc_ci = {};
7665 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7666 pc_ci.pNext = NULL;
7667 pc_ci.initialSize = 0;
7668 pc_ci.initialData = 0;
7669 pc_ci.maxSize = 0;
7670
7671 VkPipeline pipeline;
7672 VkPipelineCache pipelineCache;
7673
Karl Schultz6addd812016-02-02 17:17:23 -07007674 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7675&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007676 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007677 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7678&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007679
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007680 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007681
Chia-I Wuf7458c52015-10-26 21:10:41 +08007682 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7683 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007686}
7687*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007689TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007690 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007692 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007693
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694 ASSERT_NO_FATAL_FAILURE(InitState());
7695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007696
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7699 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007700
7701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7703 ds_pool_ci.maxSets = 1;
7704 ds_pool_ci.poolSizeCount = 1;
7705 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706
7707 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007709 ASSERT_VK_SUCCESS(err);
7710
7711 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007712 dsl_binding.binding = 0;
7713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7714 dsl_binding.descriptorCount = 1;
7715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7719 ds_layout_ci.bindingCount = 1;
7720 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007721
7722 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007724 ASSERT_VK_SUCCESS(err);
7725
7726 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007727 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007728 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007729 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007730 alloc_info.descriptorPool = ds_pool;
7731 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007733 ASSERT_VK_SUCCESS(err);
7734
7735 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007736 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7737 pipeline_layout_ci.setLayoutCount = 1;
7738 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007739
7740 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007742 ASSERT_VK_SUCCESS(err);
7743
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007744 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007746 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007747 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007748 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007749 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007750
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007751 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7752 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7753 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7754 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7755 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7756 rs_state_ci.depthClampEnable = VK_FALSE;
7757 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7758 rs_state_ci.depthBiasEnable = VK_FALSE;
7759
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007760 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7761 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7762 vi_ci.pNext = nullptr;
7763 vi_ci.vertexBindingDescriptionCount = 0;
7764 vi_ci.pVertexBindingDescriptions = nullptr;
7765 vi_ci.vertexAttributeDescriptionCount = 0;
7766 vi_ci.pVertexAttributeDescriptions = nullptr;
7767
7768 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7769 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7770 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7771
7772 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7773 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7774 pipe_ms_state_ci.pNext = NULL;
7775 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7776 pipe_ms_state_ci.sampleShadingEnable = 0;
7777 pipe_ms_state_ci.minSampleShading = 1.0;
7778 pipe_ms_state_ci.pSampleMask = NULL;
7779
Cody Northropeb3a6c12015-10-05 14:44:45 -06007780 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007781 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007783 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007784 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007785 shaderStages[0] = vs.GetStageCreateInfo();
7786 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007787
7788 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7790 gp_ci.stageCount = 2;
7791 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007792 gp_ci.pVertexInputState = &vi_ci;
7793 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007794 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007795 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007796 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007797 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7798 gp_ci.layout = pipeline_layout;
7799 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007800
7801 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007802 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
7804 VkPipeline pipeline;
7805 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007806 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007807 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007808
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007809 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007810 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007811
7812 // Check case where multiViewport is disabled and viewport count is not 1
7813 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7816 vp_state_ci.scissorCount = 0;
7817 vp_state_ci.viewportCount = 0;
7818 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7819 m_errorMonitor->VerifyFound();
7820 } else {
7821 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007822 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007823 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007824 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007825
7826 // Check is that viewportcount and scissorcount match
7827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7828 vp_state_ci.scissorCount = 1;
7829 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7830 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7831 m_errorMonitor->VerifyFound();
7832
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007833 // Check case where multiViewport is enabled and viewport count is greater than max
7834 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7837 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7838 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7839 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7840 m_errorMonitor->VerifyFound();
7841 }
7842 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843
Chia-I Wuf7458c52015-10-26 21:10:41 +08007844 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7845 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7846 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7847 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007848}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007849
7850// 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
7851// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007852TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007853 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007855 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7856
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007858
Tobin Ehlise68360f2015-10-01 11:15:13 -06007859 ASSERT_NO_FATAL_FAILURE(InitState());
7860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007861
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007862 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007863 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7864 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007865
7866 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007867 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7868 ds_pool_ci.maxSets = 1;
7869 ds_pool_ci.poolSizeCount = 1;
7870 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871
7872 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007874 ASSERT_VK_SUCCESS(err);
7875
7876 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007877 dsl_binding.binding = 0;
7878 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7879 dsl_binding.descriptorCount = 1;
7880 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007883 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7884 ds_layout_ci.bindingCount = 1;
7885 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007886
7887 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007888 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007889 ASSERT_VK_SUCCESS(err);
7890
7891 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007892 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007893 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007894 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007895 alloc_info.descriptorPool = ds_pool;
7896 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007898 ASSERT_VK_SUCCESS(err);
7899
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007900 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7901 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7902 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7903
7904 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7905 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7906 vi_ci.pNext = nullptr;
7907 vi_ci.vertexBindingDescriptionCount = 0;
7908 vi_ci.pVertexBindingDescriptions = nullptr;
7909 vi_ci.vertexAttributeDescriptionCount = 0;
7910 vi_ci.pVertexAttributeDescriptions = nullptr;
7911
7912 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7913 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7914 pipe_ms_state_ci.pNext = NULL;
7915 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7916 pipe_ms_state_ci.sampleShadingEnable = 0;
7917 pipe_ms_state_ci.minSampleShading = 1.0;
7918 pipe_ms_state_ci.pSampleMask = NULL;
7919
Tobin Ehlise68360f2015-10-01 11:15:13 -06007920 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007921 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7922 pipeline_layout_ci.setLayoutCount = 1;
7923 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007924
7925 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007926 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007927 ASSERT_VK_SUCCESS(err);
7928
7929 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7930 // Set scissor as dynamic to avoid second error
7931 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007932 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7933 dyn_state_ci.dynamicStateCount = 1;
7934 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007935
Cody Northropeb3a6c12015-10-05 14:44:45 -06007936 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007937 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007940 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7941 // 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 +08007942 shaderStages[0] = vs.GetStageCreateInfo();
7943 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007944
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007945 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7946 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7947 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7948 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7949 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7950 rs_state_ci.depthClampEnable = VK_FALSE;
7951 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7952 rs_state_ci.depthBiasEnable = VK_FALSE;
7953
Tobin Ehlise68360f2015-10-01 11:15:13 -06007954 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7956 gp_ci.stageCount = 2;
7957 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007958 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007959 // Not setting VP state w/o dynamic vp state should cause validation error
7960 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007961 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007962 gp_ci.pVertexInputState = &vi_ci;
7963 gp_ci.pInputAssemblyState = &ia_ci;
7964 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007965 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7966 gp_ci.layout = pipeline_layout;
7967 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007968
7969 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007970 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971
7972 VkPipeline pipeline;
7973 VkPipelineCache pipelineCache;
7974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007978
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007979 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980
Chia-I Wuf7458c52015-10-26 21:10:41 +08007981 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007986
7987// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7988// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007989TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7990 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007991
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007993
Tobin Ehlise68360f2015-10-01 11:15:13 -06007994 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007995
7996 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007997 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007998 return;
7999 }
8000
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008003 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008004 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8005 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008006
8007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8009 ds_pool_ci.maxSets = 1;
8010 ds_pool_ci.poolSizeCount = 1;
8011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012
8013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008015 ASSERT_VK_SUCCESS(err);
8016
8017 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008018 dsl_binding.binding = 0;
8019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8020 dsl_binding.descriptorCount = 1;
8021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8025 ds_layout_ci.bindingCount = 1;
8026 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027
8028 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008029 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030 ASSERT_VK_SUCCESS(err);
8031
8032 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008033 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008035 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008036 alloc_info.descriptorPool = ds_pool;
8037 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008039 ASSERT_VK_SUCCESS(err);
8040
8041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8043 pipeline_layout_ci.setLayoutCount = 1;
8044 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045
8046 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048 ASSERT_VK_SUCCESS(err);
8049
8050 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008051 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8052 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008053 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008054 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008055 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008056
8057 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8058 // Set scissor as dynamic to avoid that error
8059 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008060 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8061 dyn_state_ci.dynamicStateCount = 1;
8062 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008063
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008064 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8065 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8066 pipe_ms_state_ci.pNext = NULL;
8067 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8068 pipe_ms_state_ci.sampleShadingEnable = 0;
8069 pipe_ms_state_ci.minSampleShading = 1.0;
8070 pipe_ms_state_ci.pSampleMask = NULL;
8071
Cody Northropeb3a6c12015-10-05 14:44:45 -06008072 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008073 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008074
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008076 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8077 // 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 +08008078 shaderStages[0] = vs.GetStageCreateInfo();
8079 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008080
Cody Northropf6622dc2015-10-06 10:33:21 -06008081 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8082 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8083 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008084 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008085 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008086 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008087 vi_ci.pVertexAttributeDescriptions = nullptr;
8088
8089 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8090 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8091 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8092
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008093 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008094 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008095 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008096 rs_ci.pNext = nullptr;
8097
Mark Youngc89c6312016-03-31 16:03:20 -06008098 VkPipelineColorBlendAttachmentState att = {};
8099 att.blendEnable = VK_FALSE;
8100 att.colorWriteMask = 0xf;
8101
Cody Northropf6622dc2015-10-06 10:33:21 -06008102 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8103 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8104 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008105 cb_ci.attachmentCount = 1;
8106 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008107
Tobin Ehlise68360f2015-10-01 11:15:13 -06008108 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008109 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8110 gp_ci.stageCount = 2;
8111 gp_ci.pStages = shaderStages;
8112 gp_ci.pVertexInputState = &vi_ci;
8113 gp_ci.pInputAssemblyState = &ia_ci;
8114 gp_ci.pViewportState = &vp_state_ci;
8115 gp_ci.pRasterizationState = &rs_ci;
8116 gp_ci.pColorBlendState = &cb_ci;
8117 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008118 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8120 gp_ci.layout = pipeline_layout;
8121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008122
8123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125
8126 VkPipeline pipeline;
8127 VkPipelineCache pipelineCache;
8128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008133 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008134
Tobin Ehlisd332f282015-10-02 11:00:56 -06008135 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008136 // First need to successfully create the PSO from above by setting
8137 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008138 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 -07008139
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008140 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008141 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008143 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008144 m_commandBuffer->BeginCommandBuffer();
8145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008147 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008148 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008149 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008150 Draw(1, 0, 0, 0);
8151
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008152 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008153
8154 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8155 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8157 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008158 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008159}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008160
8161// 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 -07008162// viewportCount
8163TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8164 VkResult err;
8165
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008167
8168 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008169
8170 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008171 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008172 return;
8173 }
8174
Karl Schultz6addd812016-02-02 17:17:23 -07008175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8176
8177 VkDescriptorPoolSize ds_type_count = {};
8178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8179 ds_type_count.descriptorCount = 1;
8180
8181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8183 ds_pool_ci.maxSets = 1;
8184 ds_pool_ci.poolSizeCount = 1;
8185 ds_pool_ci.pPoolSizes = &ds_type_count;
8186
8187 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008189 ASSERT_VK_SUCCESS(err);
8190
8191 VkDescriptorSetLayoutBinding dsl_binding = {};
8192 dsl_binding.binding = 0;
8193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8194 dsl_binding.descriptorCount = 1;
8195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8196
8197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8199 ds_layout_ci.bindingCount = 1;
8200 ds_layout_ci.pBindings = &dsl_binding;
8201
8202 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008204 ASSERT_VK_SUCCESS(err);
8205
8206 VkDescriptorSet descriptorSet;
8207 VkDescriptorSetAllocateInfo alloc_info = {};
8208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8209 alloc_info.descriptorSetCount = 1;
8210 alloc_info.descriptorPool = ds_pool;
8211 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008213 ASSERT_VK_SUCCESS(err);
8214
8215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8217 pipeline_layout_ci.setLayoutCount = 1;
8218 pipeline_layout_ci.pSetLayouts = &ds_layout;
8219
8220 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008222 ASSERT_VK_SUCCESS(err);
8223
8224 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8225 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008227 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008228 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008229 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008230
8231 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8232 // Set scissor as dynamic to avoid that error
8233 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8234 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8235 dyn_state_ci.dynamicStateCount = 1;
8236 dyn_state_ci.pDynamicStates = &vp_state;
8237
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008238 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8239 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8240 pipe_ms_state_ci.pNext = NULL;
8241 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8242 pipe_ms_state_ci.sampleShadingEnable = 0;
8243 pipe_ms_state_ci.minSampleShading = 1.0;
8244 pipe_ms_state_ci.pSampleMask = NULL;
8245
Karl Schultz6addd812016-02-02 17:17:23 -07008246 VkPipelineShaderStageCreateInfo shaderStages[2];
8247 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008250 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8251 // 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 -07008252 shaderStages[0] = vs.GetStageCreateInfo();
8253 shaderStages[1] = fs.GetStageCreateInfo();
8254
8255 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8256 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8257 vi_ci.pNext = nullptr;
8258 vi_ci.vertexBindingDescriptionCount = 0;
8259 vi_ci.pVertexBindingDescriptions = nullptr;
8260 vi_ci.vertexAttributeDescriptionCount = 0;
8261 vi_ci.pVertexAttributeDescriptions = nullptr;
8262
8263 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8264 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8265 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8266
8267 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8268 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008269 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008270 rs_ci.pNext = nullptr;
8271
Mark Youngc89c6312016-03-31 16:03:20 -06008272 VkPipelineColorBlendAttachmentState att = {};
8273 att.blendEnable = VK_FALSE;
8274 att.colorWriteMask = 0xf;
8275
Karl Schultz6addd812016-02-02 17:17:23 -07008276 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8277 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8278 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008279 cb_ci.attachmentCount = 1;
8280 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008281
8282 VkGraphicsPipelineCreateInfo gp_ci = {};
8283 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8284 gp_ci.stageCount = 2;
8285 gp_ci.pStages = shaderStages;
8286 gp_ci.pVertexInputState = &vi_ci;
8287 gp_ci.pInputAssemblyState = &ia_ci;
8288 gp_ci.pViewportState = &vp_state_ci;
8289 gp_ci.pRasterizationState = &rs_ci;
8290 gp_ci.pColorBlendState = &cb_ci;
8291 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008292 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008293 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8294 gp_ci.layout = pipeline_layout;
8295 gp_ci.renderPass = renderPass();
8296
8297 VkPipelineCacheCreateInfo pc_ci = {};
8298 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8299
8300 VkPipeline pipeline;
8301 VkPipelineCache pipelineCache;
8302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008304 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008307 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008308
8309 // Now hit second fail case where we set scissor w/ different count than PSO
8310 // First need to successfully create the PSO from above by setting
8311 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8313 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008314
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008315 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008316 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008318 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008319 m_commandBuffer->BeginCommandBuffer();
8320 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008322 VkViewport viewports[1] = {};
8323 viewports[0].width = 8;
8324 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008325 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008326 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008327 Draw(1, 0, 0, 0);
8328
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008329 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008330
Chia-I Wuf7458c52015-10-26 21:10:41 +08008331 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8332 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8333 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8334 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008335 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008336}
8337
Mark Young7394fdd2016-03-31 14:56:43 -06008338TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8339 VkResult err;
8340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008342
8343 ASSERT_NO_FATAL_FAILURE(InitState());
8344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8345
8346 VkDescriptorPoolSize ds_type_count = {};
8347 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8348 ds_type_count.descriptorCount = 1;
8349
8350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8352 ds_pool_ci.maxSets = 1;
8353 ds_pool_ci.poolSizeCount = 1;
8354 ds_pool_ci.pPoolSizes = &ds_type_count;
8355
8356 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008358 ASSERT_VK_SUCCESS(err);
8359
8360 VkDescriptorSetLayoutBinding dsl_binding = {};
8361 dsl_binding.binding = 0;
8362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8363 dsl_binding.descriptorCount = 1;
8364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8365
8366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8368 ds_layout_ci.bindingCount = 1;
8369 ds_layout_ci.pBindings = &dsl_binding;
8370
8371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008373 ASSERT_VK_SUCCESS(err);
8374
8375 VkDescriptorSet descriptorSet;
8376 VkDescriptorSetAllocateInfo alloc_info = {};
8377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8378 alloc_info.descriptorSetCount = 1;
8379 alloc_info.descriptorPool = ds_pool;
8380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008382 ASSERT_VK_SUCCESS(err);
8383
8384 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8385 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8386 pipeline_layout_ci.setLayoutCount = 1;
8387 pipeline_layout_ci.pSetLayouts = &ds_layout;
8388
8389 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008391 ASSERT_VK_SUCCESS(err);
8392
8393 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8394 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8395 vp_state_ci.scissorCount = 1;
8396 vp_state_ci.pScissors = NULL;
8397 vp_state_ci.viewportCount = 1;
8398 vp_state_ci.pViewports = NULL;
8399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008401 // Set scissor as dynamic to avoid that error
8402 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8403 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8404 dyn_state_ci.dynamicStateCount = 2;
8405 dyn_state_ci.pDynamicStates = dynamic_states;
8406
8407 VkPipelineShaderStageCreateInfo shaderStages[2];
8408 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8411 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008412 this); // TODO - We shouldn't need a fragment shader
8413 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008414 shaderStages[0] = vs.GetStageCreateInfo();
8415 shaderStages[1] = fs.GetStageCreateInfo();
8416
8417 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8418 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8419 vi_ci.pNext = nullptr;
8420 vi_ci.vertexBindingDescriptionCount = 0;
8421 vi_ci.pVertexBindingDescriptions = nullptr;
8422 vi_ci.vertexAttributeDescriptionCount = 0;
8423 vi_ci.pVertexAttributeDescriptions = nullptr;
8424
8425 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8426 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8427 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8428
8429 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8430 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8431 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008432 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008433
Mark Young47107952016-05-02 15:59:55 -06008434 // Check too low (line width of -1.0f).
8435 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008436
8437 VkPipelineColorBlendAttachmentState att = {};
8438 att.blendEnable = VK_FALSE;
8439 att.colorWriteMask = 0xf;
8440
8441 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8442 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8443 cb_ci.pNext = nullptr;
8444 cb_ci.attachmentCount = 1;
8445 cb_ci.pAttachments = &att;
8446
8447 VkGraphicsPipelineCreateInfo gp_ci = {};
8448 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8449 gp_ci.stageCount = 2;
8450 gp_ci.pStages = shaderStages;
8451 gp_ci.pVertexInputState = &vi_ci;
8452 gp_ci.pInputAssemblyState = &ia_ci;
8453 gp_ci.pViewportState = &vp_state_ci;
8454 gp_ci.pRasterizationState = &rs_ci;
8455 gp_ci.pColorBlendState = &cb_ci;
8456 gp_ci.pDynamicState = &dyn_state_ci;
8457 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8458 gp_ci.layout = pipeline_layout;
8459 gp_ci.renderPass = renderPass();
8460
8461 VkPipelineCacheCreateInfo pc_ci = {};
8462 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8463
8464 VkPipeline pipeline;
8465 VkPipelineCache pipelineCache;
8466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008468 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008472 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008475
8476 // Check too high (line width of 65536.0f).
8477 rs_ci.lineWidth = 65536.0f;
8478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008487
8488 dyn_state_ci.dynamicStateCount = 3;
8489
8490 rs_ci.lineWidth = 1.0f;
8491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008493 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008495 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008497
8498 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008499 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008500 m_errorMonitor->VerifyFound();
8501
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 // Check too high with dynamic setting.
8505 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8506 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008507 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008508
8509 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8510 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008513 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008514}
8515
Karl Schultz6addd812016-02-02 17:17:23 -07008516TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008517 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008519 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008520
8521 ASSERT_NO_FATAL_FAILURE(InitState());
8522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Tony Barbour552f6c02016-12-21 14:34:07 -07008524 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008525 // Don't care about RenderPass handle b/c error should be flagged before
8526 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008529 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008530}
8531
Karl Schultz6addd812016-02-02 17:17:23 -07008532TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008533 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8535 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008536
8537 ASSERT_NO_FATAL_FAILURE(InitState());
8538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008539
Tony Barbour552f6c02016-12-21 14:34:07 -07008540 m_commandBuffer->BeginCommandBuffer();
8541 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008542 // Just create a dummy Renderpass that's non-NULL so we can get to the
8543 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008544 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008546 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008547}
8548
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008550 TEST_DESCRIPTION(
8551 "Begin a renderPass where clearValueCount is less than"
8552 "the number of renderPass attachments that use loadOp"
8553 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008554
8555 ASSERT_NO_FATAL_FAILURE(InitState());
8556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8557
8558 // Create a renderPass with a single attachment that uses loadOp CLEAR
8559 VkAttachmentReference attach = {};
8560 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8561 VkSubpassDescription subpass = {};
8562 subpass.inputAttachmentCount = 1;
8563 subpass.pInputAttachments = &attach;
8564 VkRenderPassCreateInfo rpci = {};
8565 rpci.subpassCount = 1;
8566 rpci.pSubpasses = &subpass;
8567 rpci.attachmentCount = 1;
8568 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008569 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008570 // Set loadOp to CLEAR
8571 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8572 rpci.pAttachments = &attach_desc;
8573 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8574 VkRenderPass rp;
8575 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8576
8577 VkCommandBufferInheritanceInfo hinfo = {};
8578 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8579 hinfo.renderPass = VK_NULL_HANDLE;
8580 hinfo.subpass = 0;
8581 hinfo.framebuffer = VK_NULL_HANDLE;
8582 hinfo.occlusionQueryEnable = VK_FALSE;
8583 hinfo.queryFlags = 0;
8584 hinfo.pipelineStatistics = 0;
8585 VkCommandBufferBeginInfo info = {};
8586 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8587 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8588 info.pInheritanceInfo = &hinfo;
8589
8590 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8591 VkRenderPassBeginInfo rp_begin = {};
8592 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8593 rp_begin.pNext = NULL;
8594 rp_begin.renderPass = renderPass();
8595 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008596 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008597
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008600 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008601
8602 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008603
8604 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008605}
8606
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008608 TEST_DESCRIPTION(
8609 "Begin a renderPass where clearValueCount is greater than"
8610 "the number of renderPass attachments that use loadOp"
8611 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008612
8613 ASSERT_NO_FATAL_FAILURE(InitState());
8614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8615
8616 // Create a renderPass with a single attachment that uses loadOp CLEAR
8617 VkAttachmentReference attach = {};
8618 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8619 VkSubpassDescription subpass = {};
8620 subpass.inputAttachmentCount = 1;
8621 subpass.pInputAttachments = &attach;
8622 VkRenderPassCreateInfo rpci = {};
8623 rpci.subpassCount = 1;
8624 rpci.pSubpasses = &subpass;
8625 rpci.attachmentCount = 1;
8626 VkAttachmentDescription attach_desc = {};
8627 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8628 // Set loadOp to CLEAR
8629 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8630 rpci.pAttachments = &attach_desc;
8631 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8632 VkRenderPass rp;
8633 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8634
8635 VkCommandBufferBeginInfo info = {};
8636 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8637 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8638
8639 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8640 VkRenderPassBeginInfo rp_begin = {};
8641 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8642 rp_begin.pNext = NULL;
8643 rp_begin.renderPass = renderPass();
8644 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008645 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008646
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8648 " has a clearValueCount of"
8649 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008650
8651 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8652
8653 m_errorMonitor->VerifyFound();
8654
8655 vkDestroyRenderPass(m_device->device(), rp, NULL);
8656}
8657
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008659 TEST_DESCRIPTION("End a command buffer with an active render pass");
8660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8662 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008663
8664 ASSERT_NO_FATAL_FAILURE(InitState());
8665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8666
Tony Barbour552f6c02016-12-21 14:34:07 -07008667 m_commandBuffer->BeginCommandBuffer();
8668 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8669 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670
8671 m_errorMonitor->VerifyFound();
8672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008673 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8674 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008675}
8676
Karl Schultz6addd812016-02-02 17:17:23 -07008677TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008678 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8680 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008681
8682 ASSERT_NO_FATAL_FAILURE(InitState());
8683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684
Tony Barbour552f6c02016-12-21 14:34:07 -07008685 m_commandBuffer->BeginCommandBuffer();
8686 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008687
8688 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008689 vk_testing::Buffer dstBuffer;
8690 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008692 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008694 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008695}
8696
Karl Schultz6addd812016-02-02 17:17:23 -07008697TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008698 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8700 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008701
8702 ASSERT_NO_FATAL_FAILURE(InitState());
8703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008704
Tony Barbour552f6c02016-12-21 14:34:07 -07008705 m_commandBuffer->BeginCommandBuffer();
8706 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008707
8708 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008709 vk_testing::Buffer dstBuffer;
8710 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Karl Schultz6addd812016-02-02 17:17:23 -07008712 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008713 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8714 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8715 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008717 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008718}
8719
Karl Schultz6addd812016-02-02 17:17:23 -07008720TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008721 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8723 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008724
8725 ASSERT_NO_FATAL_FAILURE(InitState());
8726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008727
Tony Barbour552f6c02016-12-21 14:34:07 -07008728 m_commandBuffer->BeginCommandBuffer();
8729 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008730
Michael Lentine0a369f62016-02-03 16:51:46 -06008731 VkClearColorValue clear_color;
8732 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008733 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8735 const int32_t tex_width = 32;
8736 const int32_t tex_height = 32;
8737 VkImageCreateInfo image_create_info = {};
8738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8739 image_create_info.pNext = NULL;
8740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8741 image_create_info.format = tex_format;
8742 image_create_info.extent.width = tex_width;
8743 image_create_info.extent.height = tex_height;
8744 image_create_info.extent.depth = 1;
8745 image_create_info.mipLevels = 1;
8746 image_create_info.arrayLayers = 1;
8747 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8748 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8749 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008751 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008752 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008754 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008756 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008758
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008759 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760}
8761
Karl Schultz6addd812016-02-02 17:17:23 -07008762TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8765 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008766
8767 ASSERT_NO_FATAL_FAILURE(InitState());
8768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008769
Tony Barbour552f6c02016-12-21 14:34:07 -07008770 m_commandBuffer->BeginCommandBuffer();
8771 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
8773 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008774 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008775 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8777 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8778 image_create_info.extent.width = 64;
8779 image_create_info.extent.height = 64;
8780 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8781 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008783 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008788 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8789 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008791 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792}
8793
Karl Schultz6addd812016-02-02 17:17:23 -07008794TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008795 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008796 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "vkCmdClearAttachments(): This call "
8800 "must be issued inside an active "
8801 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803 ASSERT_NO_FATAL_FAILURE(InitState());
8804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
8806 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008807 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_VK_SUCCESS(err);
8809
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008810 VkClearAttachment color_attachment;
8811 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 color_attachment.clearValue.color.float32[0] = 0;
8813 color_attachment.clearValue.color.float32[1] = 0;
8814 color_attachment.clearValue.color.float32[2] = 0;
8815 color_attachment.clearValue.color.float32[3] = 0;
8816 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008817 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821}
8822
Chris Forbes3b97e932016-09-07 11:29:24 +12008823TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 TEST_DESCRIPTION(
8825 "Test that an error is produced when CmdNextSubpass is "
8826 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8829 "vkCmdNextSubpass(): Attempted to advance "
8830 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008831
8832 ASSERT_NO_FATAL_FAILURE(InitState());
8833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8834
Tony Barbour552f6c02016-12-21 14:34:07 -07008835 m_commandBuffer->BeginCommandBuffer();
8836 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008837
8838 // error here.
8839 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8840 m_errorMonitor->VerifyFound();
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->EndRenderPass();
8843 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008844}
8845
Chris Forbes6d624702016-09-07 13:57:05 +12008846TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008847 TEST_DESCRIPTION(
8848 "Test that an error is produced when CmdEndRenderPass is "
8849 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8852 "vkCmdEndRenderPass(): Called before reaching "
8853 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008854
8855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8857 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008860
8861 VkRenderPass rp;
8862 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8863 ASSERT_VK_SUCCESS(err);
8864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 VkFramebuffer fb;
8868 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8869 ASSERT_VK_SUCCESS(err);
8870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008874
8875 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8876
8877 // Error here.
8878 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8879 m_errorMonitor->VerifyFound();
8880
8881 // Clean up.
8882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8884}
8885
Karl Schultz9e66a292016-04-21 15:57:51 -06008886TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8887 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008892 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008893
8894 VkBufferMemoryBarrier buf_barrier = {};
8895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8896 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8897 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8898 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8899 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8900 buf_barrier.buffer = VK_NULL_HANDLE;
8901 buf_barrier.offset = 0;
8902 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8904 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 m_errorMonitor->VerifyFound();
8907}
8908
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008909TEST_F(VkLayerTest, InvalidBarriers) {
8910 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008913
8914 ASSERT_NO_FATAL_FAILURE(InitState());
8915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8916
8917 VkMemoryBarrier mem_barrier = {};
8918 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8919 mem_barrier.pNext = NULL;
8920 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8921 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008922 m_commandBuffer->BeginCommandBuffer();
8923 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008924 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008925 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008926 &mem_barrier, 0, nullptr, 0, nullptr);
8927 m_errorMonitor->VerifyFound();
8928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008930 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008931 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 -06008932 ASSERT_TRUE(image.initialized());
8933 VkImageMemoryBarrier img_barrier = {};
8934 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8935 img_barrier.pNext = NULL;
8936 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8937 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8938 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8939 // New layout can't be UNDEFINED
8940 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8941 img_barrier.image = image.handle();
8942 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8943 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8944 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8945 img_barrier.subresourceRange.baseArrayLayer = 0;
8946 img_barrier.subresourceRange.baseMipLevel = 0;
8947 img_barrier.subresourceRange.layerCount = 1;
8948 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008949 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8950 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008951 m_errorMonitor->VerifyFound();
8952 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8953
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8955 "Subresource must have the sum of the "
8956 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008957 // baseArrayLayer + layerCount must be <= image's arrayLayers
8958 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8960 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008961 m_errorMonitor->VerifyFound();
8962 img_barrier.subresourceRange.baseArrayLayer = 0;
8963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008965 // baseMipLevel + levelCount must be <= image's mipLevels
8966 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008967 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8968 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008969 m_errorMonitor->VerifyFound();
8970 img_barrier.subresourceRange.baseMipLevel = 0;
8971
Mike Weiblen7053aa32017-01-25 15:21:10 -07008972 // levelCount must be non-zero.
8973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8974 img_barrier.subresourceRange.levelCount = 0;
8975 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8976 nullptr, 0, nullptr, 1, &img_barrier);
8977 m_errorMonitor->VerifyFound();
8978 img_barrier.subresourceRange.levelCount = 1;
8979
8980 // layerCount must be non-zero.
8981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8982 img_barrier.subresourceRange.layerCount = 0;
8983 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8984 nullptr, 0, nullptr, 1, &img_barrier);
8985 m_errorMonitor->VerifyFound();
8986 img_barrier.subresourceRange.layerCount = 1;
8987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008988 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 -06008989 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008990 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8991 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008992 VkBufferMemoryBarrier buf_barrier = {};
8993 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8994 buf_barrier.pNext = NULL;
8995 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8996 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8997 buf_barrier.buffer = buffer.handle();
8998 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8999 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9000 buf_barrier.offset = 0;
9001 buf_barrier.size = VK_WHOLE_SIZE;
9002 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009003 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9004 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009005 m_errorMonitor->VerifyFound();
9006 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009009 buf_barrier.offset = 257;
9010 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9012 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009013 m_errorMonitor->VerifyFound();
9014 buf_barrier.offset = 0;
9015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009017 buf_barrier.size = 257;
9018 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009019 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9020 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009021 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009023 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009024 m_errorMonitor->SetDesiredFailureMsg(
9025 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009026 "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 -06009027 VkDepthStencilObj ds_image(m_device);
9028 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9029 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009030 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9031 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009032 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009033
9034 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009035 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009036 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9037 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009038 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009039
9040 // Having anything other than DEPTH or STENCIL is an error
9041 m_errorMonitor->SetDesiredFailureMsg(
9042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9043 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9044 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9045 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9046 nullptr, 0, nullptr, 1, &img_barrier);
9047 m_errorMonitor->VerifyFound();
9048
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009049 // Now test depth-only
9050 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9052 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009053 VkDepthStencilObj d_image(m_device);
9054 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9055 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009057 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009059
9060 // DEPTH bit must be set
9061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9062 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009063 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009064 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9065 0, nullptr, 0, nullptr, 1, &img_barrier);
9066 m_errorMonitor->VerifyFound();
9067
9068 // No bits other than DEPTH may be set
9069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9070 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9071 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009072 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9073 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009074 m_errorMonitor->VerifyFound();
9075 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009076
9077 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9079 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009080 VkDepthStencilObj s_image(m_device);
9081 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9082 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009084 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009085 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009086 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9088 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009089 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9091 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009092 m_errorMonitor->VerifyFound();
9093 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009094
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009095 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009096 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009097 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 -06009098 ASSERT_TRUE(c_image.initialized());
9099 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9100 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9101 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009102
9103 // COLOR bit must be set
9104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9105 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009106 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009107 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9108 nullptr, 0, nullptr, 1, &img_barrier);
9109 m_errorMonitor->VerifyFound();
9110
9111 // No bits other than COLOR may be set
9112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9113 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9114 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009115 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9116 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009117 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009118
9119 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9120
9121 // Create command pool with incompatible queueflags
9122 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9123 uint32_t queue_family_index = UINT32_MAX;
9124 for (uint32_t i = 0; i < queue_props.size(); i++) {
9125 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9126 queue_family_index = i;
9127 break;
9128 }
9129 }
9130 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009131 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009132 return;
9133 }
9134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9135
9136 VkCommandPool command_pool;
9137 VkCommandPoolCreateInfo pool_create_info{};
9138 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9139 pool_create_info.queueFamilyIndex = queue_family_index;
9140 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9141 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9142
9143 // Allocate a command buffer
9144 VkCommandBuffer bad_command_buffer;
9145 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9146 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9147 command_buffer_allocate_info.commandPool = command_pool;
9148 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9149 command_buffer_allocate_info.commandBufferCount = 1;
9150 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9151
9152 VkCommandBufferBeginInfo cbbi = {};
9153 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9154 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9155 buf_barrier.offset = 0;
9156 buf_barrier.size = VK_WHOLE_SIZE;
9157 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9158 &buf_barrier, 0, nullptr);
9159 m_errorMonitor->VerifyFound();
9160
9161 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9162 vkEndCommandBuffer(bad_command_buffer);
9163 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009164 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009165 return;
9166 }
9167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9168 VkEvent event;
9169 VkEventCreateInfo event_create_info{};
9170 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9171 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9172 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9173 nullptr, 0, nullptr);
9174 m_errorMonitor->VerifyFound();
9175
9176 vkEndCommandBuffer(bad_command_buffer);
9177 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009178}
9179
Tony Barbour18ba25c2016-09-29 13:42:40 -06009180TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9181 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9182
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009184 ASSERT_NO_FATAL_FAILURE(InitState());
9185 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009186 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 -06009187 ASSERT_TRUE(image.initialized());
9188
9189 VkImageMemoryBarrier barrier = {};
9190 VkImageSubresourceRange range;
9191 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9192 barrier.srcAccessMask = 0;
9193 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9194 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9195 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9196 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9197 barrier.image = image.handle();
9198 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9199 range.baseMipLevel = 0;
9200 range.levelCount = 1;
9201 range.baseArrayLayer = 0;
9202 range.layerCount = 1;
9203 barrier.subresourceRange = range;
9204 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9205 cmdbuf.BeginCommandBuffer();
9206 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9207 &barrier);
9208 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9209 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9210 barrier.srcAccessMask = 0;
9211 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9212 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9213 &barrier);
9214
9215 m_errorMonitor->VerifyFound();
9216}
9217
Karl Schultz6addd812016-02-02 17:17:23 -07009218TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009219 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009220 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009223
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009224 ASSERT_NO_FATAL_FAILURE(InitState());
9225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009226 uint32_t qfi = 0;
9227 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009228 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9229 buffCI.size = 1024;
9230 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9231 buffCI.queueFamilyIndexCount = 1;
9232 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009233
9234 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009235 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009236 ASSERT_VK_SUCCESS(err);
9237
Tony Barbour552f6c02016-12-21 14:34:07 -07009238 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009239 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009240 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9241 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009242 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009243 m_errorMonitor->SetUnexpectedError(
9244 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009246
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009247 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009248
Chia-I Wuf7458c52015-10-26 21:10:41 +08009249 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009250}
9251
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009252TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9253 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9255 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9256 "of the indices specified when the device was created, via the "
9257 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009258
9259 ASSERT_NO_FATAL_FAILURE(InitState());
9260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9261 VkBufferCreateInfo buffCI = {};
9262 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9263 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009264 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009265 buffCI.queueFamilyIndexCount = 1;
9266 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009267 uint32_t qfi[2];
9268 qfi[0] = 777;
9269
9270 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009271 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009272
9273 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009274 m_errorMonitor->SetUnexpectedError(
9275 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009276 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009278 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009279
9280 if (m_device->queue_props.size() > 2) {
9281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9282
9283 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9284 buffCI.queueFamilyIndexCount = 2;
9285 qfi[0] = 1;
9286 qfi[1] = 2;
9287 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9288 VkDeviceMemory mem;
9289 VkMemoryRequirements mem_reqs;
9290 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9291
9292 VkMemoryAllocateInfo alloc_info = {};
9293 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9294 alloc_info.allocationSize = 1024;
9295 bool pass = false;
9296 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9297 if (!pass) {
9298 vkDestroyBuffer(m_device->device(), ib, NULL);
9299 return;
9300 }
9301 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9302 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9303
9304 m_commandBuffer->begin();
9305 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9306 m_commandBuffer->end();
9307 QueueCommandBuffer(false);
9308 m_errorMonitor->VerifyFound();
9309 }
9310
Tony Barbourdf4c0042016-06-01 15:55:43 -06009311 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009312}
9313
Karl Schultz6addd812016-02-02 17:17:23 -07009314TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009315 TEST_DESCRIPTION(
9316 "Attempt vkCmdExecuteCommands with a primary command buffer"
9317 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009318
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009319 ASSERT_NO_FATAL_FAILURE(InitState());
9320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009321
Chris Forbesf29a84f2016-10-06 18:39:28 +13009322 // An empty primary command buffer
9323 VkCommandBufferObj cb(m_device, m_commandPool);
9324 cb.BeginCommandBuffer();
9325 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009326
Chris Forbesf29a84f2016-10-06 18:39:28 +13009327 m_commandBuffer->BeginCommandBuffer();
9328 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9329 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009330
Chris Forbesf29a84f2016-10-06 18:39:28 +13009331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9332 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009333 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009334
9335 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009336}
9337
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009338TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009339 TEST_DESCRIPTION(
9340 "Attempt to update descriptor sets for images and buffers "
9341 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009342 VkResult err;
9343
9344 ASSERT_NO_FATAL_FAILURE(InitState());
9345 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9346 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9347 ds_type_count[i].type = VkDescriptorType(i);
9348 ds_type_count[i].descriptorCount = 1;
9349 }
9350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9352 ds_pool_ci.pNext = NULL;
9353 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9354 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9355 ds_pool_ci.pPoolSizes = ds_type_count;
9356
9357 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009358 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009359 ASSERT_VK_SUCCESS(err);
9360
9361 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009363 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9364 dsl_binding[i].binding = 0;
9365 dsl_binding[i].descriptorType = VkDescriptorType(i);
9366 dsl_binding[i].descriptorCount = 1;
9367 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9368 dsl_binding[i].pImmutableSamplers = NULL;
9369 }
9370
9371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9373 ds_layout_ci.pNext = NULL;
9374 ds_layout_ci.bindingCount = 1;
9375 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9376 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9377 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009378 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009379 ASSERT_VK_SUCCESS(err);
9380 }
9381 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9382 VkDescriptorSetAllocateInfo alloc_info = {};
9383 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9384 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9385 alloc_info.descriptorPool = ds_pool;
9386 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009388 ASSERT_VK_SUCCESS(err);
9389
9390 // Create a buffer & bufferView to be used for invalid updates
9391 VkBufferCreateInfo buff_ci = {};
9392 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009393 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009394 buff_ci.size = 256;
9395 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009396 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009397 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9398 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009399
9400 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9401 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9402 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9403 ASSERT_VK_SUCCESS(err);
9404
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009405 VkMemoryRequirements mem_reqs;
9406 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9407 VkMemoryAllocateInfo mem_alloc_info = {};
9408 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9409 mem_alloc_info.pNext = NULL;
9410 mem_alloc_info.memoryTypeIndex = 0;
9411 mem_alloc_info.allocationSize = mem_reqs.size;
9412 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9413 if (!pass) {
9414 vkDestroyBuffer(m_device->device(), buffer, NULL);
9415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9416 return;
9417 }
9418 VkDeviceMemory mem;
9419 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9420 ASSERT_VK_SUCCESS(err);
9421 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009423
9424 VkBufferViewCreateInfo buff_view_ci = {};
9425 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9426 buff_view_ci.buffer = buffer;
9427 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9428 buff_view_ci.range = VK_WHOLE_SIZE;
9429 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009430 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009431 ASSERT_VK_SUCCESS(err);
9432
Tony Barbour415497c2017-01-24 10:06:09 -07009433 // Now get resources / view for storage_texel_buffer
9434 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9435 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9436 if (!pass) {
9437 vkDestroyBuffer(m_device->device(), buffer, NULL);
9438 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9439 vkFreeMemory(m_device->device(), mem, NULL);
9440 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9442 return;
9443 }
9444 VkDeviceMemory storage_texel_buffer_mem;
9445 VkBufferView storage_texel_buffer_view;
9446 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9447 ASSERT_VK_SUCCESS(err);
9448 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9449 ASSERT_VK_SUCCESS(err);
9450 buff_view_ci.buffer = storage_texel_buffer;
9451 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9452 ASSERT_VK_SUCCESS(err);
9453
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009454 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009455 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009456 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009457 image_ci.format = VK_FORMAT_UNDEFINED;
9458 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9459 VkFormat format = static_cast<VkFormat>(f);
9460 VkFormatProperties fProps = m_device->format_properties(format);
9461 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9462 image_ci.format = format;
9463 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9464 break;
9465 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9466 image_ci.format = format;
9467 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9468 break;
9469 }
9470 }
9471 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9472 return;
9473 }
9474
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9476 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009477 image_ci.extent.width = 64;
9478 image_ci.extent.height = 64;
9479 image_ci.extent.depth = 1;
9480 image_ci.mipLevels = 1;
9481 image_ci.arrayLayers = 1;
9482 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009483 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009484 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9486 VkImage image;
9487 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9488 ASSERT_VK_SUCCESS(err);
9489 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009490 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009491
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009492 VkMemoryAllocateInfo mem_alloc = {};
9493 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9494 mem_alloc.pNext = NULL;
9495 mem_alloc.allocationSize = 0;
9496 mem_alloc.memoryTypeIndex = 0;
9497 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9498 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009499 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009500 ASSERT_TRUE(pass);
9501 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9502 ASSERT_VK_SUCCESS(err);
9503 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9504 ASSERT_VK_SUCCESS(err);
9505 // Now create view for image
9506 VkImageViewCreateInfo image_view_ci = {};
9507 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9508 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009509 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9511 image_view_ci.subresourceRange.layerCount = 1;
9512 image_view_ci.subresourceRange.baseArrayLayer = 0;
9513 image_view_ci.subresourceRange.levelCount = 1;
9514 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9515 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009516 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009517 ASSERT_VK_SUCCESS(err);
9518
9519 VkDescriptorBufferInfo buff_info = {};
9520 buff_info.buffer = buffer;
9521 VkDescriptorImageInfo img_info = {};
9522 img_info.imageView = image_view;
9523 VkWriteDescriptorSet descriptor_write = {};
9524 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9525 descriptor_write.dstBinding = 0;
9526 descriptor_write.descriptorCount = 1;
9527 descriptor_write.pTexelBufferView = &buff_view;
9528 descriptor_write.pBufferInfo = &buff_info;
9529 descriptor_write.pImageInfo = &img_info;
9530
9531 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009532 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009533 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9534 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9535 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9536 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9537 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9538 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9539 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9540 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9541 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9542 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9543 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009544 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009545 // Start loop at 1 as SAMPLER desc type has no usage bit error
9546 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009547 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9548 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9549 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9550 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009551 descriptor_write.descriptorType = VkDescriptorType(i);
9552 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009555 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009556
9557 m_errorMonitor->VerifyFound();
9558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009559 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9560 descriptor_write.pTexelBufferView = &buff_view;
9561 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009562 }
Tony Barbour415497c2017-01-24 10:06:09 -07009563
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9565 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009566 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009567 vkDestroyImageView(m_device->device(), image_view, NULL);
9568 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009569 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009570 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009571 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009572 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009573 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9575}
9576
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009577TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009578 TEST_DESCRIPTION(
9579 "Attempt to update buffer descriptor set that has incorrect "
9580 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9581 "1. offset value greater than buffer size\n"
9582 "2. range value of 0\n"
9583 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009584 VkResult err;
9585
9586 ASSERT_NO_FATAL_FAILURE(InitState());
9587 VkDescriptorPoolSize ds_type_count = {};
9588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9589 ds_type_count.descriptorCount = 1;
9590
9591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9593 ds_pool_ci.pNext = NULL;
9594 ds_pool_ci.maxSets = 1;
9595 ds_pool_ci.poolSizeCount = 1;
9596 ds_pool_ci.pPoolSizes = &ds_type_count;
9597
9598 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009600 ASSERT_VK_SUCCESS(err);
9601
9602 // Create layout with single uniform buffer descriptor
9603 VkDescriptorSetLayoutBinding dsl_binding = {};
9604 dsl_binding.binding = 0;
9605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9606 dsl_binding.descriptorCount = 1;
9607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9608 dsl_binding.pImmutableSamplers = NULL;
9609
9610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9612 ds_layout_ci.pNext = NULL;
9613 ds_layout_ci.bindingCount = 1;
9614 ds_layout_ci.pBindings = &dsl_binding;
9615 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009617 ASSERT_VK_SUCCESS(err);
9618
9619 VkDescriptorSet descriptor_set = {};
9620 VkDescriptorSetAllocateInfo alloc_info = {};
9621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9622 alloc_info.descriptorSetCount = 1;
9623 alloc_info.descriptorPool = ds_pool;
9624 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009626 ASSERT_VK_SUCCESS(err);
9627
9628 // Create a buffer to be used for invalid updates
9629 VkBufferCreateInfo buff_ci = {};
9630 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9631 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9632 buff_ci.size = 256;
9633 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9634 VkBuffer buffer;
9635 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9636 ASSERT_VK_SUCCESS(err);
9637 // Have to bind memory to buffer before descriptor update
9638 VkMemoryAllocateInfo mem_alloc = {};
9639 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9640 mem_alloc.pNext = NULL;
9641 mem_alloc.allocationSize = 256;
9642 mem_alloc.memoryTypeIndex = 0;
9643
9644 VkMemoryRequirements mem_reqs;
9645 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009647 if (!pass) {
9648 vkDestroyBuffer(m_device->device(), buffer, NULL);
9649 return;
9650 }
9651
9652 VkDeviceMemory mem;
9653 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9654 ASSERT_VK_SUCCESS(err);
9655 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9656 ASSERT_VK_SUCCESS(err);
9657
9658 VkDescriptorBufferInfo buff_info = {};
9659 buff_info.buffer = buffer;
9660 // First make offset 1 larger than buffer size
9661 buff_info.offset = 257;
9662 buff_info.range = VK_WHOLE_SIZE;
9663 VkWriteDescriptorSet descriptor_write = {};
9664 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9665 descriptor_write.dstBinding = 0;
9666 descriptor_write.descriptorCount = 1;
9667 descriptor_write.pTexelBufferView = nullptr;
9668 descriptor_write.pBufferInfo = &buff_info;
9669 descriptor_write.pImageInfo = nullptr;
9670
9671 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9672 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009674
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009675 m_errorMonitor->SetUnexpectedError(
9676 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9677 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9679
9680 m_errorMonitor->VerifyFound();
9681 // Now cause error due to range of 0
9682 buff_info.offset = 0;
9683 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009685
9686 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9687
9688 m_errorMonitor->VerifyFound();
9689 // Now cause error due to range exceeding buffer size - offset
9690 buff_info.offset = 128;
9691 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009693
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009694 m_errorMonitor->SetUnexpectedError(
9695 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9696 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009697 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9698
9699 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009700 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009701 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9702 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009703 m_errorMonitor->SetUnexpectedError(
9704 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009705 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9706 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9707}
9708
Tobin Ehlis845887e2017-02-02 19:01:44 -07009709TEST_F(VkLayerTest, DSBufferLimitErrors) {
9710 TEST_DESCRIPTION(
9711 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9712 "Test cases include:\n"
9713 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9714 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9715 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9716 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9717 VkResult err;
9718
9719 ASSERT_NO_FATAL_FAILURE(InitState());
9720 VkDescriptorPoolSize ds_type_count[2] = {};
9721 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9722 ds_type_count[0].descriptorCount = 1;
9723 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9724 ds_type_count[1].descriptorCount = 1;
9725
9726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9728 ds_pool_ci.pNext = NULL;
9729 ds_pool_ci.maxSets = 1;
9730 ds_pool_ci.poolSizeCount = 2;
9731 ds_pool_ci.pPoolSizes = ds_type_count;
9732
9733 VkDescriptorPool ds_pool;
9734 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9735 ASSERT_VK_SUCCESS(err);
9736
9737 // Create layout with single uniform buffer & single storage buffer descriptor
9738 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9739 dsl_binding[0].binding = 0;
9740 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9741 dsl_binding[0].descriptorCount = 1;
9742 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9743 dsl_binding[0].pImmutableSamplers = NULL;
9744 dsl_binding[1].binding = 1;
9745 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9746 dsl_binding[1].descriptorCount = 1;
9747 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9748 dsl_binding[1].pImmutableSamplers = NULL;
9749
9750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9752 ds_layout_ci.pNext = NULL;
9753 ds_layout_ci.bindingCount = 2;
9754 ds_layout_ci.pBindings = dsl_binding;
9755 VkDescriptorSetLayout ds_layout;
9756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9757 ASSERT_VK_SUCCESS(err);
9758
9759 VkDescriptorSet descriptor_set = {};
9760 VkDescriptorSetAllocateInfo alloc_info = {};
9761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9762 alloc_info.descriptorSetCount = 1;
9763 alloc_info.descriptorPool = ds_pool;
9764 alloc_info.pSetLayouts = &ds_layout;
9765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9766 ASSERT_VK_SUCCESS(err);
9767
9768 // Create a buffer to be used for invalid updates
9769 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9770 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9771 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9772 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9773 VkBufferCreateInfo ub_ci = {};
9774 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9775 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9776 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9777 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9778 VkBuffer uniform_buffer;
9779 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9780 ASSERT_VK_SUCCESS(err);
9781 VkBufferCreateInfo sb_ci = {};
9782 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9783 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9784 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9785 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9786 VkBuffer storage_buffer;
9787 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9788 ASSERT_VK_SUCCESS(err);
9789 // Have to bind memory to buffer before descriptor update
9790 VkMemoryAllocateInfo mem_alloc = {};
9791 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9792 mem_alloc.pNext = NULL;
9793 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9794 mem_alloc.memoryTypeIndex = 0;
9795
9796 VkMemoryRequirements mem_reqs;
9797 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9798 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9799 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9800 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9801 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009803 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009804 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009806 return;
9807 }
9808
9809 VkDeviceMemory mem;
9810 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009811 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009812 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9814 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9815 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9817 return;
9818 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819 ASSERT_VK_SUCCESS(err);
9820 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9821 ASSERT_VK_SUCCESS(err);
9822 auto sb_offset = ub_ci.size + 1024;
9823 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9824 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9825 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9826 ASSERT_VK_SUCCESS(err);
9827
9828 VkDescriptorBufferInfo buff_info = {};
9829 buff_info.buffer = uniform_buffer;
9830 buff_info.range = ub_ci.size; // This will exceed limit
9831 VkWriteDescriptorSet descriptor_write = {};
9832 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9833 descriptor_write.dstBinding = 0;
9834 descriptor_write.descriptorCount = 1;
9835 descriptor_write.pTexelBufferView = nullptr;
9836 descriptor_write.pBufferInfo = &buff_info;
9837 descriptor_write.pImageInfo = nullptr;
9838
9839 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9840 descriptor_write.dstSet = descriptor_set;
9841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9842 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9843 m_errorMonitor->VerifyFound();
9844
9845 // Reduce size of range to acceptable limit & cause offset error
9846 buff_info.range = max_ub_range;
9847 buff_info.offset = min_ub_align - 1;
9848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9849 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9850 m_errorMonitor->VerifyFound();
9851
9852 // Now break storage updates
9853 buff_info.buffer = storage_buffer;
9854 buff_info.range = sb_ci.size; // This will exceed limit
9855 buff_info.offset = 0; // Reset offset for this update
9856
9857 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9858 descriptor_write.dstBinding = 1;
9859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9861 m_errorMonitor->VerifyFound();
9862
9863 // Reduce size of range to acceptable limit & cause offset error
9864 buff_info.range = max_sb_range;
9865 buff_info.offset = min_sb_align - 1;
9866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9868 m_errorMonitor->VerifyFound();
9869
9870 vkFreeMemory(m_device->device(), mem, NULL);
9871 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9872 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9873 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9875}
9876
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009877TEST_F(VkLayerTest, DSAspectBitsErrors) {
9878 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9879 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009880 TEST_DESCRIPTION(
9881 "Attempt to update descriptor sets for images "
9882 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009883 VkResult err;
9884
9885 ASSERT_NO_FATAL_FAILURE(InitState());
9886 VkDescriptorPoolSize ds_type_count = {};
9887 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9888 ds_type_count.descriptorCount = 1;
9889
9890 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9891 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9892 ds_pool_ci.pNext = NULL;
9893 ds_pool_ci.maxSets = 5;
9894 ds_pool_ci.poolSizeCount = 1;
9895 ds_pool_ci.pPoolSizes = &ds_type_count;
9896
9897 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009898 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009899 ASSERT_VK_SUCCESS(err);
9900
9901 VkDescriptorSetLayoutBinding dsl_binding = {};
9902 dsl_binding.binding = 0;
9903 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9904 dsl_binding.descriptorCount = 1;
9905 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9906 dsl_binding.pImmutableSamplers = NULL;
9907
9908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9910 ds_layout_ci.pNext = NULL;
9911 ds_layout_ci.bindingCount = 1;
9912 ds_layout_ci.pBindings = &dsl_binding;
9913 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009915 ASSERT_VK_SUCCESS(err);
9916
9917 VkDescriptorSet descriptor_set = {};
9918 VkDescriptorSetAllocateInfo alloc_info = {};
9919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9920 alloc_info.descriptorSetCount = 1;
9921 alloc_info.descriptorPool = ds_pool;
9922 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009924 ASSERT_VK_SUCCESS(err);
9925
9926 // Create an image to be used for invalid updates
9927 VkImageCreateInfo image_ci = {};
9928 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9929 image_ci.imageType = VK_IMAGE_TYPE_2D;
9930 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9931 image_ci.extent.width = 64;
9932 image_ci.extent.height = 64;
9933 image_ci.extent.depth = 1;
9934 image_ci.mipLevels = 1;
9935 image_ci.arrayLayers = 1;
9936 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9937 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9938 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9939 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9940 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9941 VkImage image;
9942 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9943 ASSERT_VK_SUCCESS(err);
9944 // Bind memory to image
9945 VkMemoryRequirements mem_reqs;
9946 VkDeviceMemory image_mem;
9947 bool pass;
9948 VkMemoryAllocateInfo mem_alloc = {};
9949 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9950 mem_alloc.pNext = NULL;
9951 mem_alloc.allocationSize = 0;
9952 mem_alloc.memoryTypeIndex = 0;
9953 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9954 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009955 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009956 ASSERT_TRUE(pass);
9957 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9958 ASSERT_VK_SUCCESS(err);
9959 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9960 ASSERT_VK_SUCCESS(err);
9961 // Now create view for image
9962 VkImageViewCreateInfo image_view_ci = {};
9963 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9964 image_view_ci.image = image;
9965 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9966 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9967 image_view_ci.subresourceRange.layerCount = 1;
9968 image_view_ci.subresourceRange.baseArrayLayer = 0;
9969 image_view_ci.subresourceRange.levelCount = 1;
9970 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009971 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009972
9973 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009975 ASSERT_VK_SUCCESS(err);
9976
9977 VkDescriptorImageInfo img_info = {};
9978 img_info.imageView = image_view;
9979 VkWriteDescriptorSet descriptor_write = {};
9980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9981 descriptor_write.dstBinding = 0;
9982 descriptor_write.descriptorCount = 1;
9983 descriptor_write.pTexelBufferView = NULL;
9984 descriptor_write.pBufferInfo = NULL;
9985 descriptor_write.pImageInfo = &img_info;
9986 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9987 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009988 const char *error_msg =
9989 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9990 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009992
9993 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9994
9995 m_errorMonitor->VerifyFound();
9996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9997 vkDestroyImage(m_device->device(), image, NULL);
9998 vkFreeMemory(m_device->device(), image_mem, NULL);
9999 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010000 m_errorMonitor->SetUnexpectedError(
10001 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010002 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10003 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10004}
10005
Karl Schultz6addd812016-02-02 17:17:23 -070010006TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010007 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010008 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10011 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10012 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010013
Tobin Ehlis3b780662015-05-28 12:11:26 -060010014 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010015 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010016 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010017 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10018 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010019
10020 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010021 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10022 ds_pool_ci.pNext = NULL;
10023 ds_pool_ci.maxSets = 1;
10024 ds_pool_ci.poolSizeCount = 1;
10025 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010026
Tobin Ehlis3b780662015-05-28 12:11:26 -060010027 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010029 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010030 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010031 dsl_binding.binding = 0;
10032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10033 dsl_binding.descriptorCount = 1;
10034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10035 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010036
Tony Barboureb254902015-07-15 12:50:33 -060010037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10039 ds_layout_ci.pNext = NULL;
10040 ds_layout_ci.bindingCount = 1;
10041 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010042
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010045 ASSERT_VK_SUCCESS(err);
10046
10047 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010048 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010049 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010050 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010051 alloc_info.descriptorPool = ds_pool;
10052 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010054 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010055
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010056 VkSamplerCreateInfo sampler_ci = {};
10057 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10058 sampler_ci.pNext = NULL;
10059 sampler_ci.magFilter = VK_FILTER_NEAREST;
10060 sampler_ci.minFilter = VK_FILTER_NEAREST;
10061 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10062 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10063 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10064 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10065 sampler_ci.mipLodBias = 1.0;
10066 sampler_ci.anisotropyEnable = VK_FALSE;
10067 sampler_ci.maxAnisotropy = 1;
10068 sampler_ci.compareEnable = VK_FALSE;
10069 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10070 sampler_ci.minLod = 1.0;
10071 sampler_ci.maxLod = 1.0;
10072 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10073 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10074 VkSampler sampler;
10075 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10076 ASSERT_VK_SUCCESS(err);
10077
10078 VkDescriptorImageInfo info = {};
10079 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010080
10081 VkWriteDescriptorSet descriptor_write;
10082 memset(&descriptor_write, 0, sizeof(descriptor_write));
10083 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010084 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010085 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010086 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010087 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010088 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010089
10090 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10091
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010092 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010093
Chia-I Wuf7458c52015-10-26 21:10:41 +080010094 vkDestroySampler(m_device->device(), sampler, NULL);
10095 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10096 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010097}
10098
Karl Schultz6addd812016-02-02 17:17:23 -070010099TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010100 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010101 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010102
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010104
Tobin Ehlis3b780662015-05-28 12:11:26 -060010105 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010106 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010107 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010108 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10109 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010110
10111 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010112 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10113 ds_pool_ci.pNext = NULL;
10114 ds_pool_ci.maxSets = 1;
10115 ds_pool_ci.poolSizeCount = 1;
10116 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010117
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010119 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010120 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121
Tony Barboureb254902015-07-15 12:50:33 -060010122 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010123 dsl_binding.binding = 0;
10124 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10125 dsl_binding.descriptorCount = 1;
10126 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10127 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010128
10129 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010130 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10131 ds_layout_ci.pNext = NULL;
10132 ds_layout_ci.bindingCount = 1;
10133 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010134
Tobin Ehlis3b780662015-05-28 12:11:26 -060010135 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010137 ASSERT_VK_SUCCESS(err);
10138
10139 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010140 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010142 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010143 alloc_info.descriptorPool = ds_pool;
10144 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010147
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010148 // Correctly update descriptor to avoid "NOT_UPDATED" error
10149 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010150 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010151 buff_info.offset = 0;
10152 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010153
10154 VkWriteDescriptorSet descriptor_write;
10155 memset(&descriptor_write, 0, sizeof(descriptor_write));
10156 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010157 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010158 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010159 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010160 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10161 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010162
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010163 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010164 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10165
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010166 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010167
Chia-I Wuf7458c52015-10-26 21:10:41 +080010168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010170}
10171
Karl Schultz6addd812016-02-02 17:17:23 -070010172TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010173 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010174 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010175
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010177
Tobin Ehlis3b780662015-05-28 12:11:26 -060010178 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010179 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10182 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010183
10184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10186 ds_pool_ci.pNext = NULL;
10187 ds_pool_ci.maxSets = 1;
10188 ds_pool_ci.poolSizeCount = 1;
10189 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010190
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010193 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010194
Tony Barboureb254902015-07-15 12:50:33 -060010195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010196 dsl_binding.binding = 0;
10197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10198 dsl_binding.descriptorCount = 1;
10199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10200 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010201
10202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10204 ds_layout_ci.pNext = NULL;
10205 ds_layout_ci.bindingCount = 1;
10206 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010207 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010209 ASSERT_VK_SUCCESS(err);
10210
10211 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010212 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010213 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010214 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010215 alloc_info.descriptorPool = ds_pool;
10216 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010217 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010218 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010219
Tony Barboureb254902015-07-15 12:50:33 -060010220 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010221 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10222 sampler_ci.pNext = NULL;
10223 sampler_ci.magFilter = VK_FILTER_NEAREST;
10224 sampler_ci.minFilter = VK_FILTER_NEAREST;
10225 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10226 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10227 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10228 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10229 sampler_ci.mipLodBias = 1.0;
10230 sampler_ci.anisotropyEnable = VK_FALSE;
10231 sampler_ci.maxAnisotropy = 1;
10232 sampler_ci.compareEnable = VK_FALSE;
10233 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10234 sampler_ci.minLod = 1.0;
10235 sampler_ci.maxLod = 1.0;
10236 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10237 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010238
Tobin Ehlis3b780662015-05-28 12:11:26 -060010239 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010240 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010241 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010242
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010243 VkDescriptorImageInfo info = {};
10244 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010245
10246 VkWriteDescriptorSet descriptor_write;
10247 memset(&descriptor_write, 0, sizeof(descriptor_write));
10248 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010249 descriptor_write.dstSet = descriptorSet;
10250 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010251 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010252 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010253 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010254 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010255
10256 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010259
Chia-I Wuf7458c52015-10-26 21:10:41 +080010260 vkDestroySampler(m_device->device(), sampler, NULL);
10261 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010263}
10264
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010265TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10266 // Create layout w/ empty binding and attempt to update it
10267 VkResult err;
10268
10269 ASSERT_NO_FATAL_FAILURE(InitState());
10270
10271 VkDescriptorPoolSize ds_type_count = {};
10272 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10273 ds_type_count.descriptorCount = 1;
10274
10275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10277 ds_pool_ci.pNext = NULL;
10278 ds_pool_ci.maxSets = 1;
10279 ds_pool_ci.poolSizeCount = 1;
10280 ds_pool_ci.pPoolSizes = &ds_type_count;
10281
10282 VkDescriptorPool ds_pool;
10283 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10284 ASSERT_VK_SUCCESS(err);
10285
10286 VkDescriptorSetLayoutBinding dsl_binding = {};
10287 dsl_binding.binding = 0;
10288 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10289 dsl_binding.descriptorCount = 0;
10290 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10291 dsl_binding.pImmutableSamplers = NULL;
10292
10293 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10294 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10295 ds_layout_ci.pNext = NULL;
10296 ds_layout_ci.bindingCount = 1;
10297 ds_layout_ci.pBindings = &dsl_binding;
10298 VkDescriptorSetLayout ds_layout;
10299 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10300 ASSERT_VK_SUCCESS(err);
10301
10302 VkDescriptorSet descriptor_set;
10303 VkDescriptorSetAllocateInfo alloc_info = {};
10304 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10305 alloc_info.descriptorSetCount = 1;
10306 alloc_info.descriptorPool = ds_pool;
10307 alloc_info.pSetLayouts = &ds_layout;
10308 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10309 ASSERT_VK_SUCCESS(err);
10310
10311 VkSamplerCreateInfo sampler_ci = {};
10312 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10313 sampler_ci.magFilter = VK_FILTER_NEAREST;
10314 sampler_ci.minFilter = VK_FILTER_NEAREST;
10315 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10316 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10317 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10318 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10319 sampler_ci.mipLodBias = 1.0;
10320 sampler_ci.maxAnisotropy = 1;
10321 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10322 sampler_ci.minLod = 1.0;
10323 sampler_ci.maxLod = 1.0;
10324 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10325
10326 VkSampler sampler;
10327 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10328 ASSERT_VK_SUCCESS(err);
10329
10330 VkDescriptorImageInfo info = {};
10331 info.sampler = sampler;
10332
10333 VkWriteDescriptorSet descriptor_write;
10334 memset(&descriptor_write, 0, sizeof(descriptor_write));
10335 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10336 descriptor_write.dstSet = descriptor_set;
10337 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010338 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010339 // This is the wrong type, but empty binding error will be flagged first
10340 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10341 descriptor_write.pImageInfo = &info;
10342
10343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10344 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10345 m_errorMonitor->VerifyFound();
10346
10347 vkDestroySampler(m_device->device(), sampler, NULL);
10348 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10349 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10350}
10351
Karl Schultz6addd812016-02-02 17:17:23 -070010352TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10353 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10354 // types
10355 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 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 -060010358
Tobin Ehlis3b780662015-05-28 12:11:26 -060010359 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010360
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010361 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010362 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10363 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010364
10365 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010366 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10367 ds_pool_ci.pNext = NULL;
10368 ds_pool_ci.maxSets = 1;
10369 ds_pool_ci.poolSizeCount = 1;
10370 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010371
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010374 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010375 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010376 dsl_binding.binding = 0;
10377 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10378 dsl_binding.descriptorCount = 1;
10379 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10380 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010381
Tony Barboureb254902015-07-15 12:50:33 -060010382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10384 ds_layout_ci.pNext = NULL;
10385 ds_layout_ci.bindingCount = 1;
10386 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010387
Tobin Ehlis3b780662015-05-28 12:11:26 -060010388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010390 ASSERT_VK_SUCCESS(err);
10391
10392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010396 alloc_info.descriptorPool = ds_pool;
10397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010399 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010400
Tony Barboureb254902015-07-15 12:50:33 -060010401 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010402 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10403 sampler_ci.pNext = NULL;
10404 sampler_ci.magFilter = VK_FILTER_NEAREST;
10405 sampler_ci.minFilter = VK_FILTER_NEAREST;
10406 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10407 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10408 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10409 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10410 sampler_ci.mipLodBias = 1.0;
10411 sampler_ci.anisotropyEnable = VK_FALSE;
10412 sampler_ci.maxAnisotropy = 1;
10413 sampler_ci.compareEnable = VK_FALSE;
10414 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10415 sampler_ci.minLod = 1.0;
10416 sampler_ci.maxLod = 1.0;
10417 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10418 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010419 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010420 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010421 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010422
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010423 VkDescriptorImageInfo info = {};
10424 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010425
10426 VkWriteDescriptorSet descriptor_write;
10427 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010428 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010429 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010430 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010431 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010432 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010433 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010434
10435 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010437 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010438
Chia-I Wuf7458c52015-10-26 21:10:41 +080010439 vkDestroySampler(m_device->device(), sampler, NULL);
10440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010442}
10443
Karl Schultz6addd812016-02-02 17:17:23 -070010444TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010445 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010446 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010447
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010449
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010450 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010451 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10452 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010453 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010454 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10455 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010456
10457 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010458 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10459 ds_pool_ci.pNext = NULL;
10460 ds_pool_ci.maxSets = 1;
10461 ds_pool_ci.poolSizeCount = 1;
10462 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010463
10464 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466 ASSERT_VK_SUCCESS(err);
10467
10468 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010469 dsl_binding.binding = 0;
10470 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10471 dsl_binding.descriptorCount = 1;
10472 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10473 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010474
10475 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010476 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10477 ds_layout_ci.pNext = NULL;
10478 ds_layout_ci.bindingCount = 1;
10479 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010480 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010482 ASSERT_VK_SUCCESS(err);
10483
10484 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010485 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010486 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010487 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010488 alloc_info.descriptorPool = ds_pool;
10489 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010491 ASSERT_VK_SUCCESS(err);
10492
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010493 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010494
10495 VkDescriptorImageInfo descriptor_info;
10496 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10497 descriptor_info.sampler = sampler;
10498
10499 VkWriteDescriptorSet descriptor_write;
10500 memset(&descriptor_write, 0, sizeof(descriptor_write));
10501 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010502 descriptor_write.dstSet = descriptorSet;
10503 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010504 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010505 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10506 descriptor_write.pImageInfo = &descriptor_info;
10507
10508 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10509
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010510 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010511
Chia-I Wuf7458c52015-10-26 21:10:41 +080010512 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10513 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010514}
10515
Karl Schultz6addd812016-02-02 17:17:23 -070010516TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10517 // Create a single combined Image/Sampler descriptor and send it an invalid
10518 // imageView
10519 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010520
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010522
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010523 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010524 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010525 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10526 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010527
10528 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010529 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10530 ds_pool_ci.pNext = NULL;
10531 ds_pool_ci.maxSets = 1;
10532 ds_pool_ci.poolSizeCount = 1;
10533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010534
10535 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010536 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010537 ASSERT_VK_SUCCESS(err);
10538
10539 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010540 dsl_binding.binding = 0;
10541 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10542 dsl_binding.descriptorCount = 1;
10543 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10544 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010545
10546 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010547 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10548 ds_layout_ci.pNext = NULL;
10549 ds_layout_ci.bindingCount = 1;
10550 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010551 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010553 ASSERT_VK_SUCCESS(err);
10554
10555 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010556 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010558 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010559 alloc_info.descriptorPool = ds_pool;
10560 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010562 ASSERT_VK_SUCCESS(err);
10563
10564 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010565 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10566 sampler_ci.pNext = NULL;
10567 sampler_ci.magFilter = VK_FILTER_NEAREST;
10568 sampler_ci.minFilter = VK_FILTER_NEAREST;
10569 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10570 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10571 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10572 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10573 sampler_ci.mipLodBias = 1.0;
10574 sampler_ci.anisotropyEnable = VK_FALSE;
10575 sampler_ci.maxAnisotropy = 1;
10576 sampler_ci.compareEnable = VK_FALSE;
10577 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10578 sampler_ci.minLod = 1.0;
10579 sampler_ci.maxLod = 1.0;
10580 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10581 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010582
10583 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010584 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010585 ASSERT_VK_SUCCESS(err);
10586
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010587 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010588
10589 VkDescriptorImageInfo descriptor_info;
10590 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10591 descriptor_info.sampler = sampler;
10592 descriptor_info.imageView = view;
10593
10594 VkWriteDescriptorSet descriptor_write;
10595 memset(&descriptor_write, 0, sizeof(descriptor_write));
10596 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010597 descriptor_write.dstSet = descriptorSet;
10598 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010599 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010600 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10601 descriptor_write.pImageInfo = &descriptor_info;
10602
10603 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010605 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010606
Chia-I Wuf7458c52015-10-26 21:10:41 +080010607 vkDestroySampler(m_device->device(), sampler, NULL);
10608 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10609 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010610}
10611
Karl Schultz6addd812016-02-02 17:17:23 -070010612TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10613 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10614 // into the other
10615 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010616
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10618 " binding #1 with type "
10619 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10620 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010621
Tobin Ehlis04356f92015-10-27 16:35:27 -060010622 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010623 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010624 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010625 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10626 ds_type_count[0].descriptorCount = 1;
10627 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10628 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010629
10630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10632 ds_pool_ci.pNext = NULL;
10633 ds_pool_ci.maxSets = 1;
10634 ds_pool_ci.poolSizeCount = 2;
10635 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010636
10637 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010639 ASSERT_VK_SUCCESS(err);
10640 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010641 dsl_binding[0].binding = 0;
10642 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10643 dsl_binding[0].descriptorCount = 1;
10644 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10645 dsl_binding[0].pImmutableSamplers = NULL;
10646 dsl_binding[1].binding = 1;
10647 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10648 dsl_binding[1].descriptorCount = 1;
10649 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10650 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010651
10652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10654 ds_layout_ci.pNext = NULL;
10655 ds_layout_ci.bindingCount = 2;
10656 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010657
10658 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010660 ASSERT_VK_SUCCESS(err);
10661
10662 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010663 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010664 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010665 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010666 alloc_info.descriptorPool = ds_pool;
10667 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010668 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010669 ASSERT_VK_SUCCESS(err);
10670
10671 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010672 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10673 sampler_ci.pNext = NULL;
10674 sampler_ci.magFilter = VK_FILTER_NEAREST;
10675 sampler_ci.minFilter = VK_FILTER_NEAREST;
10676 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10677 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10678 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10679 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10680 sampler_ci.mipLodBias = 1.0;
10681 sampler_ci.anisotropyEnable = VK_FALSE;
10682 sampler_ci.maxAnisotropy = 1;
10683 sampler_ci.compareEnable = VK_FALSE;
10684 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10685 sampler_ci.minLod = 1.0;
10686 sampler_ci.maxLod = 1.0;
10687 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10688 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689
10690 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010691 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010692 ASSERT_VK_SUCCESS(err);
10693
10694 VkDescriptorImageInfo info = {};
10695 info.sampler = sampler;
10696
10697 VkWriteDescriptorSet descriptor_write;
10698 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10699 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010700 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010701 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010702 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010703 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10704 descriptor_write.pImageInfo = &info;
10705 // This write update should succeed
10706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10707 // Now perform a copy update that fails due to type mismatch
10708 VkCopyDescriptorSet copy_ds_update;
10709 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10710 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10711 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010712 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010713 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010714 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10715 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010716 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010718 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010719 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 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 -060010721 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10722 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10723 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010724 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010725 copy_ds_update.dstSet = descriptorSet;
10726 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010727 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010728 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010730 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010731
Tobin Ehlis04356f92015-10-27 16:35:27 -060010732 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10734 " binding#1 with offset index of 1 plus "
10735 "update array offset of 0 and update of "
10736 "5 descriptors oversteps total number "
10737 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010738
Tobin Ehlis04356f92015-10-27 16:35:27 -060010739 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10740 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10741 copy_ds_update.srcSet = descriptorSet;
10742 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010743 copy_ds_update.dstSet = descriptorSet;
10744 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010745 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010746 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010748 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010749
Chia-I Wuf7458c52015-10-26 21:10:41 +080010750 vkDestroySampler(m_device->device(), sampler, NULL);
10751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010753}
10754
Karl Schultz6addd812016-02-02 17:17:23 -070010755TEST_F(VkLayerTest, NumSamplesMismatch) {
10756 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10757 // sampleCount
10758 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010761
Tobin Ehlis3b780662015-05-28 12:11:26 -060010762 ASSERT_NO_FATAL_FAILURE(InitState());
10763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010764 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010767
10768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10770 ds_pool_ci.pNext = NULL;
10771 ds_pool_ci.maxSets = 1;
10772 ds_pool_ci.poolSizeCount = 1;
10773 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010774
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010777 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010778
Tony Barboureb254902015-07-15 12:50:33 -060010779 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010780 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010782 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010785
Tony Barboureb254902015-07-15 12:50:33 -060010786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10788 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010789 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010790 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010791
Tobin Ehlis3b780662015-05-28 12:11:26 -060010792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_VK_SUCCESS(err);
10795
10796 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010799 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010800 alloc_info.descriptorPool = ds_pool;
10801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010803 ASSERT_VK_SUCCESS(err);
10804
Tony Barboureb254902015-07-15 12:50:33 -060010805 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010806 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010807 pipe_ms_state_ci.pNext = NULL;
10808 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10809 pipe_ms_state_ci.sampleShadingEnable = 0;
10810 pipe_ms_state_ci.minSampleShading = 1.0;
10811 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010812
Tony Barboureb254902015-07-15 12:50:33 -060010813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010814 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10815 pipeline_layout_ci.pNext = NULL;
10816 pipeline_layout_ci.setLayoutCount = 1;
10817 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010818
10819 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010820 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010821 ASSERT_VK_SUCCESS(err);
10822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010824 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 -060010825 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010826 VkPipelineObj pipe(m_device);
10827 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010828 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010829 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010830 pipe.SetMSAA(&pipe_ms_state_ci);
10831 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010832
Tony Barbour552f6c02016-12-21 14:34:07 -070010833 m_commandBuffer->BeginCommandBuffer();
10834 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010835 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010836
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010837 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10838 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10839 VkRect2D scissor = {{0, 0}, {16, 16}};
10840 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10841
Mark Young29927482016-05-04 14:38:51 -060010842 // Render triangle (the error should trigger on the attempt to draw).
10843 Draw(3, 1, 0, 0);
10844
10845 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010846 m_commandBuffer->EndRenderPass();
10847 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010848
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010849 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010850
Chia-I Wuf7458c52015-10-26 21:10:41 +080010851 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10852 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10853 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010854}
Mark Young29927482016-05-04 14:38:51 -060010855
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010856TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010857 TEST_DESCRIPTION(
10858 "Hit RenderPass incompatible cases. "
10859 "Initial case is drawing with an active renderpass that's "
10860 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010861 VkResult err;
10862
10863 ASSERT_NO_FATAL_FAILURE(InitState());
10864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10865
10866 VkDescriptorSetLayoutBinding dsl_binding = {};
10867 dsl_binding.binding = 0;
10868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10869 dsl_binding.descriptorCount = 1;
10870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10871 dsl_binding.pImmutableSamplers = NULL;
10872
10873 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10874 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10875 ds_layout_ci.pNext = NULL;
10876 ds_layout_ci.bindingCount = 1;
10877 ds_layout_ci.pBindings = &dsl_binding;
10878
10879 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010880 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010881 ASSERT_VK_SUCCESS(err);
10882
10883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10885 pipeline_layout_ci.pNext = NULL;
10886 pipeline_layout_ci.setLayoutCount = 1;
10887 pipeline_layout_ci.pSetLayouts = &ds_layout;
10888
10889 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010890 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010891 ASSERT_VK_SUCCESS(err);
10892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010893 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010894 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 -060010895 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010896 // Create a renderpass that will be incompatible with default renderpass
10897 VkAttachmentReference attach = {};
10898 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10899 VkAttachmentReference color_att = {};
10900 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10901 VkSubpassDescription subpass = {};
10902 subpass.inputAttachmentCount = 1;
10903 subpass.pInputAttachments = &attach;
10904 subpass.colorAttachmentCount = 1;
10905 subpass.pColorAttachments = &color_att;
10906 VkRenderPassCreateInfo rpci = {};
10907 rpci.subpassCount = 1;
10908 rpci.pSubpasses = &subpass;
10909 rpci.attachmentCount = 1;
10910 VkAttachmentDescription attach_desc = {};
10911 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010912 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10913 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010914 rpci.pAttachments = &attach_desc;
10915 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10916 VkRenderPass rp;
10917 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10918 VkPipelineObj pipe(m_device);
10919 pipe.AddShader(&vs);
10920 pipe.AddShader(&fs);
10921 pipe.AddColorAttachment();
10922 VkViewport view_port = {};
10923 m_viewports.push_back(view_port);
10924 pipe.SetViewport(m_viewports);
10925 VkRect2D rect = {};
10926 m_scissors.push_back(rect);
10927 pipe.SetScissor(m_scissors);
10928 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10929
10930 VkCommandBufferInheritanceInfo cbii = {};
10931 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10932 cbii.renderPass = rp;
10933 cbii.subpass = 0;
10934 VkCommandBufferBeginInfo cbbi = {};
10935 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10936 cbbi.pInheritanceInfo = &cbii;
10937 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10938 VkRenderPassBeginInfo rpbi = {};
10939 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10940 rpbi.framebuffer = m_framebuffer;
10941 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10943 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010946 // Render triangle (the error should trigger on the attempt to draw).
10947 Draw(3, 1, 0, 0);
10948
10949 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010950 m_commandBuffer->EndRenderPass();
10951 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010952
10953 m_errorMonitor->VerifyFound();
10954
10955 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10956 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10957 vkDestroyRenderPass(m_device->device(), rp, NULL);
10958}
10959
Mark Youngc89c6312016-03-31 16:03:20 -060010960TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10961 // Create Pipeline where the number of blend attachments doesn't match the
10962 // number of color attachments. In this case, we don't add any color
10963 // blend attachments even though we have a color attachment.
10964 VkResult err;
10965
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010967
10968 ASSERT_NO_FATAL_FAILURE(InitState());
10969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10970 VkDescriptorPoolSize ds_type_count = {};
10971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10972 ds_type_count.descriptorCount = 1;
10973
10974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10976 ds_pool_ci.pNext = NULL;
10977 ds_pool_ci.maxSets = 1;
10978 ds_pool_ci.poolSizeCount = 1;
10979 ds_pool_ci.pPoolSizes = &ds_type_count;
10980
10981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010983 ASSERT_VK_SUCCESS(err);
10984
10985 VkDescriptorSetLayoutBinding dsl_binding = {};
10986 dsl_binding.binding = 0;
10987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10988 dsl_binding.descriptorCount = 1;
10989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10990 dsl_binding.pImmutableSamplers = NULL;
10991
10992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10994 ds_layout_ci.pNext = NULL;
10995 ds_layout_ci.bindingCount = 1;
10996 ds_layout_ci.pBindings = &dsl_binding;
10997
10998 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011000 ASSERT_VK_SUCCESS(err);
11001
11002 VkDescriptorSet descriptorSet;
11003 VkDescriptorSetAllocateInfo alloc_info = {};
11004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11005 alloc_info.descriptorSetCount = 1;
11006 alloc_info.descriptorPool = ds_pool;
11007 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011009 ASSERT_VK_SUCCESS(err);
11010
11011 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011013 pipe_ms_state_ci.pNext = NULL;
11014 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11015 pipe_ms_state_ci.sampleShadingEnable = 0;
11016 pipe_ms_state_ci.minSampleShading = 1.0;
11017 pipe_ms_state_ci.pSampleMask = NULL;
11018
11019 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11020 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11021 pipeline_layout_ci.pNext = NULL;
11022 pipeline_layout_ci.setLayoutCount = 1;
11023 pipeline_layout_ci.pSetLayouts = &ds_layout;
11024
11025 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011027 ASSERT_VK_SUCCESS(err);
11028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011029 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011030 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 -060011031 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011032 VkPipelineObj pipe(m_device);
11033 pipe.AddShader(&vs);
11034 pipe.AddShader(&fs);
11035 pipe.SetMSAA(&pipe_ms_state_ci);
11036 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011037 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011038
11039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11042}
Mark Young29927482016-05-04 14:38:51 -060011043
Mark Muellerd4914412016-06-13 17:52:06 -060011044TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011045 TEST_DESCRIPTION(
11046 "Points to a wrong colorAttachment index in a VkClearAttachment "
11047 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011048 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011050
11051 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11052 m_errorMonitor->VerifyFound();
11053}
11054
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011055TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011056 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11057 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011058
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011059 ASSERT_NO_FATAL_FAILURE(InitState());
11060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011061
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011063 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11064 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011065
11066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11068 ds_pool_ci.pNext = NULL;
11069 ds_pool_ci.maxSets = 1;
11070 ds_pool_ci.poolSizeCount = 1;
11071 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011072
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011073 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011074 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011075 ASSERT_VK_SUCCESS(err);
11076
Tony Barboureb254902015-07-15 12:50:33 -060011077 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011078 dsl_binding.binding = 0;
11079 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11080 dsl_binding.descriptorCount = 1;
11081 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11082 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011083
Tony Barboureb254902015-07-15 12:50:33 -060011084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11086 ds_layout_ci.pNext = NULL;
11087 ds_layout_ci.bindingCount = 1;
11088 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011089
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011090 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011092 ASSERT_VK_SUCCESS(err);
11093
11094 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011095 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011097 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011098 alloc_info.descriptorPool = ds_pool;
11099 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011101 ASSERT_VK_SUCCESS(err);
11102
Tony Barboureb254902015-07-15 12:50:33 -060011103 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011104 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011105 pipe_ms_state_ci.pNext = NULL;
11106 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11107 pipe_ms_state_ci.sampleShadingEnable = 0;
11108 pipe_ms_state_ci.minSampleShading = 1.0;
11109 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011110
Tony Barboureb254902015-07-15 12:50:33 -060011111 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011112 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11113 pipeline_layout_ci.pNext = NULL;
11114 pipeline_layout_ci.setLayoutCount = 1;
11115 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011116
11117 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011119 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011122 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011123 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011124 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011125
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011126 VkPipelineObj pipe(m_device);
11127 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011128 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011129 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011130 m_errorMonitor->SetUnexpectedError(
11131 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11132 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011133 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011134
Tony Barbour552f6c02016-12-21 14:34:07 -070011135 m_commandBuffer->BeginCommandBuffer();
11136 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011137
Karl Schultz6addd812016-02-02 17:17:23 -070011138 // Main thing we care about for this test is that the VkImage obj we're
11139 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011140 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011141 VkClearAttachment color_attachment;
11142 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11143 color_attachment.clearValue.color.float32[0] = 1.0;
11144 color_attachment.clearValue.color.float32[1] = 1.0;
11145 color_attachment.clearValue.color.float32[2] = 1.0;
11146 color_attachment.clearValue.color.float32[3] = 1.0;
11147 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011149
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011150 // Call for full-sized FB Color attachment prior to issuing a Draw
11151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011152 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011154 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011155
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011156 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11157 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11159 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11160 m_errorMonitor->VerifyFound();
11161
11162 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11163 clear_rect.layerCount = 2;
11164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11165 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011166 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011167
Chia-I Wuf7458c52015-10-26 21:10:41 +080011168 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11169 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11170 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011171}
11172
Karl Schultz6addd812016-02-02 17:17:23 -070011173TEST_F(VkLayerTest, VtxBufferBadIndex) {
11174 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11177 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011178
Tobin Ehlis502480b2015-06-24 15:53:07 -060011179 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011180 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011182
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011183 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011184 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11185 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011186
11187 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011188 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11189 ds_pool_ci.pNext = NULL;
11190 ds_pool_ci.maxSets = 1;
11191 ds_pool_ci.poolSizeCount = 1;
11192 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011193
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011194 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011196 ASSERT_VK_SUCCESS(err);
11197
Tony Barboureb254902015-07-15 12:50:33 -060011198 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011199 dsl_binding.binding = 0;
11200 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11201 dsl_binding.descriptorCount = 1;
11202 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11203 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011204
Tony Barboureb254902015-07-15 12:50:33 -060011205 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011206 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11207 ds_layout_ci.pNext = NULL;
11208 ds_layout_ci.bindingCount = 1;
11209 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011210
Tobin Ehlis502480b2015-06-24 15:53:07 -060011211 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011213 ASSERT_VK_SUCCESS(err);
11214
11215 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011216 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011217 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011218 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011219 alloc_info.descriptorPool = ds_pool;
11220 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011221 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011222 ASSERT_VK_SUCCESS(err);
11223
Tony Barboureb254902015-07-15 12:50:33 -060011224 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011225 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011226 pipe_ms_state_ci.pNext = NULL;
11227 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11228 pipe_ms_state_ci.sampleShadingEnable = 0;
11229 pipe_ms_state_ci.minSampleShading = 1.0;
11230 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011231
Tony Barboureb254902015-07-15 12:50:33 -060011232 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011233 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11234 pipeline_layout_ci.pNext = NULL;
11235 pipeline_layout_ci.setLayoutCount = 1;
11236 pipeline_layout_ci.pSetLayouts = &ds_layout;
11237 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011240 ASSERT_VK_SUCCESS(err);
11241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011243 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 -060011244 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011245 VkPipelineObj pipe(m_device);
11246 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011247 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011248 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011249 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011250 pipe.SetViewport(m_viewports);
11251 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011252 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011253
Tony Barbour552f6c02016-12-21 14:34:07 -070011254 m_commandBuffer->BeginCommandBuffer();
11255 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011257 // Don't care about actual data, just need to get to draw to flag error
11258 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011260 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011261 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011263 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011264
Chia-I Wuf7458c52015-10-26 21:10:41 +080011265 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011268}
Mark Muellerdfe37552016-07-07 14:47:42 -060011269
Mark Mueller2ee294f2016-08-04 12:59:48 -060011270TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011271 TEST_DESCRIPTION(
11272 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11273 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011274 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011275
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011276 const char *invalid_queueFamilyIndex_message =
11277 "Invalid queue create request in vkCreateDevice(). Invalid "
11278 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011280 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011281
Mark Mueller880fce52016-08-17 15:23:23 -060011282 // The following test fails with recent NVidia drivers.
11283 // By the time core_validation is reached, the NVidia
11284 // driver has sanitized the invalid condition and core_validation
11285 // is not introduced to the failure condition. This is not the case
11286 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011287 // uint32_t count = static_cast<uint32_t>(~0);
11288 // VkPhysicalDevice physical_device;
11289 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11290 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011293 float queue_priority = 0.0;
11294
11295 VkDeviceQueueCreateInfo queue_create_info = {};
11296 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11297 queue_create_info.queueCount = 1;
11298 queue_create_info.pQueuePriorities = &queue_priority;
11299 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11300
11301 VkPhysicalDeviceFeatures features = m_device->phy().features();
11302 VkDevice testDevice;
11303 VkDeviceCreateInfo device_create_info = {};
11304 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11305 device_create_info.queueCreateInfoCount = 1;
11306 device_create_info.pQueueCreateInfos = &queue_create_info;
11307 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011308 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011309 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11310 m_errorMonitor->VerifyFound();
11311
11312 queue_create_info.queueFamilyIndex = 1;
11313
11314 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11315 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11316 for (unsigned i = 0; i < feature_count; i++) {
11317 if (VK_FALSE == feature_array[i]) {
11318 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011320 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011321 m_errorMonitor->SetUnexpectedError(
11322 "You requested features that are unavailable on this device. You should first query feature availability by "
11323 "calling vkGetPhysicalDeviceFeatures().");
11324 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 break;
11328 }
11329 }
11330}
11331
Tobin Ehlis16edf082016-11-21 12:33:49 -070011332TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11333 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11334
11335 ASSERT_NO_FATAL_FAILURE(InitState());
11336
11337 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11338 std::vector<VkDeviceQueueCreateInfo> queue_info;
11339 queue_info.reserve(queue_props.size());
11340 std::vector<std::vector<float>> queue_priorities;
11341 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11342 VkDeviceQueueCreateInfo qi{};
11343 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11344 qi.queueFamilyIndex = i;
11345 qi.queueCount = queue_props[i].queueCount;
11346 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11347 qi.pQueuePriorities = queue_priorities[i].data();
11348 queue_info.push_back(qi);
11349 }
11350
11351 std::vector<const char *> device_extension_names;
11352
11353 VkDevice local_device;
11354 VkDeviceCreateInfo device_create_info = {};
11355 auto features = m_device->phy().features();
11356 // Intentionally disable pipeline stats
11357 features.pipelineStatisticsQuery = VK_FALSE;
11358 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11359 device_create_info.pNext = NULL;
11360 device_create_info.queueCreateInfoCount = queue_info.size();
11361 device_create_info.pQueueCreateInfos = queue_info.data();
11362 device_create_info.enabledLayerCount = 0;
11363 device_create_info.ppEnabledLayerNames = NULL;
11364 device_create_info.pEnabledFeatures = &features;
11365 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11366 ASSERT_VK_SUCCESS(err);
11367
11368 VkQueryPoolCreateInfo qpci{};
11369 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11370 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11371 qpci.queryCount = 1;
11372 VkQueryPool query_pool;
11373
11374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11375 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11376 m_errorMonitor->VerifyFound();
11377
11378 vkDestroyDevice(local_device, nullptr);
11379}
11380
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011382 TEST_DESCRIPTION(
11383 "Use an invalid queue index in a vkCmdWaitEvents call."
11384 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011385
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011386 const char *invalid_queue_index =
11387 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11388 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11389 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011394
11395 ASSERT_NO_FATAL_FAILURE(InitState());
11396
11397 VkEvent event;
11398 VkEventCreateInfo event_create_info{};
11399 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11400 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11401
Mark Mueller2ee294f2016-08-04 12:59:48 -060011402 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011404
Tony Barbour552f6c02016-12-21 14:34:07 -070011405 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011406
11407 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011408 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 -060011409 ASSERT_TRUE(image.initialized());
11410 VkImageMemoryBarrier img_barrier = {};
11411 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11412 img_barrier.pNext = NULL;
11413 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11414 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11415 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11416 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11417 img_barrier.image = image.handle();
11418 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011419
11420 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11421 // that layer validation catches the case when it is not.
11422 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011423 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11424 img_barrier.subresourceRange.baseArrayLayer = 0;
11425 img_barrier.subresourceRange.baseMipLevel = 0;
11426 img_barrier.subresourceRange.layerCount = 1;
11427 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011428 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11429 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011430 m_errorMonitor->VerifyFound();
11431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011433
11434 VkQueryPool query_pool;
11435 VkQueryPoolCreateInfo query_pool_create_info = {};
11436 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11437 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11438 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011441 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011442 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11443
11444 vkEndCommandBuffer(m_commandBuffer->handle());
11445 m_errorMonitor->VerifyFound();
11446
11447 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11448 vkDestroyEvent(m_device->device(), event, nullptr);
11449}
11450
Mark Muellerdfe37552016-07-07 14:47:42 -060011451TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011452 TEST_DESCRIPTION(
11453 "Submit a command buffer using deleted vertex buffer, "
11454 "delete a buffer twice, use an invalid offset for each "
11455 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011456
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011457 const char *deleted_buffer_in_command_buffer =
11458 "Cannot submit cmd buffer "
11459 "using deleted buffer ";
11460 const char *invalid_offset_message =
11461 "vkBindBufferMemory(): "
11462 "memoryOffset is 0x";
11463 const char *invalid_storage_buffer_offset_message =
11464 "vkBindBufferMemory(): "
11465 "storage memoryOffset "
11466 "is 0x";
11467 const char *invalid_texel_buffer_offset_message =
11468 "vkBindBufferMemory(): "
11469 "texel memoryOffset "
11470 "is 0x";
11471 const char *invalid_uniform_buffer_offset_message =
11472 "vkBindBufferMemory(): "
11473 "uniform memoryOffset "
11474 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011475
11476 ASSERT_NO_FATAL_FAILURE(InitState());
11477 ASSERT_NO_FATAL_FAILURE(InitViewport());
11478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11479
11480 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011481 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011482 pipe_ms_state_ci.pNext = NULL;
11483 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11484 pipe_ms_state_ci.sampleShadingEnable = 0;
11485 pipe_ms_state_ci.minSampleShading = 1.0;
11486 pipe_ms_state_ci.pSampleMask = nullptr;
11487
11488 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11489 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11490 VkPipelineLayout pipeline_layout;
11491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011493 ASSERT_VK_SUCCESS(err);
11494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011495 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11496 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011497 VkPipelineObj pipe(m_device);
11498 pipe.AddShader(&vs);
11499 pipe.AddShader(&fs);
11500 pipe.AddColorAttachment();
11501 pipe.SetMSAA(&pipe_ms_state_ci);
11502 pipe.SetViewport(m_viewports);
11503 pipe.SetScissor(m_scissors);
11504 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11505
Tony Barbour552f6c02016-12-21 14:34:07 -070011506 m_commandBuffer->BeginCommandBuffer();
11507 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011509
11510 {
11511 // Create and bind a vertex buffer in a reduced scope, which will cause
11512 // it to be deleted upon leaving this scope
11513 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011515 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11516 draw_verticies.AddVertexInputToPipe(pipe);
11517 }
11518
11519 Draw(1, 0, 0, 0);
11520
Tony Barbour552f6c02016-12-21 14:34:07 -070011521 m_commandBuffer->EndRenderPass();
11522 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011525 QueueCommandBuffer(false);
11526 m_errorMonitor->VerifyFound();
11527
11528 {
11529 // Create and bind a vertex buffer in a reduced scope, and delete it
11530 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011533 buffer_test.TestDoubleDestroy();
11534 }
11535 m_errorMonitor->VerifyFound();
11536
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011537 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011539 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011541 m_errorMonitor->SetUnexpectedError(
11542 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11543 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011544 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11545 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011546 m_errorMonitor->VerifyFound();
11547 }
11548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011549 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11550 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011551 // Create and bind a memory buffer with an invalid offset again,
11552 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011554 m_errorMonitor->SetUnexpectedError(
11555 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11556 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011557 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11558 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011559 m_errorMonitor->VerifyFound();
11560 }
11561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011563 // Create and bind a memory buffer with an invalid offset again, but
11564 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011566 m_errorMonitor->SetUnexpectedError(
11567 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11568 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11570 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011571 m_errorMonitor->VerifyFound();
11572 }
11573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011574 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011575 // Create and bind a memory buffer with an invalid offset again, but
11576 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011578 m_errorMonitor->SetUnexpectedError(
11579 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11580 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11582 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011583 m_errorMonitor->VerifyFound();
11584 }
11585
11586 {
11587 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011589 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11590 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011591 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11592 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011593 m_errorMonitor->VerifyFound();
11594 }
11595
11596 {
11597 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11600 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011601 }
11602 m_errorMonitor->VerifyFound();
11603
11604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11605}
11606
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011607// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11608TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011609 TEST_DESCRIPTION(
11610 "Hit all possible validation checks associated with the "
11611 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11612 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011613 // 3 in ValidateCmdBufImageLayouts
11614 // * -1 Attempt to submit cmd buf w/ deleted image
11615 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11616 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011617
11618 ASSERT_NO_FATAL_FAILURE(InitState());
11619 // Create src & dst images to use for copy operations
11620 VkImage src_image;
11621 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011622 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011623
11624 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11625 const int32_t tex_width = 32;
11626 const int32_t tex_height = 32;
11627
11628 VkImageCreateInfo image_create_info = {};
11629 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11630 image_create_info.pNext = NULL;
11631 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11632 image_create_info.format = tex_format;
11633 image_create_info.extent.width = tex_width;
11634 image_create_info.extent.height = tex_height;
11635 image_create_info.extent.depth = 1;
11636 image_create_info.mipLevels = 1;
11637 image_create_info.arrayLayers = 4;
11638 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11639 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11640 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011641 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011642 image_create_info.flags = 0;
11643
11644 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11645 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011646 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011647 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11648 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011649 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11650 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11651 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11652 ASSERT_VK_SUCCESS(err);
11653
11654 // Allocate memory
11655 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011656 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011657 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11659 mem_alloc.pNext = NULL;
11660 mem_alloc.allocationSize = 0;
11661 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011662
11663 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011664 mem_alloc.allocationSize = img_mem_reqs.size;
11665 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011666 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011667 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011668 ASSERT_VK_SUCCESS(err);
11669
11670 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011671 mem_alloc.allocationSize = img_mem_reqs.size;
11672 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011673 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011674 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011675 ASSERT_VK_SUCCESS(err);
11676
11677 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011678 mem_alloc.allocationSize = img_mem_reqs.size;
11679 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011680 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011681 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011682 ASSERT_VK_SUCCESS(err);
11683
11684 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11685 ASSERT_VK_SUCCESS(err);
11686 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11687 ASSERT_VK_SUCCESS(err);
11688 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11689 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011690
Tony Barbour552f6c02016-12-21 14:34:07 -070011691 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011692 VkImageCopy copy_region;
11693 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11694 copy_region.srcSubresource.mipLevel = 0;
11695 copy_region.srcSubresource.baseArrayLayer = 0;
11696 copy_region.srcSubresource.layerCount = 1;
11697 copy_region.srcOffset.x = 0;
11698 copy_region.srcOffset.y = 0;
11699 copy_region.srcOffset.z = 0;
11700 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11701 copy_region.dstSubresource.mipLevel = 0;
11702 copy_region.dstSubresource.baseArrayLayer = 0;
11703 copy_region.dstSubresource.layerCount = 1;
11704 copy_region.dstOffset.x = 0;
11705 copy_region.dstOffset.y = 0;
11706 copy_region.dstOffset.z = 0;
11707 copy_region.extent.width = 1;
11708 copy_region.extent.height = 1;
11709 copy_region.extent.depth = 1;
11710
11711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11712 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011713 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011714 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 -060011715 m_errorMonitor->VerifyFound();
11716 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11718 "Cannot copy from an image whose source layout is "
11719 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11720 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011721 m_errorMonitor->SetUnexpectedError(
11722 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011723 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 -060011724 m_errorMonitor->VerifyFound();
11725 // Final src error is due to bad layout type
11726 m_errorMonitor->SetDesiredFailureMsg(
11727 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11728 "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 -070011729 m_errorMonitor->SetUnexpectedError(
11730 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11731 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011732 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 -060011733 m_errorMonitor->VerifyFound();
11734 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11736 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011737 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011738 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 -060011739 m_errorMonitor->VerifyFound();
11740 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11742 "Cannot copy from an image whose dest layout is "
11743 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11744 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011745 m_errorMonitor->SetUnexpectedError(
11746 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011747 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 -060011748 m_errorMonitor->VerifyFound();
11749 m_errorMonitor->SetDesiredFailureMsg(
11750 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11751 "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 -070011752 m_errorMonitor->SetUnexpectedError(
11753 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11754 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011755 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 -060011756 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011757
Cort3b021012016-12-07 12:00:57 -080011758 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11759 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11760 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11761 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11762 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11763 transfer_dst_image_barrier[0].srcAccessMask = 0;
11764 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11765 transfer_dst_image_barrier[0].image = dst_image;
11766 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11767 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11768 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11769 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11770 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11771 transfer_dst_image_barrier[0].image = depth_image;
11772 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11773 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11774 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11775
11776 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011777 VkClearColorValue color_clear_value = {};
11778 VkImageSubresourceRange clear_range;
11779 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11780 clear_range.baseMipLevel = 0;
11781 clear_range.baseArrayLayer = 0;
11782 clear_range.layerCount = 1;
11783 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011784
Cort3b021012016-12-07 12:00:57 -080011785 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11786 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011789 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011790 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011791 // Fail due to provided layout not matching actual current layout for color clear.
11792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011793 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011794 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011795
Cort530cf382016-12-08 09:59:47 -080011796 VkClearDepthStencilValue depth_clear_value = {};
11797 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011798
11799 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11800 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011803 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011804 m_errorMonitor->VerifyFound();
11805 // Fail due to provided layout not matching actual current layout for depth clear.
11806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011807 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011808 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011809
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011810 // Now cause error due to bad image layout transition in PipelineBarrier
11811 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011812 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011813 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011814 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011815 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011816 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11817 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011818 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11820 "You cannot transition the layout of aspect 1 from "
11821 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11822 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011823 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11824 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011825 m_errorMonitor->VerifyFound();
11826
11827 // Finally some layout errors at RenderPass create time
11828 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11829 VkAttachmentReference attach = {};
11830 // perf warning for GENERAL layout w/ non-DS input attachment
11831 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11832 VkSubpassDescription subpass = {};
11833 subpass.inputAttachmentCount = 1;
11834 subpass.pInputAttachments = &attach;
11835 VkRenderPassCreateInfo rpci = {};
11836 rpci.subpassCount = 1;
11837 rpci.pSubpasses = &subpass;
11838 rpci.attachmentCount = 1;
11839 VkAttachmentDescription attach_desc = {};
11840 attach_desc.format = VK_FORMAT_UNDEFINED;
11841 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011842 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011843 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11845 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011846 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11847 m_errorMonitor->VerifyFound();
11848 // error w/ non-general layout
11849 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11850
11851 m_errorMonitor->SetDesiredFailureMsg(
11852 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11853 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11854 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11855 m_errorMonitor->VerifyFound();
11856 subpass.inputAttachmentCount = 0;
11857 subpass.colorAttachmentCount = 1;
11858 subpass.pColorAttachments = &attach;
11859 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11860 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11862 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011863 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11864 m_errorMonitor->VerifyFound();
11865 // error w/ non-color opt or GENERAL layout for color attachment
11866 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11867 m_errorMonitor->SetDesiredFailureMsg(
11868 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11869 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11870 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11871 m_errorMonitor->VerifyFound();
11872 subpass.colorAttachmentCount = 0;
11873 subpass.pDepthStencilAttachment = &attach;
11874 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11875 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11877 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011878 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11879 m_errorMonitor->VerifyFound();
11880 // error w/ non-ds opt or GENERAL layout for color attachment
11881 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11883 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11884 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011885 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11886 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011887 // For this error we need a valid renderpass so create default one
11888 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11889 attach.attachment = 0;
11890 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11891 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11892 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11893 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11894 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11895 // Can't do a CLEAR load on READ_ONLY initialLayout
11896 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11897 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11898 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11900 " with invalid first layout "
11901 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11902 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011903 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11904 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011905
Cort3b021012016-12-07 12:00:57 -080011906 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11907 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11908 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011909 vkDestroyImage(m_device->device(), src_image, NULL);
11910 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011911 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011912}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011913
Tobin Ehlise0936662016-10-11 08:10:51 -060011914TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11915 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11916 VkResult err;
11917
11918 ASSERT_NO_FATAL_FAILURE(InitState());
11919
11920 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11921 VkImageTiling tiling;
11922 VkFormatProperties format_properties;
11923 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11924 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11925 tiling = VK_IMAGE_TILING_LINEAR;
11926 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11927 tiling = VK_IMAGE_TILING_OPTIMAL;
11928 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011929 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011930 return;
11931 }
11932
11933 VkDescriptorPoolSize ds_type = {};
11934 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11935 ds_type.descriptorCount = 1;
11936
11937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11939 ds_pool_ci.maxSets = 1;
11940 ds_pool_ci.poolSizeCount = 1;
11941 ds_pool_ci.pPoolSizes = &ds_type;
11942 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11943
11944 VkDescriptorPool ds_pool;
11945 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11946 ASSERT_VK_SUCCESS(err);
11947
11948 VkDescriptorSetLayoutBinding dsl_binding = {};
11949 dsl_binding.binding = 0;
11950 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11951 dsl_binding.descriptorCount = 1;
11952 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11953 dsl_binding.pImmutableSamplers = NULL;
11954
11955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11957 ds_layout_ci.pNext = NULL;
11958 ds_layout_ci.bindingCount = 1;
11959 ds_layout_ci.pBindings = &dsl_binding;
11960
11961 VkDescriptorSetLayout ds_layout;
11962 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11963 ASSERT_VK_SUCCESS(err);
11964
11965 VkDescriptorSetAllocateInfo alloc_info = {};
11966 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11967 alloc_info.descriptorSetCount = 1;
11968 alloc_info.descriptorPool = ds_pool;
11969 alloc_info.pSetLayouts = &ds_layout;
11970 VkDescriptorSet descriptor_set;
11971 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11972 ASSERT_VK_SUCCESS(err);
11973
11974 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11975 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11976 pipeline_layout_ci.pNext = NULL;
11977 pipeline_layout_ci.setLayoutCount = 1;
11978 pipeline_layout_ci.pSetLayouts = &ds_layout;
11979 VkPipelineLayout pipeline_layout;
11980 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11981 ASSERT_VK_SUCCESS(err);
11982
11983 VkImageObj image(m_device);
11984 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11985 ASSERT_TRUE(image.initialized());
11986 VkImageView view = image.targetView(tex_format);
11987
11988 VkDescriptorImageInfo image_info = {};
11989 image_info.imageView = view;
11990 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11991
11992 VkWriteDescriptorSet descriptor_write = {};
11993 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11994 descriptor_write.dstSet = descriptor_set;
11995 descriptor_write.dstBinding = 0;
11996 descriptor_write.descriptorCount = 1;
11997 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11998 descriptor_write.pImageInfo = &image_info;
11999
12000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12001 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12002 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12003 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12004 m_errorMonitor->VerifyFound();
12005
12006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12008 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12009 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12010}
12011
Mark Mueller93b938f2016-08-18 10:27:40 -060012012TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012013 TEST_DESCRIPTION(
12014 "Use vkCmdExecuteCommands with invalid state "
12015 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012016
12017 ASSERT_NO_FATAL_FAILURE(InitState());
12018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12019
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012020 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012021 const char *simultaneous_use_message2 =
12022 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12023 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012024
12025 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012027 command_buffer_allocate_info.commandPool = m_commandPool;
12028 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12029 command_buffer_allocate_info.commandBufferCount = 1;
12030
12031 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012033 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12034 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012035 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012036 command_buffer_inheritance_info.renderPass = m_renderPass;
12037 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012038
Mark Mueller93b938f2016-08-18 10:27:40 -060012039 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012040 command_buffer_begin_info.flags =
12041 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012042 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12043
12044 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12045 vkEndCommandBuffer(secondary_command_buffer);
12046
Mark Mueller93b938f2016-08-18 10:27:40 -060012047 VkSubmitInfo submit_info = {};
12048 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12049 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012050 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012051
Mark Mueller4042b652016-09-05 22:52:21 -060012052 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012053 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12055 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012056 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012057 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012058 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12059 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012060
Dave Houltonfbf52152017-01-06 12:55:29 -070012061 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012062 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012063 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012064
Mark Mueller4042b652016-09-05 22:52:21 -060012065 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012066 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12067 m_errorMonitor->SetUnexpectedError(
12068 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12069 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012070 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12074 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012075 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012076 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12077 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012078
12079 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012080
12081 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012082}
12083
Tony Barbour626994c2017-02-08 15:29:37 -070012084TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12085 TEST_DESCRIPTION(
12086 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12087 "errors");
12088 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12089 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12090 ASSERT_NO_FATAL_FAILURE(InitState());
12091
12092 VkCommandBuffer cmd_bufs[2];
12093 VkCommandBufferAllocateInfo alloc_info;
12094 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12095 alloc_info.pNext = NULL;
12096 alloc_info.commandBufferCount = 2;
12097 alloc_info.commandPool = m_commandPool;
12098 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12099 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12100
12101 VkCommandBufferBeginInfo cb_binfo;
12102 cb_binfo.pNext = NULL;
12103 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12104 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12105 cb_binfo.flags = 0;
12106 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12107 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12108 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12109 vkEndCommandBuffer(cmd_bufs[0]);
12110 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12111
12112 VkSubmitInfo submit_info = {};
12113 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12114 submit_info.commandBufferCount = 2;
12115 submit_info.pCommandBuffers = duplicates;
12116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12117 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12118 m_errorMonitor->VerifyFound();
12119 vkQueueWaitIdle(m_device->m_queue);
12120
12121 // Set one time use and now look for one time submit
12122 duplicates[0] = duplicates[1] = cmd_bufs[1];
12123 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12124 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12125 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12126 vkEndCommandBuffer(cmd_bufs[1]);
12127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12128 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12129 m_errorMonitor->VerifyFound();
12130 vkQueueWaitIdle(m_device->m_queue);
12131}
12132
Tobin Ehlisb093da82017-01-19 12:05:27 -070012133TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012134 TEST_DESCRIPTION(
12135 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12136 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012137
12138 ASSERT_NO_FATAL_FAILURE(InitState());
12139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12140
12141 std::vector<const char *> device_extension_names;
12142 auto features = m_device->phy().features();
12143 // Make sure gs & ts are disabled
12144 features.geometryShader = false;
12145 features.tessellationShader = false;
12146 // The sacrificial device object
12147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12148
12149 VkCommandPoolCreateInfo pool_create_info{};
12150 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12151 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12152
12153 VkCommandPool command_pool;
12154 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12155
12156 VkCommandBufferAllocateInfo cmd = {};
12157 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12158 cmd.pNext = NULL;
12159 cmd.commandPool = command_pool;
12160 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12161 cmd.commandBufferCount = 1;
12162
12163 VkCommandBuffer cmd_buffer;
12164 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12165 ASSERT_VK_SUCCESS(err);
12166
12167 VkEvent event;
12168 VkEventCreateInfo evci = {};
12169 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12170 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12171 ASSERT_VK_SUCCESS(result);
12172
12173 VkCommandBufferBeginInfo cbbi = {};
12174 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12175 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12177 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12178 m_errorMonitor->VerifyFound();
12179
12180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12181 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12182 m_errorMonitor->VerifyFound();
12183
12184 vkDestroyEvent(test_device.handle(), event, NULL);
12185 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12186}
12187
Mark Mueller917f6bc2016-08-30 10:57:19 -060012188TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012189 TEST_DESCRIPTION(
12190 "Use vkCmdExecuteCommands with invalid state "
12191 "in primary and secondary command buffers. "
12192 "Delete objects that are inuse. Call VkQueueSubmit "
12193 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012194
12195 ASSERT_NO_FATAL_FAILURE(InitState());
12196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12197
Tony Barbour552f6c02016-12-21 14:34:07 -070012198 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012199
12200 VkEvent event;
12201 VkEventCreateInfo event_create_info = {};
12202 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12203 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012204 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012205
Tony Barbour552f6c02016-12-21 14:34:07 -070012206 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012207 vkDestroyEvent(m_device->device(), event, nullptr);
12208
12209 VkSubmitInfo submit_info = {};
12210 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12211 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012212 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012215 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12216 m_errorMonitor->VerifyFound();
12217
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012218 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012219 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12220
12221 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12222
Mark Mueller917f6bc2016-08-30 10:57:19 -060012223 VkSemaphoreCreateInfo semaphore_create_info = {};
12224 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12225 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012227 VkFenceCreateInfo fence_create_info = {};
12228 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12229 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012231
12232 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012233 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012234 descriptor_pool_type_count.descriptorCount = 1;
12235
12236 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12237 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12238 descriptor_pool_create_info.maxSets = 1;
12239 descriptor_pool_create_info.poolSizeCount = 1;
12240 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012242
12243 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012245
12246 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012247 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012248 descriptorset_layout_binding.descriptorCount = 1;
12249 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12250
12251 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012252 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012253 descriptorset_layout_create_info.bindingCount = 1;
12254 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12255
12256 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012257 ASSERT_VK_SUCCESS(
12258 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012259
12260 VkDescriptorSet descriptorset;
12261 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012263 descriptorset_allocate_info.descriptorSetCount = 1;
12264 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12265 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012266 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012267
Mark Mueller4042b652016-09-05 22:52:21 -060012268 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12269
12270 VkDescriptorBufferInfo buffer_info = {};
12271 buffer_info.buffer = buffer_test.GetBuffer();
12272 buffer_info.offset = 0;
12273 buffer_info.range = 1024;
12274
12275 VkWriteDescriptorSet write_descriptor_set = {};
12276 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12277 write_descriptor_set.dstSet = descriptorset;
12278 write_descriptor_set.descriptorCount = 1;
12279 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12280 write_descriptor_set.pBufferInfo = &buffer_info;
12281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012284 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12285 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012286
12287 VkPipelineObj pipe(m_device);
12288 pipe.AddColorAttachment();
12289 pipe.AddShader(&vs);
12290 pipe.AddShader(&fs);
12291
12292 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012293 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012294 pipeline_layout_create_info.setLayoutCount = 1;
12295 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12296
12297 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012298 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012299
12300 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12301
Tony Barbour552f6c02016-12-21 14:34:07 -070012302 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012303 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12306 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12307 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012308
Tony Barbour552f6c02016-12-21 14:34:07 -070012309 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012310
Mark Mueller917f6bc2016-08-30 10:57:19 -060012311 submit_info.signalSemaphoreCount = 1;
12312 submit_info.pSignalSemaphores = &semaphore;
12313 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012314 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012315
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012317 vkDestroyEvent(m_device->device(), event, nullptr);
12318 m_errorMonitor->VerifyFound();
12319
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012321 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12322 m_errorMonitor->VerifyFound();
12323
Jeremy Hayes08369882017-02-02 10:31:06 -070012324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012325 vkDestroyFence(m_device->device(), fence, nullptr);
12326 m_errorMonitor->VerifyFound();
12327
Tobin Ehlis122207b2016-09-01 08:50:06 -070012328 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012329 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12330 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012331 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012332 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12333 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012334 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012335 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12336 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012337 vkDestroyEvent(m_device->device(), event, nullptr);
12338 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012339 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12341}
12342
Tobin Ehlis2adda372016-09-01 08:51:06 -070012343TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12344 TEST_DESCRIPTION("Delete in-use query pool.");
12345
12346 ASSERT_NO_FATAL_FAILURE(InitState());
12347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12348
12349 VkQueryPool query_pool;
12350 VkQueryPoolCreateInfo query_pool_ci{};
12351 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12352 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12353 query_pool_ci.queryCount = 1;
12354 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012355 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012356 // Reset query pool to create binding with cmd buffer
12357 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12358
Tony Barbour552f6c02016-12-21 14:34:07 -070012359 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012360
12361 VkSubmitInfo submit_info = {};
12362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12363 submit_info.commandBufferCount = 1;
12364 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12365 // Submit cmd buffer and then destroy query pool while in-flight
12366 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12367
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012369 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12370 m_errorMonitor->VerifyFound();
12371
12372 vkQueueWaitIdle(m_device->m_queue);
12373 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012374 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12375 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012376 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12377}
12378
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012379TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12380 TEST_DESCRIPTION("Delete in-use pipeline.");
12381
12382 ASSERT_NO_FATAL_FAILURE(InitState());
12383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12384
12385 // Empty pipeline layout used for binding PSO
12386 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12387 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12388 pipeline_layout_ci.setLayoutCount = 0;
12389 pipeline_layout_ci.pSetLayouts = NULL;
12390
12391 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012392 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012393 ASSERT_VK_SUCCESS(err);
12394
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012396 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012397 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399 // Store pipeline handle so we can actually delete it before test finishes
12400 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012401 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012402 VkPipelineObj pipe(m_device);
12403 pipe.AddShader(&vs);
12404 pipe.AddShader(&fs);
12405 pipe.AddColorAttachment();
12406 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12407 delete_this_pipeline = pipe.handle();
12408
Tony Barbour552f6c02016-12-21 14:34:07 -070012409 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012410 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012411 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012412
Tony Barbour552f6c02016-12-21 14:34:07 -070012413 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012414
12415 VkSubmitInfo submit_info = {};
12416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12417 submit_info.commandBufferCount = 1;
12418 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12419 // Submit cmd buffer and then pipeline destroyed while in-flight
12420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012421 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012422 m_errorMonitor->VerifyFound();
12423 // Make sure queue finished and then actually delete pipeline
12424 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012425 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12426 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012427 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12428 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12429}
12430
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012431TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12432 TEST_DESCRIPTION("Delete in-use imageView.");
12433
12434 ASSERT_NO_FATAL_FAILURE(InitState());
12435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12436
12437 VkDescriptorPoolSize ds_type_count;
12438 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12439 ds_type_count.descriptorCount = 1;
12440
12441 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12442 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12443 ds_pool_ci.maxSets = 1;
12444 ds_pool_ci.poolSizeCount = 1;
12445 ds_pool_ci.pPoolSizes = &ds_type_count;
12446
12447 VkDescriptorPool ds_pool;
12448 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12449 ASSERT_VK_SUCCESS(err);
12450
12451 VkSamplerCreateInfo sampler_ci = {};
12452 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12453 sampler_ci.pNext = NULL;
12454 sampler_ci.magFilter = VK_FILTER_NEAREST;
12455 sampler_ci.minFilter = VK_FILTER_NEAREST;
12456 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12457 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12458 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12459 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12460 sampler_ci.mipLodBias = 1.0;
12461 sampler_ci.anisotropyEnable = VK_FALSE;
12462 sampler_ci.maxAnisotropy = 1;
12463 sampler_ci.compareEnable = VK_FALSE;
12464 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12465 sampler_ci.minLod = 1.0;
12466 sampler_ci.maxLod = 1.0;
12467 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12468 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12469 VkSampler sampler;
12470
12471 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12472 ASSERT_VK_SUCCESS(err);
12473
12474 VkDescriptorSetLayoutBinding layout_binding;
12475 layout_binding.binding = 0;
12476 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12477 layout_binding.descriptorCount = 1;
12478 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12479 layout_binding.pImmutableSamplers = NULL;
12480
12481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12483 ds_layout_ci.bindingCount = 1;
12484 ds_layout_ci.pBindings = &layout_binding;
12485 VkDescriptorSetLayout ds_layout;
12486 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12487 ASSERT_VK_SUCCESS(err);
12488
12489 VkDescriptorSetAllocateInfo alloc_info = {};
12490 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12491 alloc_info.descriptorSetCount = 1;
12492 alloc_info.descriptorPool = ds_pool;
12493 alloc_info.pSetLayouts = &ds_layout;
12494 VkDescriptorSet descriptor_set;
12495 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12496 ASSERT_VK_SUCCESS(err);
12497
12498 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12499 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12500 pipeline_layout_ci.pNext = NULL;
12501 pipeline_layout_ci.setLayoutCount = 1;
12502 pipeline_layout_ci.pSetLayouts = &ds_layout;
12503
12504 VkPipelineLayout pipeline_layout;
12505 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12506 ASSERT_VK_SUCCESS(err);
12507
12508 VkImageObj image(m_device);
12509 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12510 ASSERT_TRUE(image.initialized());
12511
12512 VkImageView view;
12513 VkImageViewCreateInfo ivci = {};
12514 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12515 ivci.image = image.handle();
12516 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12517 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12518 ivci.subresourceRange.layerCount = 1;
12519 ivci.subresourceRange.baseMipLevel = 0;
12520 ivci.subresourceRange.levelCount = 1;
12521 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12522
12523 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12524 ASSERT_VK_SUCCESS(err);
12525
12526 VkDescriptorImageInfo image_info{};
12527 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12528 image_info.imageView = view;
12529 image_info.sampler = sampler;
12530
12531 VkWriteDescriptorSet descriptor_write = {};
12532 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12533 descriptor_write.dstSet = descriptor_set;
12534 descriptor_write.dstBinding = 0;
12535 descriptor_write.descriptorCount = 1;
12536 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12537 descriptor_write.pImageInfo = &image_info;
12538
12539 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12540
12541 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012542 char const *vsSource =
12543 "#version 450\n"
12544 "\n"
12545 "out gl_PerVertex { \n"
12546 " vec4 gl_Position;\n"
12547 "};\n"
12548 "void main(){\n"
12549 " gl_Position = vec4(1);\n"
12550 "}\n";
12551 char const *fsSource =
12552 "#version 450\n"
12553 "\n"
12554 "layout(set=0, binding=0) uniform sampler2D s;\n"
12555 "layout(location=0) out vec4 x;\n"
12556 "void main(){\n"
12557 " x = texture(s, vec2(1));\n"
12558 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012559 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12560 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12561 VkPipelineObj pipe(m_device);
12562 pipe.AddShader(&vs);
12563 pipe.AddShader(&fs);
12564 pipe.AddColorAttachment();
12565 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12566
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012568
Tony Barbour552f6c02016-12-21 14:34:07 -070012569 m_commandBuffer->BeginCommandBuffer();
12570 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012571 // Bind pipeline to cmd buffer
12572 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12573 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12574 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012575
12576 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12577 VkRect2D scissor = {{0, 0}, {16, 16}};
12578 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12579 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12580
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012581 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012582 m_commandBuffer->EndRenderPass();
12583 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012584 // Submit cmd buffer then destroy sampler
12585 VkSubmitInfo submit_info = {};
12586 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12587 submit_info.commandBufferCount = 1;
12588 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12589 // Submit cmd buffer and then destroy imageView while in-flight
12590 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12591
12592 vkDestroyImageView(m_device->device(), view, nullptr);
12593 m_errorMonitor->VerifyFound();
12594 vkQueueWaitIdle(m_device->m_queue);
12595 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012596 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12597 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012598 vkDestroyImageView(m_device->device(), view, NULL);
12599 vkDestroySampler(m_device->device(), sampler, nullptr);
12600 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12603}
12604
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012605TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12606 TEST_DESCRIPTION("Delete in-use bufferView.");
12607
12608 ASSERT_NO_FATAL_FAILURE(InitState());
12609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12610
12611 VkDescriptorPoolSize ds_type_count;
12612 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12613 ds_type_count.descriptorCount = 1;
12614
12615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12617 ds_pool_ci.maxSets = 1;
12618 ds_pool_ci.poolSizeCount = 1;
12619 ds_pool_ci.pPoolSizes = &ds_type_count;
12620
12621 VkDescriptorPool ds_pool;
12622 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12623 ASSERT_VK_SUCCESS(err);
12624
12625 VkDescriptorSetLayoutBinding layout_binding;
12626 layout_binding.binding = 0;
12627 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12628 layout_binding.descriptorCount = 1;
12629 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12630 layout_binding.pImmutableSamplers = NULL;
12631
12632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12634 ds_layout_ci.bindingCount = 1;
12635 ds_layout_ci.pBindings = &layout_binding;
12636 VkDescriptorSetLayout ds_layout;
12637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12638 ASSERT_VK_SUCCESS(err);
12639
12640 VkDescriptorSetAllocateInfo alloc_info = {};
12641 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12642 alloc_info.descriptorSetCount = 1;
12643 alloc_info.descriptorPool = ds_pool;
12644 alloc_info.pSetLayouts = &ds_layout;
12645 VkDescriptorSet descriptor_set;
12646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12647 ASSERT_VK_SUCCESS(err);
12648
12649 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12650 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12651 pipeline_layout_ci.pNext = NULL;
12652 pipeline_layout_ci.setLayoutCount = 1;
12653 pipeline_layout_ci.pSetLayouts = &ds_layout;
12654
12655 VkPipelineLayout pipeline_layout;
12656 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12657 ASSERT_VK_SUCCESS(err);
12658
12659 VkBuffer buffer;
12660 uint32_t queue_family_index = 0;
12661 VkBufferCreateInfo buffer_create_info = {};
12662 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12663 buffer_create_info.size = 1024;
12664 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12665 buffer_create_info.queueFamilyIndexCount = 1;
12666 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12667
12668 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12669 ASSERT_VK_SUCCESS(err);
12670
12671 VkMemoryRequirements memory_reqs;
12672 VkDeviceMemory buffer_memory;
12673
12674 VkMemoryAllocateInfo memory_info = {};
12675 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12676 memory_info.allocationSize = 0;
12677 memory_info.memoryTypeIndex = 0;
12678
12679 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12680 memory_info.allocationSize = memory_reqs.size;
12681 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12682 ASSERT_TRUE(pass);
12683
12684 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12685 ASSERT_VK_SUCCESS(err);
12686 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12687 ASSERT_VK_SUCCESS(err);
12688
12689 VkBufferView view;
12690 VkBufferViewCreateInfo bvci = {};
12691 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12692 bvci.buffer = buffer;
12693 bvci.format = VK_FORMAT_R8_UNORM;
12694 bvci.range = VK_WHOLE_SIZE;
12695
12696 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12697 ASSERT_VK_SUCCESS(err);
12698
12699 VkWriteDescriptorSet descriptor_write = {};
12700 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12701 descriptor_write.dstSet = descriptor_set;
12702 descriptor_write.dstBinding = 0;
12703 descriptor_write.descriptorCount = 1;
12704 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12705 descriptor_write.pTexelBufferView = &view;
12706
12707 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12708
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012709 char const *vsSource =
12710 "#version 450\n"
12711 "\n"
12712 "out gl_PerVertex { \n"
12713 " vec4 gl_Position;\n"
12714 "};\n"
12715 "void main(){\n"
12716 " gl_Position = vec4(1);\n"
12717 "}\n";
12718 char const *fsSource =
12719 "#version 450\n"
12720 "\n"
12721 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12722 "layout(location=0) out vec4 x;\n"
12723 "void main(){\n"
12724 " x = imageLoad(s, 0);\n"
12725 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12728 VkPipelineObj pipe(m_device);
12729 pipe.AddShader(&vs);
12730 pipe.AddShader(&fs);
12731 pipe.AddColorAttachment();
12732 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12733
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012735
Tony Barbour552f6c02016-12-21 14:34:07 -070012736 m_commandBuffer->BeginCommandBuffer();
12737 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012738 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12739 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12740 VkRect2D scissor = {{0, 0}, {16, 16}};
12741 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12742 // Bind pipeline to cmd buffer
12743 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12745 &descriptor_set, 0, nullptr);
12746 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012747 m_commandBuffer->EndRenderPass();
12748 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012749
12750 VkSubmitInfo submit_info = {};
12751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12752 submit_info.commandBufferCount = 1;
12753 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12754 // Submit cmd buffer and then destroy bufferView while in-flight
12755 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12756
12757 vkDestroyBufferView(m_device->device(), view, nullptr);
12758 m_errorMonitor->VerifyFound();
12759 vkQueueWaitIdle(m_device->m_queue);
12760 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012761 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12762 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012763 vkDestroyBufferView(m_device->device(), view, NULL);
12764 vkDestroyBuffer(m_device->device(), buffer, NULL);
12765 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12769}
12770
Tobin Ehlis209532e2016-09-07 13:52:18 -060012771TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12772 TEST_DESCRIPTION("Delete in-use sampler.");
12773
12774 ASSERT_NO_FATAL_FAILURE(InitState());
12775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12776
12777 VkDescriptorPoolSize ds_type_count;
12778 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12779 ds_type_count.descriptorCount = 1;
12780
12781 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12782 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12783 ds_pool_ci.maxSets = 1;
12784 ds_pool_ci.poolSizeCount = 1;
12785 ds_pool_ci.pPoolSizes = &ds_type_count;
12786
12787 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012789 ASSERT_VK_SUCCESS(err);
12790
12791 VkSamplerCreateInfo sampler_ci = {};
12792 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12793 sampler_ci.pNext = NULL;
12794 sampler_ci.magFilter = VK_FILTER_NEAREST;
12795 sampler_ci.minFilter = VK_FILTER_NEAREST;
12796 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12797 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12798 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12799 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12800 sampler_ci.mipLodBias = 1.0;
12801 sampler_ci.anisotropyEnable = VK_FALSE;
12802 sampler_ci.maxAnisotropy = 1;
12803 sampler_ci.compareEnable = VK_FALSE;
12804 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12805 sampler_ci.minLod = 1.0;
12806 sampler_ci.maxLod = 1.0;
12807 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12808 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12809 VkSampler sampler;
12810
12811 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12812 ASSERT_VK_SUCCESS(err);
12813
12814 VkDescriptorSetLayoutBinding layout_binding;
12815 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012816 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012817 layout_binding.descriptorCount = 1;
12818 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12819 layout_binding.pImmutableSamplers = NULL;
12820
12821 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12822 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12823 ds_layout_ci.bindingCount = 1;
12824 ds_layout_ci.pBindings = &layout_binding;
12825 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012827 ASSERT_VK_SUCCESS(err);
12828
12829 VkDescriptorSetAllocateInfo alloc_info = {};
12830 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12831 alloc_info.descriptorSetCount = 1;
12832 alloc_info.descriptorPool = ds_pool;
12833 alloc_info.pSetLayouts = &ds_layout;
12834 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012835 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012836 ASSERT_VK_SUCCESS(err);
12837
12838 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12839 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12840 pipeline_layout_ci.pNext = NULL;
12841 pipeline_layout_ci.setLayoutCount = 1;
12842 pipeline_layout_ci.pSetLayouts = &ds_layout;
12843
12844 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012846 ASSERT_VK_SUCCESS(err);
12847
12848 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012849 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 -060012850 ASSERT_TRUE(image.initialized());
12851
12852 VkImageView view;
12853 VkImageViewCreateInfo ivci = {};
12854 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12855 ivci.image = image.handle();
12856 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12857 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12858 ivci.subresourceRange.layerCount = 1;
12859 ivci.subresourceRange.baseMipLevel = 0;
12860 ivci.subresourceRange.levelCount = 1;
12861 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12862
12863 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12864 ASSERT_VK_SUCCESS(err);
12865
12866 VkDescriptorImageInfo image_info{};
12867 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12868 image_info.imageView = view;
12869 image_info.sampler = sampler;
12870
12871 VkWriteDescriptorSet descriptor_write = {};
12872 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12873 descriptor_write.dstSet = descriptor_set;
12874 descriptor_write.dstBinding = 0;
12875 descriptor_write.descriptorCount = 1;
12876 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12877 descriptor_write.pImageInfo = &image_info;
12878
12879 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12880
12881 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012882 char const *vsSource =
12883 "#version 450\n"
12884 "\n"
12885 "out gl_PerVertex { \n"
12886 " vec4 gl_Position;\n"
12887 "};\n"
12888 "void main(){\n"
12889 " gl_Position = vec4(1);\n"
12890 "}\n";
12891 char const *fsSource =
12892 "#version 450\n"
12893 "\n"
12894 "layout(set=0, binding=0) uniform sampler2D s;\n"
12895 "layout(location=0) out vec4 x;\n"
12896 "void main(){\n"
12897 " x = texture(s, vec2(1));\n"
12898 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12901 VkPipelineObj pipe(m_device);
12902 pipe.AddShader(&vs);
12903 pipe.AddShader(&fs);
12904 pipe.AddColorAttachment();
12905 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12906
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012908
Tony Barbour552f6c02016-12-21 14:34:07 -070012909 m_commandBuffer->BeginCommandBuffer();
12910 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012911 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012912 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12913 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12914 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012915
12916 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12917 VkRect2D scissor = {{0, 0}, {16, 16}};
12918 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12919 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12920
Tobin Ehlis209532e2016-09-07 13:52:18 -060012921 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012922 m_commandBuffer->EndRenderPass();
12923 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012924 // Submit cmd buffer then destroy sampler
12925 VkSubmitInfo submit_info = {};
12926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12927 submit_info.commandBufferCount = 1;
12928 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12929 // Submit cmd buffer and then destroy sampler while in-flight
12930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12931
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012932 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012933 m_errorMonitor->VerifyFound();
12934 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012935
Tobin Ehlis209532e2016-09-07 13:52:18 -060012936 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012937 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12938 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012939 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012940 vkDestroyImageView(m_device->device(), view, NULL);
12941 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12942 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12943 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12944}
12945
Mark Mueller1cd9f412016-08-25 13:23:52 -060012946TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012947 TEST_DESCRIPTION(
12948 "Call VkQueueSubmit with a semaphore that is already "
12949 "signaled but not waited on by the queue. Wait on a "
12950 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012951
12952 ASSERT_NO_FATAL_FAILURE(InitState());
12953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012955 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 -070012956 const char *invalid_fence_wait_message =
12957 " which has not been submitted on a Queue or during "
12958 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012959
Tony Barbour552f6c02016-12-21 14:34:07 -070012960 m_commandBuffer->BeginCommandBuffer();
12961 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012962
12963 VkSemaphoreCreateInfo semaphore_create_info = {};
12964 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12965 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012966 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012967 VkSubmitInfo submit_info = {};
12968 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12969 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012970 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012971 submit_info.signalSemaphoreCount = 1;
12972 submit_info.pSignalSemaphores = &semaphore;
12973 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012974 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012975 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012976 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012977 m_commandBuffer->BeginCommandBuffer();
12978 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012980 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12981 m_errorMonitor->VerifyFound();
12982
Mark Mueller1cd9f412016-08-25 13:23:52 -060012983 VkFenceCreateInfo fence_create_info = {};
12984 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12985 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012986 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012989 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12990 m_errorMonitor->VerifyFound();
12991
Mark Mueller4042b652016-09-05 22:52:21 -060012992 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012993 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012994 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12995}
12996
Tobin Ehlis4af23302016-07-19 10:50:30 -060012997TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012998 TEST_DESCRIPTION(
12999 "Bind a secondary command buffer with with a framebuffer "
13000 "that does not match the framebuffer for the active "
13001 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013002 ASSERT_NO_FATAL_FAILURE(InitState());
13003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13004
13005 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 VkAttachmentDescription attachment = {0,
13007 VK_FORMAT_B8G8R8A8_UNORM,
13008 VK_SAMPLE_COUNT_1_BIT,
13009 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13010 VK_ATTACHMENT_STORE_OP_STORE,
13011 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13012 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13013 VK_IMAGE_LAYOUT_UNDEFINED,
13014 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013018 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013020 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013021
13022 VkRenderPass rp;
13023 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13024 ASSERT_VK_SUCCESS(err);
13025
13026 // A compatible framebuffer.
13027 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013028 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 -060013029 ASSERT_TRUE(image.initialized());
13030
13031 VkImageViewCreateInfo ivci = {
13032 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13033 nullptr,
13034 0,
13035 image.handle(),
13036 VK_IMAGE_VIEW_TYPE_2D,
13037 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13039 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013040 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13041 };
13042 VkImageView view;
13043 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13044 ASSERT_VK_SUCCESS(err);
13045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013046 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013047 VkFramebuffer fb;
13048 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13049 ASSERT_VK_SUCCESS(err);
13050
13051 VkCommandBufferAllocateInfo cbai = {};
13052 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13053 cbai.commandPool = m_commandPool;
13054 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13055 cbai.commandBufferCount = 1;
13056
13057 VkCommandBuffer sec_cb;
13058 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13059 ASSERT_VK_SUCCESS(err);
13060 VkCommandBufferBeginInfo cbbi = {};
13061 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013062 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013063 cbii.renderPass = renderPass();
13064 cbii.framebuffer = fb;
13065 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13066 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 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 -060013068 cbbi.pInheritanceInfo = &cbii;
13069 vkBeginCommandBuffer(sec_cb, &cbbi);
13070 vkEndCommandBuffer(sec_cb);
13071
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013072 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013073 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13074 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013077 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013078 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13079 m_errorMonitor->VerifyFound();
13080 // Cleanup
13081 vkDestroyImageView(m_device->device(), view, NULL);
13082 vkDestroyRenderPass(m_device->device(), rp, NULL);
13083 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13084}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013085
13086TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013087 TEST_DESCRIPTION(
13088 "If logicOp is available on the device, set it to an "
13089 "invalid value. If logicOp is not available, attempt to "
13090 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013091 ASSERT_NO_FATAL_FAILURE(InitState());
13092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13093
13094 auto features = m_device->phy().features();
13095 // Set the expected error depending on whether or not logicOp available
13096 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13098 "If logic operations feature not "
13099 "enabled, logicOpEnable must be "
13100 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013101 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013103 }
13104 // Create a pipeline using logicOp
13105 VkResult err;
13106
13107 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13108 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13109
13110 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013112 ASSERT_VK_SUCCESS(err);
13113
13114 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13115 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13116 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013117 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013118 vp_state_ci.pViewports = &vp;
13119 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013120 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013122
13123 VkPipelineShaderStageCreateInfo shaderStages[2];
13124 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013126 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13127 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013128 shaderStages[0] = vs.GetStageCreateInfo();
13129 shaderStages[1] = fs.GetStageCreateInfo();
13130
13131 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13132 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13133
13134 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13135 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13136 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13137
13138 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13139 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013140 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013141
13142 VkPipelineColorBlendAttachmentState att = {};
13143 att.blendEnable = VK_FALSE;
13144 att.colorWriteMask = 0xf;
13145
13146 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13147 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13148 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13149 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013150 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013151 cb_ci.attachmentCount = 1;
13152 cb_ci.pAttachments = &att;
13153
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013154 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13155 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13156 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13157
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013158 VkGraphicsPipelineCreateInfo gp_ci = {};
13159 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13160 gp_ci.stageCount = 2;
13161 gp_ci.pStages = shaderStages;
13162 gp_ci.pVertexInputState = &vi_ci;
13163 gp_ci.pInputAssemblyState = &ia_ci;
13164 gp_ci.pViewportState = &vp_state_ci;
13165 gp_ci.pRasterizationState = &rs_ci;
13166 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013167 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013168 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13169 gp_ci.layout = pipeline_layout;
13170 gp_ci.renderPass = renderPass();
13171
13172 VkPipelineCacheCreateInfo pc_ci = {};
13173 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13174
13175 VkPipeline pipeline;
13176 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013178 ASSERT_VK_SUCCESS(err);
13179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013180 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013181 m_errorMonitor->VerifyFound();
13182 if (VK_SUCCESS == err) {
13183 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13184 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013185 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13186 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13187}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013188
Mike Stroyanaccf7692015-05-12 16:00:45 -060013189#if GTEST_IS_THREADSAFE
13190struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013191 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013192 VkEvent event;
13193 bool bailout;
13194};
13195
Karl Schultz6addd812016-02-02 17:17:23 -070013196extern "C" void *AddToCommandBuffer(void *arg) {
13197 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013198
Mike Stroyana6d14942016-07-13 15:10:05 -060013199 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013200 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013201 if (data->bailout) {
13202 break;
13203 }
13204 }
13205 return NULL;
13206}
13207
Karl Schultz6addd812016-02-02 17:17:23 -070013208TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013209 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013212
Mike Stroyanaccf7692015-05-12 16:00:45 -060013213 ASSERT_NO_FATAL_FAILURE(InitState());
13214 ASSERT_NO_FATAL_FAILURE(InitViewport());
13215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13216
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013217 // Calls AllocateCommandBuffers
13218 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013219
13220 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013221 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222
13223 VkEventCreateInfo event_info;
13224 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013225 VkResult err;
13226
13227 memset(&event_info, 0, sizeof(event_info));
13228 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13229
Chia-I Wuf7458c52015-10-26 21:10:41 +080013230 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013231 ASSERT_VK_SUCCESS(err);
13232
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233 err = vkResetEvent(device(), event);
13234 ASSERT_VK_SUCCESS(err);
13235
13236 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013237 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013238 data.event = event;
13239 data.bailout = false;
13240 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013241
13242 // First do some correct operations using multiple threads.
13243 // Add many entries to command buffer from another thread.
13244 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13245 // Make non-conflicting calls from this thread at the same time.
13246 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013247 uint32_t count;
13248 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013249 }
13250 test_platform_thread_join(thread, NULL);
13251
13252 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013253 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013254 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013255 // Add many entries to command buffer from this thread at the same time.
13256 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013257
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013258 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013259 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013260
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013261 m_errorMonitor->SetBailout(NULL);
13262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013263 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013264
Chia-I Wuf7458c52015-10-26 21:10:41 +080013265 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013266}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013267#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013268
Karl Schultz6addd812016-02-02 17:17:23 -070013269TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013270 TEST_DESCRIPTION(
13271 "Test that an error is produced for a spirv module "
13272 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013275
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 ASSERT_NO_FATAL_FAILURE(InitState());
13277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13278
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013279 VkShaderModule module;
13280 VkShaderModuleCreateInfo moduleCreateInfo;
13281 struct icd_spv_header spv;
13282
13283 spv.magic = ICD_SPV_MAGIC;
13284 spv.version = ICD_SPV_VERSION;
13285 spv.gen_magic = 0;
13286
13287 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13288 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013289 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290 moduleCreateInfo.codeSize = 4;
13291 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013292 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013294 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295}
13296
Karl Schultz6addd812016-02-02 17:17:23 -070013297TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013298 TEST_DESCRIPTION(
13299 "Test that an error is produced for a spirv module "
13300 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013303
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013304 ASSERT_NO_FATAL_FAILURE(InitState());
13305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13306
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013307 VkShaderModule module;
13308 VkShaderModuleCreateInfo moduleCreateInfo;
13309 struct icd_spv_header spv;
13310
13311 spv.magic = ~ICD_SPV_MAGIC;
13312 spv.version = ICD_SPV_VERSION;
13313 spv.gen_magic = 0;
13314
13315 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13316 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013317 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13319 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013320 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013322 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013323}
13324
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013325#if 0
13326// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013327TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013329 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013330
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013331 ASSERT_NO_FATAL_FAILURE(InitState());
13332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13333
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013334 VkShaderModule module;
13335 VkShaderModuleCreateInfo moduleCreateInfo;
13336 struct icd_spv_header spv;
13337
13338 spv.magic = ICD_SPV_MAGIC;
13339 spv.version = ~ICD_SPV_VERSION;
13340 spv.gen_magic = 0;
13341
13342 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13343 moduleCreateInfo.pNext = NULL;
13344
Karl Schultz6addd812016-02-02 17:17:23 -070013345 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013346 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13347 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013348 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013349
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013350 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013351}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013352#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013353
Karl Schultz6addd812016-02-02 17:17:23 -070013354TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013355 TEST_DESCRIPTION(
13356 "Test that a warning is produced for a vertex output that "
13357 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013359
Chris Forbes9f7ff632015-05-25 11:13:08 +120013360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013363 char const *vsSource =
13364 "#version 450\n"
13365 "\n"
13366 "layout(location=0) out float x;\n"
13367 "out gl_PerVertex {\n"
13368 " vec4 gl_Position;\n"
13369 "};\n"
13370 "void main(){\n"
13371 " gl_Position = vec4(1);\n"
13372 " x = 0;\n"
13373 "}\n";
13374 char const *fsSource =
13375 "#version 450\n"
13376 "\n"
13377 "layout(location=0) out vec4 color;\n"
13378 "void main(){\n"
13379 " color = vec4(1);\n"
13380 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013381
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013384
13385 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013386 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013387 pipe.AddShader(&vs);
13388 pipe.AddShader(&fs);
13389
Chris Forbes9f7ff632015-05-25 11:13:08 +120013390 VkDescriptorSetObj descriptorSet(m_device);
13391 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013392 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013393
Tony Barbour5781e8f2015-08-04 16:23:11 -060013394 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013396 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013397}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013398
Mark Mueller098c9cb2016-09-08 09:01:57 -060013399TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13400 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13401
13402 ASSERT_NO_FATAL_FAILURE(InitState());
13403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13404
13405 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013406 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013407
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013408 char const *vsSource =
13409 "#version 450\n"
13410 "\n"
13411 "out gl_PerVertex {\n"
13412 " vec4 gl_Position;\n"
13413 "};\n"
13414 "void main(){\n"
13415 " gl_Position = vec4(1);\n"
13416 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013417
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013418 char const *fsSource =
13419 "#version 450\n"
13420 "\n"
13421 "layout (constant_id = 0) const float r = 0.0f;\n"
13422 "layout(location = 0) out vec4 uFragColor;\n"
13423 "void main(){\n"
13424 " uFragColor = vec4(r,1,0,1);\n"
13425 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013426
13427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13428 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13429
13430 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13431 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13432
13433 VkPipelineLayout pipeline_layout;
13434 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13435
13436 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13437 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13438 vp_state_create_info.viewportCount = 1;
13439 VkViewport viewport = {};
13440 vp_state_create_info.pViewports = &viewport;
13441 vp_state_create_info.scissorCount = 1;
13442 VkRect2D scissors = {};
13443 vp_state_create_info.pScissors = &scissors;
13444
13445 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13446
13447 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13448 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13449 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13450 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13451
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013452 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013453
13454 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13455 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13456
13457 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13458 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13459 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13460
13461 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13462 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13463 rasterization_state_create_info.pNext = nullptr;
13464 rasterization_state_create_info.lineWidth = 1.0f;
13465 rasterization_state_create_info.rasterizerDiscardEnable = true;
13466
13467 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13468 color_blend_attachment_state.blendEnable = VK_FALSE;
13469 color_blend_attachment_state.colorWriteMask = 0xf;
13470
13471 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13472 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13473 color_blend_state_create_info.attachmentCount = 1;
13474 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13475
13476 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13477 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13478 graphicspipe_create_info.stageCount = 2;
13479 graphicspipe_create_info.pStages = shader_stage_create_info;
13480 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13481 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13482 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13483 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13484 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13485 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13486 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13487 graphicspipe_create_info.layout = pipeline_layout;
13488 graphicspipe_create_info.renderPass = renderPass();
13489
13490 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13491 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13492
13493 VkPipelineCache pipelineCache;
13494 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13495
13496 // This structure maps constant ids to data locations.
13497 const VkSpecializationMapEntry entry =
13498 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013499 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013500
13501 uint32_t data = 1;
13502
13503 // Set up the info describing spec map and data
13504 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013505 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013506 };
13507 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13508
13509 VkPipeline pipeline;
13510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13511 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13512 m_errorMonitor->VerifyFound();
13513
13514 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13515 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13516}
13517
13518TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13519 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13520
13521 ASSERT_NO_FATAL_FAILURE(InitState());
13522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13523
13524 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13525
13526 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13527 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13528 descriptor_pool_type_count[0].descriptorCount = 1;
13529 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13530 descriptor_pool_type_count[1].descriptorCount = 1;
13531
13532 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13533 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13534 descriptor_pool_create_info.maxSets = 1;
13535 descriptor_pool_create_info.poolSizeCount = 2;
13536 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13537 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13538
13539 VkDescriptorPool descriptorset_pool;
13540 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13541
13542 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13543 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13544 descriptorset_layout_binding.descriptorCount = 1;
13545 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13546
13547 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13548 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13549 descriptorset_layout_create_info.bindingCount = 1;
13550 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13551
13552 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013553 ASSERT_VK_SUCCESS(
13554 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013555
13556 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13557 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13558 descriptorset_allocate_info.descriptorSetCount = 1;
13559 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13560 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13561 VkDescriptorSet descriptorset;
13562 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13563
13564 // Challenge core_validation with a non uniform buffer type.
13565 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13566
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013567 char const *vsSource =
13568 "#version 450\n"
13569 "\n"
13570 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13571 " mat4 mvp;\n"
13572 "} ubuf;\n"
13573 "out gl_PerVertex {\n"
13574 " vec4 gl_Position;\n"
13575 "};\n"
13576 "void main(){\n"
13577 " gl_Position = ubuf.mvp * vec4(1);\n"
13578 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013579
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013580 char const *fsSource =
13581 "#version 450\n"
13582 "\n"
13583 "layout(location = 0) out vec4 uFragColor;\n"
13584 "void main(){\n"
13585 " uFragColor = vec4(0,1,0,1);\n"
13586 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013587
13588 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13589 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13590
13591 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13592 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13593 pipeline_layout_create_info.setLayoutCount = 1;
13594 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13595
13596 VkPipelineLayout pipeline_layout;
13597 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13598
13599 VkPipelineObj pipe(m_device);
13600 pipe.AddColorAttachment();
13601 pipe.AddShader(&vs);
13602 pipe.AddShader(&fs);
13603
13604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13605 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13606 m_errorMonitor->VerifyFound();
13607
13608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13609 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13610 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13611}
13612
13613TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13614 TEST_DESCRIPTION(
13615 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13616
13617 ASSERT_NO_FATAL_FAILURE(InitState());
13618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13619
13620 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13621
13622 VkDescriptorPoolSize descriptor_pool_type_count = {};
13623 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13624 descriptor_pool_type_count.descriptorCount = 1;
13625
13626 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13627 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13628 descriptor_pool_create_info.maxSets = 1;
13629 descriptor_pool_create_info.poolSizeCount = 1;
13630 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13631 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13632
13633 VkDescriptorPool descriptorset_pool;
13634 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13635
13636 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13637 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13638 descriptorset_layout_binding.descriptorCount = 1;
13639 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13640 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13641
13642 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13643 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13644 descriptorset_layout_create_info.bindingCount = 1;
13645 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13646
13647 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013648 ASSERT_VK_SUCCESS(
13649 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013650
13651 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13652 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13653 descriptorset_allocate_info.descriptorSetCount = 1;
13654 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13655 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13656 VkDescriptorSet descriptorset;
13657 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13658
13659 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13660
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013661 char const *vsSource =
13662 "#version 450\n"
13663 "\n"
13664 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13665 " mat4 mvp;\n"
13666 "} ubuf;\n"
13667 "out gl_PerVertex {\n"
13668 " vec4 gl_Position;\n"
13669 "};\n"
13670 "void main(){\n"
13671 " gl_Position = ubuf.mvp * vec4(1);\n"
13672 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013673
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013674 char const *fsSource =
13675 "#version 450\n"
13676 "\n"
13677 "layout(location = 0) out vec4 uFragColor;\n"
13678 "void main(){\n"
13679 " uFragColor = vec4(0,1,0,1);\n"
13680 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013681
13682 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13683 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13684
13685 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13686 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13687 pipeline_layout_create_info.setLayoutCount = 1;
13688 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13689
13690 VkPipelineLayout pipeline_layout;
13691 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13692
13693 VkPipelineObj pipe(m_device);
13694 pipe.AddColorAttachment();
13695 pipe.AddShader(&vs);
13696 pipe.AddShader(&fs);
13697
13698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13699 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13700 m_errorMonitor->VerifyFound();
13701
13702 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13703 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13704 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13705}
13706
13707TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013708 TEST_DESCRIPTION(
13709 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13710 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013711
13712 ASSERT_NO_FATAL_FAILURE(InitState());
13713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13714
13715 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013716 "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 -060013717
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013718 char const *vsSource =
13719 "#version 450\n"
13720 "\n"
13721 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13722 "out gl_PerVertex {\n"
13723 " vec4 gl_Position;\n"
13724 "};\n"
13725 "void main(){\n"
13726 " gl_Position = vec4(consts.x);\n"
13727 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013729 char const *fsSource =
13730 "#version 450\n"
13731 "\n"
13732 "layout(location = 0) out vec4 uFragColor;\n"
13733 "void main(){\n"
13734 " uFragColor = vec4(0,1,0,1);\n"
13735 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013736
13737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13739
13740 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13741 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13742
13743 // Set up a push constant range
13744 VkPushConstantRange push_constant_ranges = {};
13745 // Set to the wrong stage to challenge core_validation
13746 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13747 push_constant_ranges.size = 4;
13748
13749 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13750 pipeline_layout_create_info.pushConstantRangeCount = 1;
13751
13752 VkPipelineLayout pipeline_layout;
13753 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13754
13755 VkPipelineObj pipe(m_device);
13756 pipe.AddColorAttachment();
13757 pipe.AddShader(&vs);
13758 pipe.AddShader(&fs);
13759
13760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13761 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13762 m_errorMonitor->VerifyFound();
13763
13764 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13765}
13766
13767TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13768 TEST_DESCRIPTION(
13769 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13770
13771 ASSERT_NO_FATAL_FAILURE(InitState());
13772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13773
13774 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013775 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013776
13777 // Some awkward steps are required to test with custom device features.
13778 std::vector<const char *> device_extension_names;
13779 auto features = m_device->phy().features();
13780 // Disable support for 64 bit floats
13781 features.shaderFloat64 = false;
13782 // The sacrificial device object
13783 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13784
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013785 char const *vsSource =
13786 "#version 450\n"
13787 "\n"
13788 "out gl_PerVertex {\n"
13789 " vec4 gl_Position;\n"
13790 "};\n"
13791 "void main(){\n"
13792 " gl_Position = vec4(1);\n"
13793 "}\n";
13794 char const *fsSource =
13795 "#version 450\n"
13796 "\n"
13797 "layout(location=0) out vec4 color;\n"
13798 "void main(){\n"
13799 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13800 " color = vec4(green);\n"
13801 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013802
13803 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13804 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13805
13806 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013807
13808 VkPipelineObj pipe(&test_device);
13809 pipe.AddColorAttachment();
13810 pipe.AddShader(&vs);
13811 pipe.AddShader(&fs);
13812
13813 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13814 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13815 VkPipelineLayout pipeline_layout;
13816 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13817
13818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13819 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13820 m_errorMonitor->VerifyFound();
13821
13822 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13823}
13824
13825TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13826 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13827
13828 ASSERT_NO_FATAL_FAILURE(InitState());
13829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13830
13831 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13832
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013833 char const *vsSource =
13834 "#version 450\n"
13835 "\n"
13836 "out gl_PerVertex {\n"
13837 " vec4 gl_Position;\n"
13838 "};\n"
13839 "layout(xfb_buffer = 1) out;"
13840 "void main(){\n"
13841 " gl_Position = vec4(1);\n"
13842 "}\n";
13843 char const *fsSource =
13844 "#version 450\n"
13845 "\n"
13846 "layout(location=0) out vec4 color;\n"
13847 "void main(){\n"
13848 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13849 " color = vec4(green);\n"
13850 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013851
13852 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13853 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13854
13855 VkPipelineObj pipe(m_device);
13856 pipe.AddColorAttachment();
13857 pipe.AddShader(&vs);
13858 pipe.AddShader(&fs);
13859
13860 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13861 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13862 VkPipelineLayout pipeline_layout;
13863 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13864
13865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13866 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13867 m_errorMonitor->VerifyFound();
13868
13869 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13870}
13871
Karl Schultz6addd812016-02-02 17:17:23 -070013872TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013873 TEST_DESCRIPTION(
13874 "Test that an error is produced for a fragment shader input "
13875 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013878
Chris Forbes59cb88d2015-05-25 11:13:13 +120013879 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013881
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013882 char const *vsSource =
13883 "#version 450\n"
13884 "\n"
13885 "out gl_PerVertex {\n"
13886 " vec4 gl_Position;\n"
13887 "};\n"
13888 "void main(){\n"
13889 " gl_Position = vec4(1);\n"
13890 "}\n";
13891 char const *fsSource =
13892 "#version 450\n"
13893 "\n"
13894 "layout(location=0) in float x;\n"
13895 "layout(location=0) out vec4 color;\n"
13896 "void main(){\n"
13897 " color = vec4(x);\n"
13898 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013899
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013900 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13901 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013902
13903 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013904 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013905 pipe.AddShader(&vs);
13906 pipe.AddShader(&fs);
13907
Chris Forbes59cb88d2015-05-25 11:13:13 +120013908 VkDescriptorSetObj descriptorSet(m_device);
13909 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013910 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013911
Tony Barbour5781e8f2015-08-04 16:23:11 -060013912 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013913
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013914 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013915}
13916
Karl Schultz6addd812016-02-02 17:17:23 -070013917TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013918 TEST_DESCRIPTION(
13919 "Test that an error is produced for a fragment shader input "
13920 "within an interace block, which is not present in the outputs "
13921 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013923
13924 ASSERT_NO_FATAL_FAILURE(InitState());
13925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013927 char const *vsSource =
13928 "#version 450\n"
13929 "\n"
13930 "out gl_PerVertex {\n"
13931 " vec4 gl_Position;\n"
13932 "};\n"
13933 "void main(){\n"
13934 " gl_Position = vec4(1);\n"
13935 "}\n";
13936 char const *fsSource =
13937 "#version 450\n"
13938 "\n"
13939 "in block { layout(location=0) float x; } ins;\n"
13940 "layout(location=0) out vec4 color;\n"
13941 "void main(){\n"
13942 " color = vec4(ins.x);\n"
13943 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013944
13945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13947
13948 VkPipelineObj pipe(m_device);
13949 pipe.AddColorAttachment();
13950 pipe.AddShader(&vs);
13951 pipe.AddShader(&fs);
13952
13953 VkDescriptorSetObj descriptorSet(m_device);
13954 descriptorSet.AppendDummy();
13955 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13956
13957 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13958
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013959 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013960}
13961
Karl Schultz6addd812016-02-02 17:17:23 -070013962TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013963 TEST_DESCRIPTION(
13964 "Test that an error is produced for mismatched array sizes "
13965 "across the vertex->fragment shader interface");
13966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13967 "Type mismatch on location 0.0: 'ptr to "
13968 "output arr[2] of float32' vs 'ptr to "
13969 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013970
13971 ASSERT_NO_FATAL_FAILURE(InitState());
13972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13973
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013974 char const *vsSource =
13975 "#version 450\n"
13976 "\n"
13977 "layout(location=0) out float x[2];\n"
13978 "out gl_PerVertex {\n"
13979 " vec4 gl_Position;\n"
13980 "};\n"
13981 "void main(){\n"
13982 " x[0] = 0; x[1] = 0;\n"
13983 " gl_Position = vec4(1);\n"
13984 "}\n";
13985 char const *fsSource =
13986 "#version 450\n"
13987 "\n"
13988 "layout(location=0) in float x[1];\n"
13989 "layout(location=0) out vec4 color;\n"
13990 "void main(){\n"
13991 " color = vec4(x[0]);\n"
13992 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013993
13994 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13995 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13996
13997 VkPipelineObj pipe(m_device);
13998 pipe.AddColorAttachment();
13999 pipe.AddShader(&vs);
14000 pipe.AddShader(&fs);
14001
14002 VkDescriptorSetObj descriptorSet(m_device);
14003 descriptorSet.AppendDummy();
14004 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14005
14006 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14007
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014008 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014009}
14010
Karl Schultz6addd812016-02-02 17:17:23 -070014011TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014012 TEST_DESCRIPTION(
14013 "Test that an error is produced for mismatched types across "
14014 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014016
Chris Forbesb56af562015-05-25 11:13:17 +120014017 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014019
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014020 char const *vsSource =
14021 "#version 450\n"
14022 "\n"
14023 "layout(location=0) out int x;\n"
14024 "out gl_PerVertex {\n"
14025 " vec4 gl_Position;\n"
14026 "};\n"
14027 "void main(){\n"
14028 " x = 0;\n"
14029 " gl_Position = vec4(1);\n"
14030 "}\n";
14031 char const *fsSource =
14032 "#version 450\n"
14033 "\n"
14034 "layout(location=0) in float x;\n" /* VS writes int */
14035 "layout(location=0) out vec4 color;\n"
14036 "void main(){\n"
14037 " color = vec4(x);\n"
14038 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014039
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014040 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14041 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014042
14043 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014044 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014045 pipe.AddShader(&vs);
14046 pipe.AddShader(&fs);
14047
Chris Forbesb56af562015-05-25 11:13:17 +120014048 VkDescriptorSetObj descriptorSet(m_device);
14049 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014050 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014051
Tony Barbour5781e8f2015-08-04 16:23:11 -060014052 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014053
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014054 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014055}
14056
Karl Schultz6addd812016-02-02 17:17:23 -070014057TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014058 TEST_DESCRIPTION(
14059 "Test that an error is produced for mismatched types across "
14060 "the vertex->fragment shader interface, when the variable is contained within "
14061 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014063
14064 ASSERT_NO_FATAL_FAILURE(InitState());
14065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14066
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014067 char const *vsSource =
14068 "#version 450\n"
14069 "\n"
14070 "out block { layout(location=0) int x; } outs;\n"
14071 "out gl_PerVertex {\n"
14072 " vec4 gl_Position;\n"
14073 "};\n"
14074 "void main(){\n"
14075 " outs.x = 0;\n"
14076 " gl_Position = vec4(1);\n"
14077 "}\n";
14078 char const *fsSource =
14079 "#version 450\n"
14080 "\n"
14081 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14082 "layout(location=0) out vec4 color;\n"
14083 "void main(){\n"
14084 " color = vec4(ins.x);\n"
14085 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014086
14087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14089
14090 VkPipelineObj pipe(m_device);
14091 pipe.AddColorAttachment();
14092 pipe.AddShader(&vs);
14093 pipe.AddShader(&fs);
14094
14095 VkDescriptorSetObj descriptorSet(m_device);
14096 descriptorSet.AppendDummy();
14097 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14098
14099 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14100
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014101 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014102}
14103
14104TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014105 TEST_DESCRIPTION(
14106 "Test that an error is produced for location mismatches across "
14107 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14108 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109 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 +130014110
14111 ASSERT_NO_FATAL_FAILURE(InitState());
14112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14113
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014114 char const *vsSource =
14115 "#version 450\n"
14116 "\n"
14117 "out block { layout(location=1) float x; } outs;\n"
14118 "out gl_PerVertex {\n"
14119 " vec4 gl_Position;\n"
14120 "};\n"
14121 "void main(){\n"
14122 " outs.x = 0;\n"
14123 " gl_Position = vec4(1);\n"
14124 "}\n";
14125 char const *fsSource =
14126 "#version 450\n"
14127 "\n"
14128 "in block { layout(location=0) float x; } ins;\n"
14129 "layout(location=0) out vec4 color;\n"
14130 "void main(){\n"
14131 " color = vec4(ins.x);\n"
14132 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014133
14134 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14135 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14136
14137 VkPipelineObj pipe(m_device);
14138 pipe.AddColorAttachment();
14139 pipe.AddShader(&vs);
14140 pipe.AddShader(&fs);
14141
14142 VkDescriptorSetObj descriptorSet(m_device);
14143 descriptorSet.AppendDummy();
14144 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14145
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014146 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014147 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14148
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014149 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014150}
14151
14152TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014153 TEST_DESCRIPTION(
14154 "Test that an error is produced for component mismatches across the "
14155 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14156 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014157 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 +130014158
14159 ASSERT_NO_FATAL_FAILURE(InitState());
14160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14161
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014162 char const *vsSource =
14163 "#version 450\n"
14164 "\n"
14165 "out block { layout(location=0, component=0) float x; } outs;\n"
14166 "out gl_PerVertex {\n"
14167 " vec4 gl_Position;\n"
14168 "};\n"
14169 "void main(){\n"
14170 " outs.x = 0;\n"
14171 " gl_Position = vec4(1);\n"
14172 "}\n";
14173 char const *fsSource =
14174 "#version 450\n"
14175 "\n"
14176 "in block { layout(location=0, component=1) float x; } ins;\n"
14177 "layout(location=0) out vec4 color;\n"
14178 "void main(){\n"
14179 " color = vec4(ins.x);\n"
14180 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014181
14182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14184
14185 VkPipelineObj pipe(m_device);
14186 pipe.AddColorAttachment();
14187 pipe.AddShader(&vs);
14188 pipe.AddShader(&fs);
14189
14190 VkDescriptorSetObj descriptorSet(m_device);
14191 descriptorSet.AppendDummy();
14192 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14193
14194 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014196 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014197}
14198
Chris Forbes1f3b0152016-11-30 12:48:40 +130014199TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14200 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14201
14202 ASSERT_NO_FATAL_FAILURE(InitState());
14203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14204
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014205 char const *vsSource =
14206 "#version 450\n"
14207 "layout(location=0) out mediump float x;\n"
14208 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14209 char const *fsSource =
14210 "#version 450\n"
14211 "layout(location=0) in highp float x;\n"
14212 "layout(location=0) out vec4 color;\n"
14213 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014214
14215 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14216 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14217
14218 VkPipelineObj pipe(m_device);
14219 pipe.AddColorAttachment();
14220 pipe.AddShader(&vs);
14221 pipe.AddShader(&fs);
14222
14223 VkDescriptorSetObj descriptorSet(m_device);
14224 descriptorSet.AppendDummy();
14225 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14226
14227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14228
14229 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14230
14231 m_errorMonitor->VerifyFound();
14232}
14233
Chris Forbes870a39e2016-11-30 12:55:56 +130014234TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14235 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14236
14237 ASSERT_NO_FATAL_FAILURE(InitState());
14238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14239
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014240 char const *vsSource =
14241 "#version 450\n"
14242 "out block { layout(location=0) mediump float x; };\n"
14243 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14244 char const *fsSource =
14245 "#version 450\n"
14246 "in block { layout(location=0) highp float x; };\n"
14247 "layout(location=0) out vec4 color;\n"
14248 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014249
14250 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14251 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14252
14253 VkPipelineObj pipe(m_device);
14254 pipe.AddColorAttachment();
14255 pipe.AddShader(&vs);
14256 pipe.AddShader(&fs);
14257
14258 VkDescriptorSetObj descriptorSet(m_device);
14259 descriptorSet.AppendDummy();
14260 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14261
14262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14263
14264 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14265
14266 m_errorMonitor->VerifyFound();
14267}
14268
Karl Schultz6addd812016-02-02 17:17:23 -070014269TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014270 TEST_DESCRIPTION(
14271 "Test that a warning is produced for a vertex attribute which is "
14272 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014274
Chris Forbesde136e02015-05-25 11:13:28 +120014275 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014277
14278 VkVertexInputBindingDescription input_binding;
14279 memset(&input_binding, 0, sizeof(input_binding));
14280
14281 VkVertexInputAttributeDescription input_attrib;
14282 memset(&input_attrib, 0, sizeof(input_attrib));
14283 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14284
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014285 char const *vsSource =
14286 "#version 450\n"
14287 "\n"
14288 "out gl_PerVertex {\n"
14289 " vec4 gl_Position;\n"
14290 "};\n"
14291 "void main(){\n"
14292 " gl_Position = vec4(1);\n"
14293 "}\n";
14294 char const *fsSource =
14295 "#version 450\n"
14296 "\n"
14297 "layout(location=0) out vec4 color;\n"
14298 "void main(){\n"
14299 " color = vec4(1);\n"
14300 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014301
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014302 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14303 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014304
14305 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014306 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014307 pipe.AddShader(&vs);
14308 pipe.AddShader(&fs);
14309
14310 pipe.AddVertexInputBindings(&input_binding, 1);
14311 pipe.AddVertexInputAttribs(&input_attrib, 1);
14312
Chris Forbesde136e02015-05-25 11:13:28 +120014313 VkDescriptorSetObj descriptorSet(m_device);
14314 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014315 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014316
Tony Barbour5781e8f2015-08-04 16:23:11 -060014317 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014318
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014319 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014320}
14321
Karl Schultz6addd812016-02-02 17:17:23 -070014322TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014323 TEST_DESCRIPTION(
14324 "Test that a warning is produced for a location mismatch on "
14325 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014327
14328 ASSERT_NO_FATAL_FAILURE(InitState());
14329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14330
14331 VkVertexInputBindingDescription input_binding;
14332 memset(&input_binding, 0, sizeof(input_binding));
14333
14334 VkVertexInputAttributeDescription input_attrib;
14335 memset(&input_attrib, 0, sizeof(input_attrib));
14336 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14337
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014338 char const *vsSource =
14339 "#version 450\n"
14340 "\n"
14341 "layout(location=1) in float x;\n"
14342 "out gl_PerVertex {\n"
14343 " vec4 gl_Position;\n"
14344 "};\n"
14345 "void main(){\n"
14346 " gl_Position = vec4(x);\n"
14347 "}\n";
14348 char const *fsSource =
14349 "#version 450\n"
14350 "\n"
14351 "layout(location=0) out vec4 color;\n"
14352 "void main(){\n"
14353 " color = vec4(1);\n"
14354 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014355
14356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14358
14359 VkPipelineObj pipe(m_device);
14360 pipe.AddColorAttachment();
14361 pipe.AddShader(&vs);
14362 pipe.AddShader(&fs);
14363
14364 pipe.AddVertexInputBindings(&input_binding, 1);
14365 pipe.AddVertexInputAttribs(&input_attrib, 1);
14366
14367 VkDescriptorSetObj descriptorSet(m_device);
14368 descriptorSet.AppendDummy();
14369 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14370
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014371 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014372 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014374 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014375}
14376
Karl Schultz6addd812016-02-02 17:17:23 -070014377TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014378 TEST_DESCRIPTION(
14379 "Test that an error is produced for a vertex shader input which is not "
14380 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14382 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014383
Chris Forbes62e8e502015-05-25 11:13:29 +120014384 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014386
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014387 char const *vsSource =
14388 "#version 450\n"
14389 "\n"
14390 "layout(location=0) in vec4 x;\n" /* not provided */
14391 "out gl_PerVertex {\n"
14392 " vec4 gl_Position;\n"
14393 "};\n"
14394 "void main(){\n"
14395 " gl_Position = x;\n"
14396 "}\n";
14397 char const *fsSource =
14398 "#version 450\n"
14399 "\n"
14400 "layout(location=0) out vec4 color;\n"
14401 "void main(){\n"
14402 " color = vec4(1);\n"
14403 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014404
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014407
14408 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014409 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014410 pipe.AddShader(&vs);
14411 pipe.AddShader(&fs);
14412
Chris Forbes62e8e502015-05-25 11:13:29 +120014413 VkDescriptorSetObj descriptorSet(m_device);
14414 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014415 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014416
Tony Barbour5781e8f2015-08-04 16:23:11 -060014417 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014418
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014419 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014420}
14421
Karl Schultz6addd812016-02-02 17:17:23 -070014422TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014423 TEST_DESCRIPTION(
14424 "Test that an error is produced for a mismatch between the "
14425 "fundamental type (float/int/uint) of an attribute and the "
14426 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014427 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 -060014428
Chris Forbesc97d98e2015-05-25 11:13:31 +120014429 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014431
14432 VkVertexInputBindingDescription input_binding;
14433 memset(&input_binding, 0, sizeof(input_binding));
14434
14435 VkVertexInputAttributeDescription input_attrib;
14436 memset(&input_attrib, 0, sizeof(input_attrib));
14437 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14438
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014439 char const *vsSource =
14440 "#version 450\n"
14441 "\n"
14442 "layout(location=0) in int x;\n" /* attrib provided float */
14443 "out gl_PerVertex {\n"
14444 " vec4 gl_Position;\n"
14445 "};\n"
14446 "void main(){\n"
14447 " gl_Position = vec4(x);\n"
14448 "}\n";
14449 char const *fsSource =
14450 "#version 450\n"
14451 "\n"
14452 "layout(location=0) out vec4 color;\n"
14453 "void main(){\n"
14454 " color = vec4(1);\n"
14455 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014456
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014459
14460 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014461 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014462 pipe.AddShader(&vs);
14463 pipe.AddShader(&fs);
14464
14465 pipe.AddVertexInputBindings(&input_binding, 1);
14466 pipe.AddVertexInputAttribs(&input_attrib, 1);
14467
Chris Forbesc97d98e2015-05-25 11:13:31 +120014468 VkDescriptorSetObj descriptorSet(m_device);
14469 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014471
Tony Barbour5781e8f2015-08-04 16:23:11 -060014472 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014474 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014475}
14476
Chris Forbesc68b43c2016-04-06 11:18:47 +120014477TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014478 TEST_DESCRIPTION(
14479 "Test that an error is produced for a pipeline containing multiple "
14480 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14482 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014483
14484 ASSERT_NO_FATAL_FAILURE(InitState());
14485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14486
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014487 char const *vsSource =
14488 "#version 450\n"
14489 "\n"
14490 "out gl_PerVertex {\n"
14491 " vec4 gl_Position;\n"
14492 "};\n"
14493 "void main(){\n"
14494 " gl_Position = vec4(1);\n"
14495 "}\n";
14496 char const *fsSource =
14497 "#version 450\n"
14498 "\n"
14499 "layout(location=0) out vec4 color;\n"
14500 "void main(){\n"
14501 " color = vec4(1);\n"
14502 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014503
14504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14506
14507 VkPipelineObj pipe(m_device);
14508 pipe.AddColorAttachment();
14509 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014510 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014511 pipe.AddShader(&fs);
14512
14513 VkDescriptorSetObj descriptorSet(m_device);
14514 descriptorSet.AppendDummy();
14515 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14516
14517 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14518
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014519 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014520}
14521
Chris Forbes82ff92a2016-09-09 10:50:24 +120014522TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014524
14525 ASSERT_NO_FATAL_FAILURE(InitState());
14526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14527
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014528 char const *vsSource =
14529 "#version 450\n"
14530 "out gl_PerVertex {\n"
14531 " vec4 gl_Position;\n"
14532 "};\n"
14533 "void main(){\n"
14534 " gl_Position = vec4(0);\n"
14535 "}\n";
14536 char const *fsSource =
14537 "#version 450\n"
14538 "\n"
14539 "layout(location=0) out vec4 color;\n"
14540 "void main(){\n"
14541 " color = vec4(1);\n"
14542 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014543
14544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14546
14547 VkPipelineObj pipe(m_device);
14548 pipe.AddColorAttachment();
14549 pipe.AddShader(&vs);
14550 pipe.AddShader(&fs);
14551
14552 VkDescriptorSetObj descriptorSet(m_device);
14553 descriptorSet.AppendDummy();
14554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14555
14556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14557
14558 m_errorMonitor->VerifyFound();
14559}
14560
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014561TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14563 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14564 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014565
14566 ASSERT_NO_FATAL_FAILURE(InitState());
14567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014569 char const *vsSource =
14570 "#version 450\n"
14571 "void main(){ gl_Position = vec4(0); }\n";
14572 char const *fsSource =
14573 "#version 450\n"
14574 "\n"
14575 "layout(location=0) out vec4 color;\n"
14576 "void main(){\n"
14577 " color = vec4(1);\n"
14578 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014579
14580 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14581 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14582
14583 VkPipelineObj pipe(m_device);
14584 pipe.AddColorAttachment();
14585 pipe.AddShader(&vs);
14586 pipe.AddShader(&fs);
14587
14588 VkDescriptorSetObj descriptorSet(m_device);
14589 descriptorSet.AppendDummy();
14590 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14591
14592 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014593 {
14594 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14595 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14596 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014597 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014598 {
14599 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14600 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14601 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014602 },
14603 };
14604 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014605 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014606 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014607 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14608 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014609 VkRenderPass rp;
14610 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14611 ASSERT_VK_SUCCESS(err);
14612
14613 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14614
14615 m_errorMonitor->VerifyFound();
14616
14617 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14618}
14619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014620TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014621 TEST_DESCRIPTION(
14622 "Test that an error is produced for a variable output from "
14623 "the TCS without the patch decoration, but consumed in the TES "
14624 "with the decoration.");
14625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14626 "is per-vertex in tessellation control shader stage "
14627 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014628
14629 ASSERT_NO_FATAL_FAILURE(InitState());
14630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14631
Chris Forbesc1e852d2016-04-04 19:26:42 +120014632 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014633 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014634 return;
14635 }
14636
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014637 char const *vsSource =
14638 "#version 450\n"
14639 "void main(){}\n";
14640 char const *tcsSource =
14641 "#version 450\n"
14642 "layout(location=0) out int x[];\n"
14643 "layout(vertices=3) out;\n"
14644 "void main(){\n"
14645 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14646 " gl_TessLevelInner[0] = 1;\n"
14647 " x[gl_InvocationID] = gl_InvocationID;\n"
14648 "}\n";
14649 char const *tesSource =
14650 "#version 450\n"
14651 "layout(triangles, equal_spacing, cw) in;\n"
14652 "layout(location=0) patch in int x;\n"
14653 "out gl_PerVertex { vec4 gl_Position; };\n"
14654 "void main(){\n"
14655 " gl_Position.xyz = gl_TessCoord;\n"
14656 " gl_Position.w = x;\n"
14657 "}\n";
14658 char const *fsSource =
14659 "#version 450\n"
14660 "layout(location=0) out vec4 color;\n"
14661 "void main(){\n"
14662 " color = vec4(1);\n"
14663 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014664
14665 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14666 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14667 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014670 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14671 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014674
14675 VkPipelineObj pipe(m_device);
14676 pipe.SetInputAssembly(&iasci);
14677 pipe.SetTessellation(&tsci);
14678 pipe.AddColorAttachment();
14679 pipe.AddShader(&vs);
14680 pipe.AddShader(&tcs);
14681 pipe.AddShader(&tes);
14682 pipe.AddShader(&fs);
14683
14684 VkDescriptorSetObj descriptorSet(m_device);
14685 descriptorSet.AppendDummy();
14686 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14687
14688 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14689
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014690 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014691}
14692
Karl Schultz6addd812016-02-02 17:17:23 -070014693TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014694 TEST_DESCRIPTION(
14695 "Test that an error is produced for a vertex attribute setup where multiple "
14696 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14698 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014699
Chris Forbes280ba2c2015-06-12 11:16:41 +120014700 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014702
14703 /* Two binding descriptions for binding 0 */
14704 VkVertexInputBindingDescription input_bindings[2];
14705 memset(input_bindings, 0, sizeof(input_bindings));
14706
14707 VkVertexInputAttributeDescription input_attrib;
14708 memset(&input_attrib, 0, sizeof(input_attrib));
14709 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14710
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014711 char const *vsSource =
14712 "#version 450\n"
14713 "\n"
14714 "layout(location=0) in float x;\n" /* attrib provided float */
14715 "out gl_PerVertex {\n"
14716 " vec4 gl_Position;\n"
14717 "};\n"
14718 "void main(){\n"
14719 " gl_Position = vec4(x);\n"
14720 "}\n";
14721 char const *fsSource =
14722 "#version 450\n"
14723 "\n"
14724 "layout(location=0) out vec4 color;\n"
14725 "void main(){\n"
14726 " color = vec4(1);\n"
14727 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014728
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014729 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14730 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014731
14732 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014733 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014734 pipe.AddShader(&vs);
14735 pipe.AddShader(&fs);
14736
14737 pipe.AddVertexInputBindings(input_bindings, 2);
14738 pipe.AddVertexInputAttribs(&input_attrib, 1);
14739
Chris Forbes280ba2c2015-06-12 11:16:41 +120014740 VkDescriptorSetObj descriptorSet(m_device);
14741 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014742 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014743
Tony Barbour5781e8f2015-08-04 16:23:11 -060014744 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014746 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014747}
Chris Forbes8f68b562015-05-25 11:13:32 +120014748
Karl Schultz6addd812016-02-02 17:17:23 -070014749TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014750 TEST_DESCRIPTION(
14751 "Test that an error is produced for a fragment shader which does not "
14752 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014754
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014755 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014756
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014757 char const *vsSource =
14758 "#version 450\n"
14759 "\n"
14760 "out gl_PerVertex {\n"
14761 " vec4 gl_Position;\n"
14762 "};\n"
14763 "void main(){\n"
14764 " gl_Position = vec4(1);\n"
14765 "}\n";
14766 char const *fsSource =
14767 "#version 450\n"
14768 "\n"
14769 "void main(){\n"
14770 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014771
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014772 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14773 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014774
14775 VkPipelineObj pipe(m_device);
14776 pipe.AddShader(&vs);
14777 pipe.AddShader(&fs);
14778
Chia-I Wu08accc62015-07-07 11:50:03 +080014779 /* set up CB 0, not written */
14780 pipe.AddColorAttachment();
14781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014782
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014783 VkDescriptorSetObj descriptorSet(m_device);
14784 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014785 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014786
Tony Barbour5781e8f2015-08-04 16:23:11 -060014787 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014788
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014789 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014790}
14791
Karl Schultz6addd812016-02-02 17:17:23 -070014792TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014793 TEST_DESCRIPTION(
14794 "Test that a warning is produced for a fragment shader which provides a spurious "
14795 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014797 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014798
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014799 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014801 char const *vsSource =
14802 "#version 450\n"
14803 "\n"
14804 "out gl_PerVertex {\n"
14805 " vec4 gl_Position;\n"
14806 "};\n"
14807 "void main(){\n"
14808 " gl_Position = vec4(1);\n"
14809 "}\n";
14810 char const *fsSource =
14811 "#version 450\n"
14812 "\n"
14813 "layout(location=0) out vec4 x;\n"
14814 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14815 "void main(){\n"
14816 " x = vec4(1);\n"
14817 " y = vec4(1);\n"
14818 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014819
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014820 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14821 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014822
14823 VkPipelineObj pipe(m_device);
14824 pipe.AddShader(&vs);
14825 pipe.AddShader(&fs);
14826
Chia-I Wu08accc62015-07-07 11:50:03 +080014827 /* set up CB 0, not written */
14828 pipe.AddColorAttachment();
14829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014830 /* FS writes CB 1, but we don't configure it */
14831
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014832 VkDescriptorSetObj descriptorSet(m_device);
14833 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014834 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014835
Tony Barbour5781e8f2015-08-04 16:23:11 -060014836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014837
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014838 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014839}
14840
Karl Schultz6addd812016-02-02 17:17:23 -070014841TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014842 TEST_DESCRIPTION(
14843 "Test that an error is produced for a mismatch between the fundamental "
14844 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014846
Chris Forbesa36d69e2015-05-25 11:13:44 +120014847 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014848
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014849 char const *vsSource =
14850 "#version 450\n"
14851 "\n"
14852 "out gl_PerVertex {\n"
14853 " vec4 gl_Position;\n"
14854 "};\n"
14855 "void main(){\n"
14856 " gl_Position = vec4(1);\n"
14857 "}\n";
14858 char const *fsSource =
14859 "#version 450\n"
14860 "\n"
14861 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14862 "void main(){\n"
14863 " x = ivec4(1);\n"
14864 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014865
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014866 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14867 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014868
14869 VkPipelineObj pipe(m_device);
14870 pipe.AddShader(&vs);
14871 pipe.AddShader(&fs);
14872
Chia-I Wu08accc62015-07-07 11:50:03 +080014873 /* set up CB 0; type is UNORM by default */
14874 pipe.AddColorAttachment();
14875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014876
Chris Forbesa36d69e2015-05-25 11:13:44 +120014877 VkDescriptorSetObj descriptorSet(m_device);
14878 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014879 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014880
Tony Barbour5781e8f2015-08-04 16:23:11 -060014881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014882
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014883 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014884}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014885
Karl Schultz6addd812016-02-02 17:17:23 -070014886TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014887 TEST_DESCRIPTION(
14888 "Test that an error is produced for a shader consuming a uniform "
14889 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014891
Chris Forbes556c76c2015-08-14 12:04:59 +120014892 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014893
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014894 char const *vsSource =
14895 "#version 450\n"
14896 "\n"
14897 "out gl_PerVertex {\n"
14898 " vec4 gl_Position;\n"
14899 "};\n"
14900 "void main(){\n"
14901 " gl_Position = vec4(1);\n"
14902 "}\n";
14903 char const *fsSource =
14904 "#version 450\n"
14905 "\n"
14906 "layout(location=0) out vec4 x;\n"
14907 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14908 "void main(){\n"
14909 " x = vec4(bar.y);\n"
14910 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014911
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014914
Chris Forbes556c76c2015-08-14 12:04:59 +120014915 VkPipelineObj pipe(m_device);
14916 pipe.AddShader(&vs);
14917 pipe.AddShader(&fs);
14918
14919 /* set up CB 0; type is UNORM by default */
14920 pipe.AddColorAttachment();
14921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14922
14923 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014924 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014925
14926 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14927
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014928 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014929}
14930
Chris Forbes5c59e902016-02-26 16:56:09 +130014931TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014932 TEST_DESCRIPTION(
14933 "Test that an error is produced for a shader consuming push constants "
14934 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014936
14937 ASSERT_NO_FATAL_FAILURE(InitState());
14938
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014939 char const *vsSource =
14940 "#version 450\n"
14941 "\n"
14942 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14943 "out gl_PerVertex {\n"
14944 " vec4 gl_Position;\n"
14945 "};\n"
14946 "void main(){\n"
14947 " gl_Position = vec4(consts.x);\n"
14948 "}\n";
14949 char const *fsSource =
14950 "#version 450\n"
14951 "\n"
14952 "layout(location=0) out vec4 x;\n"
14953 "void main(){\n"
14954 " x = vec4(1);\n"
14955 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014956
14957 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14958 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14959
14960 VkPipelineObj pipe(m_device);
14961 pipe.AddShader(&vs);
14962 pipe.AddShader(&fs);
14963
14964 /* set up CB 0; type is UNORM by default */
14965 pipe.AddColorAttachment();
14966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14967
14968 VkDescriptorSetObj descriptorSet(m_device);
14969 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14970
14971 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14972
14973 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014974 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014975}
14976
Chris Forbes3fb17902016-08-22 14:57:55 +120014977TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014978 TEST_DESCRIPTION(
14979 "Test that an error is produced for a shader consuming an input attachment "
14980 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14982 "consumes input attachment index 0 but not provided in subpass");
14983
14984 ASSERT_NO_FATAL_FAILURE(InitState());
14985
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014986 char const *vsSource =
14987 "#version 450\n"
14988 "\n"
14989 "out gl_PerVertex {\n"
14990 " vec4 gl_Position;\n"
14991 "};\n"
14992 "void main(){\n"
14993 " gl_Position = vec4(1);\n"
14994 "}\n";
14995 char const *fsSource =
14996 "#version 450\n"
14997 "\n"
14998 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14999 "layout(location=0) out vec4 color;\n"
15000 "void main() {\n"
15001 " color = subpassLoad(x);\n"
15002 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015003
15004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15006
15007 VkPipelineObj pipe(m_device);
15008 pipe.AddShader(&vs);
15009 pipe.AddShader(&fs);
15010 pipe.AddColorAttachment();
15011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015013 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15014 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015015 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015017 ASSERT_VK_SUCCESS(err);
15018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015020 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015022 ASSERT_VK_SUCCESS(err);
15023
15024 // error here.
15025 pipe.CreateVKPipeline(pl, renderPass());
15026
15027 m_errorMonitor->VerifyFound();
15028
15029 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15030 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15031}
15032
Chris Forbes5a9a0472016-08-22 16:02:09 +120015033TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015034 TEST_DESCRIPTION(
15035 "Test that an error is produced for a shader consuming an input attachment "
15036 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15038 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15039
15040 ASSERT_NO_FATAL_FAILURE(InitState());
15041
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015042 char const *vsSource =
15043 "#version 450\n"
15044 "\n"
15045 "out gl_PerVertex {\n"
15046 " vec4 gl_Position;\n"
15047 "};\n"
15048 "void main(){\n"
15049 " gl_Position = vec4(1);\n"
15050 "}\n";
15051 char const *fsSource =
15052 "#version 450\n"
15053 "\n"
15054 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15055 "layout(location=0) out vec4 color;\n"
15056 "void main() {\n"
15057 " color = subpassLoad(x);\n"
15058 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015059
15060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15062
15063 VkPipelineObj pipe(m_device);
15064 pipe.AddShader(&vs);
15065 pipe.AddShader(&fs);
15066 pipe.AddColorAttachment();
15067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015069 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15070 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015071 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015073 ASSERT_VK_SUCCESS(err);
15074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015075 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015076 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015078 ASSERT_VK_SUCCESS(err);
15079
15080 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15082 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15083 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15084 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15085 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 +120015086 };
15087 VkAttachmentReference color = {
15088 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15089 };
15090 VkAttachmentReference input = {
15091 1, VK_IMAGE_LAYOUT_GENERAL,
15092 };
15093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015097 VkRenderPass rp;
15098 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15099 ASSERT_VK_SUCCESS(err);
15100
15101 // error here.
15102 pipe.CreateVKPipeline(pl, rp);
15103
15104 m_errorMonitor->VerifyFound();
15105
15106 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15107 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15108 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15109}
15110
Chris Forbes541f7b02016-08-22 15:30:27 +120015111TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015112 TEST_DESCRIPTION(
15113 "Test that an error is produced for a shader consuming an input attachment "
15114 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015116 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015117
15118 ASSERT_NO_FATAL_FAILURE(InitState());
15119
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015120 char const *vsSource =
15121 "#version 450\n"
15122 "\n"
15123 "out gl_PerVertex {\n"
15124 " vec4 gl_Position;\n"
15125 "};\n"
15126 "void main(){\n"
15127 " gl_Position = vec4(1);\n"
15128 "}\n";
15129 char const *fsSource =
15130 "#version 450\n"
15131 "\n"
15132 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15133 "layout(location=0) out vec4 color;\n"
15134 "void main() {\n"
15135 " color = subpassLoad(xs[0]);\n"
15136 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015137
15138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15140
15141 VkPipelineObj pipe(m_device);
15142 pipe.AddShader(&vs);
15143 pipe.AddShader(&fs);
15144 pipe.AddColorAttachment();
15145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15148 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015149 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015151 ASSERT_VK_SUCCESS(err);
15152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015153 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015154 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015155 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015156 ASSERT_VK_SUCCESS(err);
15157
15158 // error here.
15159 pipe.CreateVKPipeline(pl, renderPass());
15160
15161 m_errorMonitor->VerifyFound();
15162
15163 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15164 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15165}
15166
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015167TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015168 TEST_DESCRIPTION(
15169 "Test that an error is produced for a compute pipeline consuming a "
15170 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015172
15173 ASSERT_NO_FATAL_FAILURE(InitState());
15174
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015175 char const *csSource =
15176 "#version 450\n"
15177 "\n"
15178 "layout(local_size_x=1) in;\n"
15179 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15180 "void main(){\n"
15181 " x = vec4(1);\n"
15182 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015183
15184 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15185
15186 VkDescriptorSetObj descriptorSet(m_device);
15187 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15190 nullptr,
15191 0,
15192 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15193 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15194 descriptorSet.GetPipelineLayout(),
15195 VK_NULL_HANDLE,
15196 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015197
15198 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015199 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015200
15201 m_errorMonitor->VerifyFound();
15202
15203 if (err == VK_SUCCESS) {
15204 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15205 }
15206}
15207
Chris Forbes22a9b092016-07-19 14:34:05 +120015208TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015209 TEST_DESCRIPTION(
15210 "Test that an error is produced for a pipeline consuming a "
15211 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15213 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015214
15215 ASSERT_NO_FATAL_FAILURE(InitState());
15216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015217 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15218 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015219 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015220 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015221 ASSERT_VK_SUCCESS(err);
15222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015223 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015224 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015226 ASSERT_VK_SUCCESS(err);
15227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015228 char const *csSource =
15229 "#version 450\n"
15230 "\n"
15231 "layout(local_size_x=1) in;\n"
15232 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15233 "void main() {\n"
15234 " x.x = 1.0f;\n"
15235 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015236 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15239 nullptr,
15240 0,
15241 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15242 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15243 pl,
15244 VK_NULL_HANDLE,
15245 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015246
15247 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015249
15250 m_errorMonitor->VerifyFound();
15251
15252 if (err == VK_SUCCESS) {
15253 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15254 }
15255
15256 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15257 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15258}
15259
Chris Forbes50020592016-07-27 13:52:41 +120015260TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015261 TEST_DESCRIPTION(
15262 "Test that an error is produced when an image view type "
15263 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 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 +120015266
15267 ASSERT_NO_FATAL_FAILURE(InitState());
15268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15269
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015270 char const *vsSource =
15271 "#version 450\n"
15272 "\n"
15273 "out gl_PerVertex { vec4 gl_Position; };\n"
15274 "void main() { gl_Position = vec4(0); }\n";
15275 char const *fsSource =
15276 "#version 450\n"
15277 "\n"
15278 "layout(set=0, binding=0) uniform sampler3D s;\n"
15279 "layout(location=0) out vec4 color;\n"
15280 "void main() {\n"
15281 " color = texture(s, vec3(0));\n"
15282 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15285
15286 VkPipelineObj pipe(m_device);
15287 pipe.AddShader(&vs);
15288 pipe.AddShader(&fs);
15289 pipe.AddColorAttachment();
15290
15291 VkTextureObj texture(m_device, nullptr);
15292 VkSamplerObj sampler(m_device);
15293
15294 VkDescriptorSetObj descriptorSet(m_device);
15295 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15297
15298 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15299 ASSERT_VK_SUCCESS(err);
15300
Tony Barbour552f6c02016-12-21 14:34:07 -070015301 m_commandBuffer->BeginCommandBuffer();
15302 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015303
15304 m_commandBuffer->BindPipeline(pipe);
15305 m_commandBuffer->BindDescriptorSet(descriptorSet);
15306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015308 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015310 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15311
15312 // error produced here.
15313 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15314
15315 m_errorMonitor->VerifyFound();
15316
Tony Barbour552f6c02016-12-21 14:34:07 -070015317 m_commandBuffer->EndRenderPass();
15318 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015319}
15320
Chris Forbes5533bfc2016-07-27 14:12:34 +120015321TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015322 TEST_DESCRIPTION(
15323 "Test that an error is produced when a multisampled images "
15324 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015327
15328 ASSERT_NO_FATAL_FAILURE(InitState());
15329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15330
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015331 char const *vsSource =
15332 "#version 450\n"
15333 "\n"
15334 "out gl_PerVertex { vec4 gl_Position; };\n"
15335 "void main() { gl_Position = vec4(0); }\n";
15336 char const *fsSource =
15337 "#version 450\n"
15338 "\n"
15339 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15340 "layout(location=0) out vec4 color;\n"
15341 "void main() {\n"
15342 " color = texelFetch(s, ivec2(0), 0);\n"
15343 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015344 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15345 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15346
15347 VkPipelineObj pipe(m_device);
15348 pipe.AddShader(&vs);
15349 pipe.AddShader(&fs);
15350 pipe.AddColorAttachment();
15351
15352 VkTextureObj texture(m_device, nullptr);
15353 VkSamplerObj sampler(m_device);
15354
15355 VkDescriptorSetObj descriptorSet(m_device);
15356 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15357 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15358
15359 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15360 ASSERT_VK_SUCCESS(err);
15361
Tony Barbour552f6c02016-12-21 14:34:07 -070015362 m_commandBuffer->BeginCommandBuffer();
15363 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015364
15365 m_commandBuffer->BindPipeline(pipe);
15366 m_commandBuffer->BindDescriptorSet(descriptorSet);
15367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015368 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015369 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015371 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15372
15373 // error produced here.
15374 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15375
15376 m_errorMonitor->VerifyFound();
15377
Tony Barbour552f6c02016-12-21 14:34:07 -070015378 m_commandBuffer->EndRenderPass();
15379 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015380}
15381
Mark Youngc48c4c12016-04-11 14:26:49 -060015382TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015384
15385 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015386
15387 // Create an image
15388 VkImage image;
15389
Karl Schultz6addd812016-02-02 17:17:23 -070015390 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15391 const int32_t tex_width = 32;
15392 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015393
15394 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015395 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15396 image_create_info.pNext = NULL;
15397 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15398 image_create_info.format = tex_format;
15399 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015400 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015401 image_create_info.extent.depth = 1;
15402 image_create_info.mipLevels = 1;
15403 image_create_info.arrayLayers = 1;
15404 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15405 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15406 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15407 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015408
15409 // Introduce error by sending down a bogus width extent
15410 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015411 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015412
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015413 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015414}
15415
Mark Youngc48c4c12016-04-11 14:26:49 -060015416TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015418
15419 ASSERT_NO_FATAL_FAILURE(InitState());
15420
15421 // Create an image
15422 VkImage image;
15423
15424 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15425 const int32_t tex_width = 32;
15426 const int32_t tex_height = 32;
15427
15428 VkImageCreateInfo image_create_info = {};
15429 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15430 image_create_info.pNext = NULL;
15431 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15432 image_create_info.format = tex_format;
15433 image_create_info.extent.width = tex_width;
15434 image_create_info.extent.height = tex_height;
15435 image_create_info.extent.depth = 1;
15436 image_create_info.mipLevels = 1;
15437 image_create_info.arrayLayers = 1;
15438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15439 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15440 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15441 image_create_info.flags = 0;
15442
15443 // Introduce error by sending down a bogus width extent
15444 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015445 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015446 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15447
15448 m_errorMonitor->VerifyFound();
15449}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015450
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015451TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015452 TEST_DESCRIPTION(
15453 "Create a render pass with an attachment description "
15454 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015455
15456 ASSERT_NO_FATAL_FAILURE(InitState());
15457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15458
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015460
15461 VkAttachmentReference color_attach = {};
15462 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15463 color_attach.attachment = 0;
15464 VkSubpassDescription subpass = {};
15465 subpass.colorAttachmentCount = 1;
15466 subpass.pColorAttachments = &color_attach;
15467
15468 VkRenderPassCreateInfo rpci = {};
15469 rpci.subpassCount = 1;
15470 rpci.pSubpasses = &subpass;
15471 rpci.attachmentCount = 1;
15472 VkAttachmentDescription attach_desc = {};
15473 attach_desc.format = VK_FORMAT_UNDEFINED;
15474 rpci.pAttachments = &attach_desc;
15475 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15476 VkRenderPass rp;
15477 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15478
15479 m_errorMonitor->VerifyFound();
15480
15481 if (result == VK_SUCCESS) {
15482 vkDestroyRenderPass(m_device->device(), rp, NULL);
15483 }
15484}
15485
Karl Schultz6addd812016-02-02 17:17:23 -070015486TEST_F(VkLayerTest, InvalidImageView) {
15487 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015488
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015490
Tobin Ehliscde08892015-09-22 10:11:37 -060015491 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015492
Mike Stroyana3082432015-09-25 13:39:21 -060015493 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015494 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015495
Karl Schultz6addd812016-02-02 17:17:23 -070015496 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15497 const int32_t tex_width = 32;
15498 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015499
15500 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15502 image_create_info.pNext = NULL;
15503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15504 image_create_info.format = tex_format;
15505 image_create_info.extent.width = tex_width;
15506 image_create_info.extent.height = tex_height;
15507 image_create_info.extent.depth = 1;
15508 image_create_info.mipLevels = 1;
15509 image_create_info.arrayLayers = 1;
15510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15511 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15512 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15513 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015514
Chia-I Wuf7458c52015-10-26 21:10:41 +080015515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015516 ASSERT_VK_SUCCESS(err);
15517
15518 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015519 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015520 image_view_create_info.image = image;
15521 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15522 image_view_create_info.format = tex_format;
15523 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015524 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015525 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015526 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015527
15528 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015529 m_errorMonitor->SetUnexpectedError(
15530 "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 -060015531 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015532
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015533 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015534 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015535}
Mike Stroyana3082432015-09-25 13:39:21 -060015536
Mark Youngd339ba32016-05-30 13:28:35 -060015537TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15538 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015540 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015541
15542 ASSERT_NO_FATAL_FAILURE(InitState());
15543
15544 // Create an image and try to create a view with no memory backing the image
15545 VkImage image;
15546
15547 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15548 const int32_t tex_width = 32;
15549 const int32_t tex_height = 32;
15550
15551 VkImageCreateInfo image_create_info = {};
15552 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15553 image_create_info.pNext = NULL;
15554 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15555 image_create_info.format = tex_format;
15556 image_create_info.extent.width = tex_width;
15557 image_create_info.extent.height = tex_height;
15558 image_create_info.extent.depth = 1;
15559 image_create_info.mipLevels = 1;
15560 image_create_info.arrayLayers = 1;
15561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15562 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15563 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15564 image_create_info.flags = 0;
15565
15566 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15567 ASSERT_VK_SUCCESS(err);
15568
15569 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015570 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015571 image_view_create_info.image = image;
15572 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15573 image_view_create_info.format = tex_format;
15574 image_view_create_info.subresourceRange.layerCount = 1;
15575 image_view_create_info.subresourceRange.baseMipLevel = 0;
15576 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015577 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015578
15579 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015580 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015581
15582 m_errorMonitor->VerifyFound();
15583 vkDestroyImage(m_device->device(), image, NULL);
15584 // If last error is success, it still created the view, so delete it.
15585 if (err == VK_SUCCESS) {
15586 vkDestroyImageView(m_device->device(), view, NULL);
15587 }
Mark Youngd339ba32016-05-30 13:28:35 -060015588}
15589
Karl Schultz6addd812016-02-02 17:17:23 -070015590TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015591 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015593
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015594 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015595
Karl Schultz6addd812016-02-02 17:17:23 -070015596 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015597 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015598 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015599 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015600
15601 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015602 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015603 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015604 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15605 image_view_create_info.format = tex_format;
15606 image_view_create_info.subresourceRange.baseMipLevel = 0;
15607 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015608 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015609 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015611
15612 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015613 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015614
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015615 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015616}
15617
Mike Weiblena1e13f42017-02-09 21:25:59 -070015618TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15619 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15620
15621 ASSERT_NO_FATAL_FAILURE(InitState());
15622 VkSubresourceLayout subres_layout = {};
15623
15624 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15625 {
15626 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15627 VkImageObj img(m_device);
15628 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15629 ASSERT_TRUE(img.initialized());
15630
15631 VkImageSubresource subres = {};
15632 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15633 subres.mipLevel = 0;
15634 subres.arrayLayer = 0;
15635
15636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15637 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15638 m_errorMonitor->VerifyFound();
15639 }
15640
15641 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15642 {
15643 VkImageObj img(m_device);
15644 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15645 ASSERT_TRUE(img.initialized());
15646
15647 VkImageSubresource subres = {};
15648 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15649 subres.mipLevel = 0;
15650 subres.arrayLayer = 0;
15651
15652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15654 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15655 m_errorMonitor->VerifyFound();
15656 }
15657
15658 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15659 {
15660 VkImageObj img(m_device);
15661 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15662 ASSERT_TRUE(img.initialized());
15663
15664 VkImageSubresource subres = {};
15665 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15666 subres.mipLevel = 1; // ERROR: triggers VU 00739
15667 subres.arrayLayer = 0;
15668
15669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15670 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15671 m_errorMonitor->VerifyFound();
15672 }
15673
15674 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15675 {
15676 VkImageObj img(m_device);
15677 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15678 ASSERT_TRUE(img.initialized());
15679
15680 VkImageSubresource subres = {};
15681 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15682 subres.mipLevel = 0;
15683 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15684
15685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15686 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15687 m_errorMonitor->VerifyFound();
15688 }
15689}
15690
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015691TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015692 VkResult err;
15693 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015694
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015696
Mike Stroyana3082432015-09-25 13:39:21 -060015697 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015698
15699 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015700 VkImage srcImage;
15701 VkImage dstImage;
15702 VkDeviceMemory srcMem;
15703 VkDeviceMemory destMem;
15704 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
15706 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15708 image_create_info.pNext = NULL;
15709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15711 image_create_info.extent.width = 32;
15712 image_create_info.extent.height = 32;
15713 image_create_info.extent.depth = 1;
15714 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015715 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15719 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015722 ASSERT_VK_SUCCESS(err);
15723
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015724 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015725 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015726 ASSERT_VK_SUCCESS(err);
15727
15728 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015729 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015730 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15731 memAlloc.pNext = NULL;
15732 memAlloc.allocationSize = 0;
15733 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015734
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015735 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015736 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015738 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015739 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015740 ASSERT_VK_SUCCESS(err);
15741
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015742 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015743 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015745 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015746 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015747 ASSERT_VK_SUCCESS(err);
15748
15749 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15750 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015751 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015752 ASSERT_VK_SUCCESS(err);
15753
Tony Barbour552f6c02016-12-21 14:34:07 -070015754 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015755 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015756 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015757 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015758 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015759 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015760 copyRegion.srcOffset.x = 0;
15761 copyRegion.srcOffset.y = 0;
15762 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015763 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015764 copyRegion.dstSubresource.mipLevel = 0;
15765 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015766 // Introduce failure by forcing the dst layerCount to differ from src
15767 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015768 copyRegion.dstOffset.x = 0;
15769 copyRegion.dstOffset.y = 0;
15770 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015771 copyRegion.extent.width = 1;
15772 copyRegion.extent.height = 1;
15773 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015774 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015775 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015777 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015778
Chia-I Wuf7458c52015-10-26 21:10:41 +080015779 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015780 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015781 vkFreeMemory(m_device->device(), srcMem, NULL);
15782 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015783}
15784
Tony Barbourd6673642016-05-05 14:46:39 -060015785TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015786 TEST_DESCRIPTION("Creating images with unsuported formats ");
15787
15788 ASSERT_NO_FATAL_FAILURE(InitState());
15789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15790 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015791 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 -060015792 VK_IMAGE_TILING_OPTIMAL, 0);
15793 ASSERT_TRUE(image.initialized());
15794
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015795 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015796 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015797 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015798 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15799 image_create_info.format = VK_FORMAT_UNDEFINED;
15800 image_create_info.extent.width = 32;
15801 image_create_info.extent.height = 32;
15802 image_create_info.extent.depth = 1;
15803 image_create_info.mipLevels = 1;
15804 image_create_info.arrayLayers = 1;
15805 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15806 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15807 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15810 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015811
15812 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015813 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15814 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15815 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15816 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15818 m_errorMonitor->VerifyFound();
15819
Tony Barbourd6673642016-05-05 14:46:39 -060015820 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015821 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015822 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15823 VkFormat format = static_cast<VkFormat>(f);
15824 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015825 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015826 unsupported = format;
15827 break;
15828 }
15829 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015830
Tony Barbourd6673642016-05-05 14:46:39 -060015831 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015832 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015834
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015835 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15836 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15837 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15838 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15839 m_errorMonitor->SetUnexpectedError(
15840 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15841 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15842 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015843 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015844 m_errorMonitor->VerifyFound();
15845 }
15846}
15847
15848TEST_F(VkLayerTest, ImageLayerViewTests) {
15849 VkResult ret;
15850 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15851
15852 ASSERT_NO_FATAL_FAILURE(InitState());
15853
15854 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 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 -060015856 VK_IMAGE_TILING_OPTIMAL, 0);
15857 ASSERT_TRUE(image.initialized());
15858
15859 VkImageView imgView;
15860 VkImageViewCreateInfo imgViewInfo = {};
15861 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15862 imgViewInfo.image = image.handle();
15863 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15864 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15865 imgViewInfo.subresourceRange.layerCount = 1;
15866 imgViewInfo.subresourceRange.baseMipLevel = 0;
15867 imgViewInfo.subresourceRange.levelCount = 1;
15868 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15869
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015871 // View can't have baseMipLevel >= image's mipLevels - Expect
15872 // VIEW_CREATE_ERROR
15873 imgViewInfo.subresourceRange.baseMipLevel = 1;
15874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15875 m_errorMonitor->VerifyFound();
15876 imgViewInfo.subresourceRange.baseMipLevel = 0;
15877
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015879 // View can't have baseArrayLayer >= image's arraySize - Expect
15880 // VIEW_CREATE_ERROR
15881 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15883 m_errorMonitor->VerifyFound();
15884 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15885
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015887 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15888 imgViewInfo.subresourceRange.levelCount = 0;
15889 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15890 m_errorMonitor->VerifyFound();
15891 imgViewInfo.subresourceRange.levelCount = 1;
15892
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015893 m_errorMonitor->SetDesiredFailureMsg(
15894 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15895 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015896 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15897 imgViewInfo.subresourceRange.layerCount = 0;
15898 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15899 m_errorMonitor->VerifyFound();
15900 imgViewInfo.subresourceRange.layerCount = 1;
15901
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15903 "Formats MUST be IDENTICAL unless "
15904 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15905 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015906 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15907 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15908 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15909 m_errorMonitor->VerifyFound();
15910 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15911
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015913 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15914 // VIEW_CREATE_ERROR
15915 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15916 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15917 m_errorMonitor->VerifyFound();
15918 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15919
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015921 // TODO: Update framework to easily passing mutable flag into ImageObj init
15922 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015923 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15924 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15925 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015926 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15927 // VIEW_CREATE_ERROR
15928 VkImageCreateInfo mutImgInfo = image.create_info();
15929 VkImage mutImage;
15930 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015931 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015932 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15933 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15934 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15935 ASSERT_VK_SUCCESS(ret);
15936 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015937 m_errorMonitor->SetUnexpectedError(
15938 "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 -060015939 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15940 m_errorMonitor->VerifyFound();
15941 imgViewInfo.image = image.handle();
15942 vkDestroyImage(m_device->handle(), mutImage, NULL);
15943}
15944
Dave Houlton59a20702017-02-02 17:26:23 -070015945TEST_F(VkLayerTest, ImageBufferCopyTests) {
15946 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15947
15948 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015949
15950 // Bail if any dimension of transfer granularity is 0.
15951 auto index = m_device->graphics_queue_node_index_;
15952 auto queue_family_properties = m_device->phy().queue_properties();
15953 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15954 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15955 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15956 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15957 return;
15958 }
15959
Dave Houlton59a20702017-02-02 17:26:23 -070015960 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15961 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15962 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015963 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15964 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15965 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15966 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15967
Dave Houlton59a20702017-02-02 17:26:23 -070015968 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15969 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15970 VK_IMAGE_TILING_OPTIMAL, 0);
15971 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15972 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15973 VK_IMAGE_TILING_OPTIMAL, 0);
15974 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15975 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015976 ASSERT_TRUE(image_64k.initialized());
15977 ASSERT_TRUE(image_16k.initialized());
15978 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015979
Dave Houltonf3229d52017-02-21 15:59:08 -070015980 // Verify all needed Depth/Stencil formats are supported
15981 bool missing_ds_support = false;
15982 VkFormatProperties props = {0, 0, 0};
15983 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15984 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15985 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15986 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15987 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15988 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15989 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15990 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15991
15992 if (!missing_ds_support) {
15993 ds_image_4D_1S.init(
15994 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
15995 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15996 VK_IMAGE_TILING_OPTIMAL, 0);
15997 ASSERT_TRUE(ds_image_4D_1S.initialized());
15998
15999 ds_image_3D_1S.init(
16000 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16001 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16002 VK_IMAGE_TILING_OPTIMAL, 0);
16003 ASSERT_TRUE(ds_image_3D_1S.initialized());
16004
16005 ds_image_2D.init(
16006 256, 256, VK_FORMAT_D16_UNORM,
16007 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16008 VK_IMAGE_TILING_OPTIMAL, 0);
16009 ASSERT_TRUE(ds_image_2D.initialized());
16010
16011 ds_image_1S.init(
16012 256, 256, VK_FORMAT_S8_UINT,
16013 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16014 VK_IMAGE_TILING_OPTIMAL, 0);
16015 ASSERT_TRUE(ds_image_1S.initialized());
16016 }
16017
16018 // Allocate buffers
16019 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016020 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016021 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16022 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16023 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16024 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016025
16026 VkBufferImageCopy region = {};
16027 region.bufferRowLength = 0;
16028 region.bufferImageHeight = 0;
16029 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16030 region.imageSubresource.layerCount = 1;
16031 region.imageOffset = {0, 0, 0};
16032 region.imageExtent = {64, 64, 1};
16033 region.bufferOffset = 0;
16034
16035 // attempt copies before putting command buffer in recording state
16036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16037 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16038 &region);
16039 m_errorMonitor->VerifyFound();
16040
16041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16042 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16043 &region);
16044 m_errorMonitor->VerifyFound();
16045
16046 // start recording
16047 m_commandBuffer->BeginCommandBuffer();
16048
16049 // successful copies
16050 m_errorMonitor->ExpectSuccess();
16051 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16052 &region);
16053 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16054 &region);
16055 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16056 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16057 &region);
16058 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16059 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16060 &region);
16061 region.imageOffset.x = 0;
16062 region.imageExtent.height = 64;
16063 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16064 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16065 &region);
16066 m_errorMonitor->VerifyNotFound();
16067
16068 // image/buffer too small (extent) on copy to image
16069 region.imageExtent = {65, 64, 1};
16070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16071 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16072 &region);
16073 m_errorMonitor->VerifyFound();
16074
16075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16076 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16077 &region);
16078 m_errorMonitor->VerifyFound();
16079
16080 // image/buffer too small (offset) on copy to image
16081 region.imageExtent = {64, 64, 1};
16082 region.imageOffset = {0, 4, 0};
16083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16084 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16085 &region);
16086 m_errorMonitor->VerifyFound();
16087
16088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16089 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16090 &region);
16091 m_errorMonitor->VerifyFound();
16092
16093 // image/buffer too small on copy to buffer
16094 region.imageExtent = {64, 64, 1};
16095 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016096 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16098 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16099 &region);
16100 m_errorMonitor->VerifyFound();
16101
16102 region.imageExtent = {64, 65, 1};
16103 region.bufferOffset = 0;
16104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16105 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16106 &region);
16107 m_errorMonitor->VerifyFound();
16108
16109 // buffer size ok but rowlength causes loose packing
16110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16111 region.imageExtent = {64, 64, 1};
16112 region.bufferRowLength = 68;
16113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16114 &region);
16115 m_errorMonitor->VerifyFound();
16116
Dave Houlton59a20702017-02-02 17:26:23 -070016117 // aspect bits
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16119 region.imageExtent = {64, 64, 1};
16120 region.bufferRowLength = 0;
16121 region.bufferImageHeight = 0;
16122 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16123 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16124 buffer_16k.handle(), 1, &region);
16125 m_errorMonitor->VerifyFound();
16126
16127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16128 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16129 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16130 &region);
16131 m_errorMonitor->VerifyFound();
16132
16133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16134 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16135 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16136 buffer_16k.handle(), 1, &region);
16137 m_errorMonitor->VerifyFound();
16138
Dave Houltonf3229d52017-02-21 15:59:08 -070016139 // Test Depth/Stencil copies
16140 if (missing_ds_support) {
16141 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16142 } else {
16143 VkBufferImageCopy ds_region = {};
16144 ds_region.bufferOffset = 0;
16145 ds_region.bufferRowLength = 0;
16146 ds_region.bufferImageHeight = 0;
16147 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16148 ds_region.imageSubresource.mipLevel = 0;
16149 ds_region.imageSubresource.baseArrayLayer = 0;
16150 ds_region.imageSubresource.layerCount = 1;
16151 ds_region.imageOffset = {0, 0, 0};
16152 ds_region.imageExtent = {256, 256, 1};
16153
16154 // Depth copies that should succeed
16155 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16156 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16157 buffer_256k.handle(), 1, &ds_region);
16158 m_errorMonitor->VerifyNotFound();
16159
16160 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16161 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16162 buffer_256k.handle(), 1, &ds_region);
16163 m_errorMonitor->VerifyNotFound();
16164
16165 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16166 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16167 buffer_128k.handle(), 1, &ds_region);
16168 m_errorMonitor->VerifyNotFound();
16169
16170 // Depth copies that should fail
16171 ds_region.bufferOffset = 4;
16172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16173 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16174 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16175 buffer_256k.handle(), 1, &ds_region);
16176 m_errorMonitor->VerifyFound();
16177
16178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16179 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16180 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16181 buffer_256k.handle(), 1, &ds_region);
16182 m_errorMonitor->VerifyFound();
16183
16184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16185 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16186 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16187 buffer_128k.handle(), 1, &ds_region);
16188 m_errorMonitor->VerifyFound();
16189
16190 // Stencil copies that should succeed
16191 ds_region.bufferOffset = 0;
16192 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16193 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16194 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16195 buffer_64k.handle(), 1, &ds_region);
16196 m_errorMonitor->VerifyNotFound();
16197
16198 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16199 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16200 buffer_64k.handle(), 1, &ds_region);
16201 m_errorMonitor->VerifyNotFound();
16202
16203 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16204 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16205 buffer_64k.handle(), 1, &ds_region);
16206 m_errorMonitor->VerifyNotFound();
16207
16208 // Stencil copies that should fail
16209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16210 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16211 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16212 buffer_16k.handle(), 1, &ds_region);
16213 m_errorMonitor->VerifyFound();
16214
16215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16216 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16217 ds_region.bufferRowLength = 260;
16218 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16219 buffer_64k.handle(), 1, &ds_region);
16220 m_errorMonitor->VerifyFound();
16221
16222 ds_region.bufferRowLength = 0;
16223 ds_region.bufferOffset = 4;
16224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16225 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16226 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16227 buffer_64k.handle(), 1, &ds_region);
16228 m_errorMonitor->VerifyFound();
16229 }
16230
Dave Houlton584d51e2017-02-16 12:52:54 -070016231 // Test compressed formats, if supported
16232 VkPhysicalDeviceFeatures device_features;
16233 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016234 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16235 device_features.textureCompressionASTC_LDR)) {
16236 printf(" No compressed formats supported - block compression tests skipped.\n");
16237 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016238 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16239 if (device_features.textureCompressionBC) {
16240 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16241 } else if (device_features.textureCompressionETC2) {
16242 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16243 VK_IMAGE_TILING_OPTIMAL, 0);
16244 } else {
16245 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16246 0);
16247 }
16248 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016249
Dave Houlton584d51e2017-02-16 12:52:54 -070016250 // Just fits
16251 m_errorMonitor->ExpectSuccess();
16252 region.imageExtent = {128, 128, 1};
16253 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16254 buffer_16k.handle(), 1, &region);
16255 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016256
Dave Houlton584d51e2017-02-16 12:52:54 -070016257 // with offset, too big for buffer
16258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16259 region.bufferOffset = 16;
16260 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16261 buffer_16k.handle(), 1, &region);
16262 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016263
Dave Houlton584d51e2017-02-16 12:52:54 -070016264 // buffer offset must be a multiple of texel block size (16)
16265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16267 region.imageExtent = {64, 64, 1};
16268 region.bufferOffset = 24;
16269 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16270 buffer_16k.handle(), 1, &region);
16271 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016272
Dave Houlton584d51e2017-02-16 12:52:54 -070016273 // rowlength not a multiple of block width (4)
16274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16275 region.bufferOffset = 0;
16276 region.bufferRowLength = 130;
16277 region.bufferImageHeight = 0;
16278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16279 buffer_64k.handle(), 1, &region);
16280 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016281
Dave Houlton584d51e2017-02-16 12:52:54 -070016282 // imageheight not a multiple of block height (4)
16283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16284 region.bufferRowLength = 0;
16285 region.bufferImageHeight = 130;
16286 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16287 buffer_64k.handle(), 1, &region);
16288 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016289
Dave Houlton584d51e2017-02-16 12:52:54 -070016290 // image extents must be multiple of block dimensions (4x4)
16291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16292 region.bufferImageHeight = 0;
16293 region.imageOffset = {4, 6, 0};
16294 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16295 buffer_64k.handle(), 1, &region);
16296 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016297
Dave Houlton584d51e2017-02-16 12:52:54 -070016298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16299 region.imageOffset = {22, 0, 0};
16300 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16301 buffer_64k.handle(), 1, &region);
16302 m_errorMonitor->VerifyFound();
16303 }
Dave Houlton59a20702017-02-02 17:26:23 -070016304}
16305
Tony Barbourd6673642016-05-05 14:46:39 -060016306TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016307 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016308
16309 ASSERT_NO_FATAL_FAILURE(InitState());
16310
Rene Lindsay135204f2016-12-22 17:11:09 -070016311 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016312 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016313 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 -070016314 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016315 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016316 vk_testing::Buffer buffer;
16317 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016318 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016319 VkBufferImageCopy region = {};
16320 region.bufferRowLength = 128;
16321 region.bufferImageHeight = 128;
16322 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16323 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016324 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016325 region.imageExtent.height = 4;
16326 region.imageExtent.width = 4;
16327 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016328
16329 VkImageObj image2(m_device);
16330 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 -070016331 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016332 ASSERT_TRUE(image2.initialized());
16333 vk_testing::Buffer buffer2;
16334 VkMemoryPropertyFlags reqs2 = 0;
16335 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16336 VkBufferImageCopy region2 = {};
16337 region2.bufferRowLength = 128;
16338 region2.bufferImageHeight = 128;
16339 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16340 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16341 region2.imageSubresource.layerCount = 1;
16342 region2.imageExtent.height = 4;
16343 region2.imageExtent.width = 4;
16344 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016345 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016346
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016347 // Image must have offset.z of 0 and extent.depth of 1
16348 // Introduce failure by setting imageExtent.depth to 0
16349 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016351 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016352 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016353 m_errorMonitor->VerifyFound();
16354
16355 region.imageExtent.depth = 1;
16356
16357 // Image must have offset.z of 0 and extent.depth of 1
16358 // Introduce failure by setting imageOffset.z to 4
16359 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016361 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016362 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016363 m_errorMonitor->VerifyFound();
16364
16365 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016366 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16367 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016368 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016370 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16371 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016372 m_errorMonitor->VerifyFound();
16373
16374 // BufferOffset must be a multiple of 4
16375 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016376 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016378 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16379 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016380 m_errorMonitor->VerifyFound();
16381
16382 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16383 region.bufferOffset = 0;
16384 region.imageExtent.height = 128;
16385 region.imageExtent.width = 128;
16386 // Introduce failure by setting bufferRowLength > 0 but less than width
16387 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016389 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16390 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016391 m_errorMonitor->VerifyFound();
16392
16393 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16394 region.bufferRowLength = 128;
16395 // Introduce failure by setting bufferRowHeight > 0 but less than height
16396 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016398 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16399 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016400 m_errorMonitor->VerifyFound();
16401
16402 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016403 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016404 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16405 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016406 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016407 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16408 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016409 VkImageBlit blitRegion = {};
16410 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16411 blitRegion.srcSubresource.baseArrayLayer = 0;
16412 blitRegion.srcSubresource.layerCount = 1;
16413 blitRegion.srcSubresource.mipLevel = 0;
16414 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16415 blitRegion.dstSubresource.baseArrayLayer = 0;
16416 blitRegion.dstSubresource.layerCount = 1;
16417 blitRegion.dstSubresource.mipLevel = 0;
16418
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016419 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016421 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016422 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16423 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016424 m_errorMonitor->VerifyFound();
16425
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016427 VkImageMemoryBarrier img_barrier;
16428 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16429 img_barrier.pNext = NULL;
16430 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16431 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16432 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16433 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16434 img_barrier.image = image.handle();
16435 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16436 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16437 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16438 img_barrier.subresourceRange.baseArrayLayer = 0;
16439 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016440 img_barrier.subresourceRange.layerCount = 0;
16441 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016442 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16443 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016444 m_errorMonitor->VerifyFound();
16445 img_barrier.subresourceRange.layerCount = 1;
16446}
16447
16448TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016449 TEST_DESCRIPTION("Exceed the limits of image format ");
16450
Cody Northropc31a84f2016-08-22 10:41:47 -060016451 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016453 VkImageCreateInfo image_create_info = {};
16454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16455 image_create_info.pNext = NULL;
16456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16457 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16458 image_create_info.extent.width = 32;
16459 image_create_info.extent.height = 32;
16460 image_create_info.extent.depth = 1;
16461 image_create_info.mipLevels = 1;
16462 image_create_info.arrayLayers = 1;
16463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16464 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16465 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16466 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16467 image_create_info.flags = 0;
16468
16469 VkImage nullImg;
16470 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016471 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16472 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016473 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016474 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16475 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16476 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016477 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016480 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16481 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16482 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16483 m_errorMonitor->VerifyFound();
16484 image_create_info.mipLevels = 1;
16485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016487 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16488 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16489 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16490 m_errorMonitor->VerifyFound();
16491 image_create_info.arrayLayers = 1;
16492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016494 int samples = imgFmtProps.sampleCounts >> 1;
16495 image_create_info.samples = (VkSampleCountFlagBits)samples;
16496 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16497 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16498 m_errorMonitor->VerifyFound();
16499 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16500
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16502 "pCreateInfo->initialLayout, must be "
16503 "VK_IMAGE_LAYOUT_UNDEFINED or "
16504 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016505 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16506 // Expect INVALID_LAYOUT
16507 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16508 m_errorMonitor->VerifyFound();
16509 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16510}
16511
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016512TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016513 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016515
16516 ASSERT_NO_FATAL_FAILURE(InitState());
16517
16518 VkImageObj src_image(m_device);
16519 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16520 VkImageObj dst_image(m_device);
16521 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16522
Tony Barbour552f6c02016-12-21 14:34:07 -070016523 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016524 VkImageCopy copy_region;
16525 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16526 copy_region.srcSubresource.mipLevel = 0;
16527 copy_region.srcSubresource.baseArrayLayer = 0;
16528 copy_region.srcSubresource.layerCount = 0;
16529 copy_region.srcOffset.x = 0;
16530 copy_region.srcOffset.y = 0;
16531 copy_region.srcOffset.z = 0;
16532 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16533 copy_region.dstSubresource.mipLevel = 0;
16534 copy_region.dstSubresource.baseArrayLayer = 0;
16535 copy_region.dstSubresource.layerCount = 0;
16536 copy_region.dstOffset.x = 0;
16537 copy_region.dstOffset.y = 0;
16538 copy_region.dstOffset.z = 0;
16539 copy_region.extent.width = 64;
16540 copy_region.extent.height = 64;
16541 copy_region.extent.depth = 1;
16542 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16543 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016544 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016545
16546 m_errorMonitor->VerifyFound();
16547}
16548
16549TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016550 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016552
16553 ASSERT_NO_FATAL_FAILURE(InitState());
16554
16555 VkImageObj src_image(m_device);
16556 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16557 VkImageObj dst_image(m_device);
16558 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16559
Tony Barbour552f6c02016-12-21 14:34:07 -070016560 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016561 VkImageCopy copy_region;
16562 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16563 copy_region.srcSubresource.mipLevel = 0;
16564 copy_region.srcSubresource.baseArrayLayer = 0;
16565 copy_region.srcSubresource.layerCount = 0;
16566 copy_region.srcOffset.x = 0;
16567 copy_region.srcOffset.y = 0;
16568 copy_region.srcOffset.z = 0;
16569 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16570 copy_region.dstSubresource.mipLevel = 0;
16571 copy_region.dstSubresource.baseArrayLayer = 0;
16572 copy_region.dstSubresource.layerCount = 0;
16573 copy_region.dstOffset.x = 0;
16574 copy_region.dstOffset.y = 0;
16575 copy_region.dstOffset.z = 0;
16576 copy_region.extent.width = 64;
16577 copy_region.extent.height = 64;
16578 copy_region.extent.depth = 1;
16579 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16580 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016581 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016582
16583 m_errorMonitor->VerifyFound();
16584}
16585
Karl Schultz6addd812016-02-02 17:17:23 -070016586TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016587 VkResult err;
16588 bool pass;
16589
16590 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016592
16593 ASSERT_NO_FATAL_FAILURE(InitState());
16594
16595 // Create two images of different types and try to copy between them
16596 VkImage srcImage;
16597 VkImage dstImage;
16598 VkDeviceMemory srcMem;
16599 VkDeviceMemory destMem;
16600 VkMemoryRequirements memReqs;
16601
16602 VkImageCreateInfo image_create_info = {};
16603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16604 image_create_info.pNext = NULL;
16605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16606 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16607 image_create_info.extent.width = 32;
16608 image_create_info.extent.height = 32;
16609 image_create_info.extent.depth = 1;
16610 image_create_info.mipLevels = 1;
16611 image_create_info.arrayLayers = 1;
16612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16613 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16614 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16615 image_create_info.flags = 0;
16616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016617 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016618 ASSERT_VK_SUCCESS(err);
16619
16620 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16621 // Introduce failure by creating second image with a different-sized format.
16622 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016625 ASSERT_VK_SUCCESS(err);
16626
16627 // Allocate memory
16628 VkMemoryAllocateInfo memAlloc = {};
16629 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16630 memAlloc.pNext = NULL;
16631 memAlloc.allocationSize = 0;
16632 memAlloc.memoryTypeIndex = 0;
16633
16634 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16635 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016636 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016637 ASSERT_TRUE(pass);
16638 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16639 ASSERT_VK_SUCCESS(err);
16640
16641 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16642 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016643 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016644 ASSERT_TRUE(pass);
16645 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16646 ASSERT_VK_SUCCESS(err);
16647
16648 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16649 ASSERT_VK_SUCCESS(err);
16650 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16651 ASSERT_VK_SUCCESS(err);
16652
Tony Barbour552f6c02016-12-21 14:34:07 -070016653 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016654 VkImageCopy copyRegion;
16655 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16656 copyRegion.srcSubresource.mipLevel = 0;
16657 copyRegion.srcSubresource.baseArrayLayer = 0;
16658 copyRegion.srcSubresource.layerCount = 0;
16659 copyRegion.srcOffset.x = 0;
16660 copyRegion.srcOffset.y = 0;
16661 copyRegion.srcOffset.z = 0;
16662 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16663 copyRegion.dstSubresource.mipLevel = 0;
16664 copyRegion.dstSubresource.baseArrayLayer = 0;
16665 copyRegion.dstSubresource.layerCount = 0;
16666 copyRegion.dstOffset.x = 0;
16667 copyRegion.dstOffset.y = 0;
16668 copyRegion.dstOffset.z = 0;
16669 copyRegion.extent.width = 1;
16670 copyRegion.extent.height = 1;
16671 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016673 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016674
16675 m_errorMonitor->VerifyFound();
16676
16677 vkDestroyImage(m_device->device(), srcImage, NULL);
16678 vkDestroyImage(m_device->device(), dstImage, NULL);
16679 vkFreeMemory(m_device->device(), srcMem, NULL);
16680 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016681}
16682
Karl Schultz6addd812016-02-02 17:17:23 -070016683TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16684 VkResult err;
16685 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016686
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016687 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16689 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016690
Mike Stroyana3082432015-09-25 13:39:21 -060016691 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016692
16693 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016694 VkImage srcImage;
16695 VkImage dstImage;
16696 VkDeviceMemory srcMem;
16697 VkDeviceMemory destMem;
16698 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016699
16700 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016701 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16702 image_create_info.pNext = NULL;
16703 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16704 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16705 image_create_info.extent.width = 32;
16706 image_create_info.extent.height = 32;
16707 image_create_info.extent.depth = 1;
16708 image_create_info.mipLevels = 1;
16709 image_create_info.arrayLayers = 1;
16710 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16711 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16712 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16713 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016715 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016716 ASSERT_VK_SUCCESS(err);
16717
Karl Schultzbdb75952016-04-19 11:36:49 -060016718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16719
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016720 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016721 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016722 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016725 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016726 ASSERT_VK_SUCCESS(err);
16727
16728 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016729 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016730 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16731 memAlloc.pNext = NULL;
16732 memAlloc.allocationSize = 0;
16733 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016734
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016735 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016736 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016737 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016738 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016739 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016740 ASSERT_VK_SUCCESS(err);
16741
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016742 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016743 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016744 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016745 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016746 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016747 ASSERT_VK_SUCCESS(err);
16748
16749 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16750 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016751 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016752 ASSERT_VK_SUCCESS(err);
16753
Tony Barbour552f6c02016-12-21 14:34:07 -070016754 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016755 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016756 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016757 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016758 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016759 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016760 copyRegion.srcOffset.x = 0;
16761 copyRegion.srcOffset.y = 0;
16762 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016763 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016764 copyRegion.dstSubresource.mipLevel = 0;
16765 copyRegion.dstSubresource.baseArrayLayer = 0;
16766 copyRegion.dstSubresource.layerCount = 0;
16767 copyRegion.dstOffset.x = 0;
16768 copyRegion.dstOffset.y = 0;
16769 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016770 copyRegion.extent.width = 1;
16771 copyRegion.extent.height = 1;
16772 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016773 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016774 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016775
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016776 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016777
Chia-I Wuf7458c52015-10-26 21:10:41 +080016778 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016779 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016780 vkFreeMemory(m_device->device(), srcMem, NULL);
16781 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016782}
16783
Karl Schultz6addd812016-02-02 17:17:23 -070016784TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16785 VkResult err;
16786 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16789 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016790
Mike Stroyana3082432015-09-25 13:39:21 -060016791 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016792
16793 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016794 VkImage srcImage;
16795 VkImage dstImage;
16796 VkDeviceMemory srcMem;
16797 VkDeviceMemory destMem;
16798 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016799
16800 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016801 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16802 image_create_info.pNext = NULL;
16803 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16804 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16805 image_create_info.extent.width = 32;
16806 image_create_info.extent.height = 1;
16807 image_create_info.extent.depth = 1;
16808 image_create_info.mipLevels = 1;
16809 image_create_info.arrayLayers = 1;
16810 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16811 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16812 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16813 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016815 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016816 ASSERT_VK_SUCCESS(err);
16817
Karl Schultz6addd812016-02-02 17:17:23 -070016818 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016820 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016821 ASSERT_VK_SUCCESS(err);
16822
16823 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016824 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016825 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16826 memAlloc.pNext = NULL;
16827 memAlloc.allocationSize = 0;
16828 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016829
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016830 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016831 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016832 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016833 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016834 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016835 ASSERT_VK_SUCCESS(err);
16836
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016837 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016838 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016839 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016840 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016841 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016842 ASSERT_VK_SUCCESS(err);
16843
16844 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16845 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016846 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016847 ASSERT_VK_SUCCESS(err);
16848
Tony Barbour552f6c02016-12-21 14:34:07 -070016849 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016850 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016851 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16852 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016853 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016854 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016855 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016856 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016857 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016858 resolveRegion.srcOffset.x = 0;
16859 resolveRegion.srcOffset.y = 0;
16860 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016861 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016862 resolveRegion.dstSubresource.mipLevel = 0;
16863 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016864 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016865 resolveRegion.dstOffset.x = 0;
16866 resolveRegion.dstOffset.y = 0;
16867 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016868 resolveRegion.extent.width = 1;
16869 resolveRegion.extent.height = 1;
16870 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016871 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016872 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016873
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016874 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016875
Chia-I Wuf7458c52015-10-26 21:10:41 +080016876 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016877 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016878 vkFreeMemory(m_device->device(), srcMem, NULL);
16879 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016880}
16881
Karl Schultz6addd812016-02-02 17:17:23 -070016882TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16883 VkResult err;
16884 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16887 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016888
Mike Stroyana3082432015-09-25 13:39:21 -060016889 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016890
Chris Forbesa7530692016-05-08 12:35:39 +120016891 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016892 VkImage srcImage;
16893 VkImage dstImage;
16894 VkDeviceMemory srcMem;
16895 VkDeviceMemory destMem;
16896 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016897
16898 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016899 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16900 image_create_info.pNext = NULL;
16901 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16902 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16903 image_create_info.extent.width = 32;
16904 image_create_info.extent.height = 1;
16905 image_create_info.extent.depth = 1;
16906 image_create_info.mipLevels = 1;
16907 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016908 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016909 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16910 // Note: Some implementations expect color attachment usage for any
16911 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016912 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016913 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016916 ASSERT_VK_SUCCESS(err);
16917
Karl Schultz6addd812016-02-02 17:17:23 -070016918 // Note: Some implementations expect color attachment usage for any
16919 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016920 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016922 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016923 ASSERT_VK_SUCCESS(err);
16924
16925 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016926 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016927 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16928 memAlloc.pNext = NULL;
16929 memAlloc.allocationSize = 0;
16930 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016931
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016932 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016933 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016934 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016935 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016936 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016937 ASSERT_VK_SUCCESS(err);
16938
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016939 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016940 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016941 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016942 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016943 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016944 ASSERT_VK_SUCCESS(err);
16945
16946 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16947 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016948 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016949 ASSERT_VK_SUCCESS(err);
16950
Tony Barbour552f6c02016-12-21 14:34:07 -070016951 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016952 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016953 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16954 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016955 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016956 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016957 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016958 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016959 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016960 resolveRegion.srcOffset.x = 0;
16961 resolveRegion.srcOffset.y = 0;
16962 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016963 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016964 resolveRegion.dstSubresource.mipLevel = 0;
16965 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016966 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016967 resolveRegion.dstOffset.x = 0;
16968 resolveRegion.dstOffset.y = 0;
16969 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016970 resolveRegion.extent.width = 1;
16971 resolveRegion.extent.height = 1;
16972 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016973 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016974 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016975
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016976 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016977
Chia-I Wuf7458c52015-10-26 21:10:41 +080016978 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016979 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016980 vkFreeMemory(m_device->device(), srcMem, NULL);
16981 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016982}
16983
Karl Schultz6addd812016-02-02 17:17:23 -070016984TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16985 VkResult err;
16986 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016987
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016989 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016990
Mike Stroyana3082432015-09-25 13:39:21 -060016991 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016992
16993 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016994 VkImage srcImage;
16995 VkImage dstImage;
16996 VkDeviceMemory srcMem;
16997 VkDeviceMemory destMem;
16998 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016999
17000 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017001 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17002 image_create_info.pNext = NULL;
17003 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17004 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17005 image_create_info.extent.width = 32;
17006 image_create_info.extent.height = 1;
17007 image_create_info.extent.depth = 1;
17008 image_create_info.mipLevels = 1;
17009 image_create_info.arrayLayers = 1;
17010 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17011 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17012 // Note: Some implementations expect color attachment usage for any
17013 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017014 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017015 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017018 ASSERT_VK_SUCCESS(err);
17019
Karl Schultz6addd812016-02-02 17:17:23 -070017020 // Set format to something other than source image
17021 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17022 // Note: Some implementations expect color attachment usage for any
17023 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017025 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017027 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017028 ASSERT_VK_SUCCESS(err);
17029
17030 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017031 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017032 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17033 memAlloc.pNext = NULL;
17034 memAlloc.allocationSize = 0;
17035 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017036
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017037 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017038 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017039 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017040 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017041 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017042 ASSERT_VK_SUCCESS(err);
17043
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017044 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017045 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017046 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017047 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017048 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017049 ASSERT_VK_SUCCESS(err);
17050
17051 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17052 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017053 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017054 ASSERT_VK_SUCCESS(err);
17055
Tony Barbour552f6c02016-12-21 14:34:07 -070017056 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017057 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017058 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17059 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017060 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017061 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017062 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017063 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017064 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017065 resolveRegion.srcOffset.x = 0;
17066 resolveRegion.srcOffset.y = 0;
17067 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017068 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017069 resolveRegion.dstSubresource.mipLevel = 0;
17070 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017071 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017072 resolveRegion.dstOffset.x = 0;
17073 resolveRegion.dstOffset.y = 0;
17074 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017075 resolveRegion.extent.width = 1;
17076 resolveRegion.extent.height = 1;
17077 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017078 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017079 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017081 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017082
Chia-I Wuf7458c52015-10-26 21:10:41 +080017083 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017084 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017085 vkFreeMemory(m_device->device(), srcMem, NULL);
17086 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017087}
17088
Karl Schultz6addd812016-02-02 17:17:23 -070017089TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17090 VkResult err;
17091 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017092
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017094 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017095
Mike Stroyana3082432015-09-25 13:39:21 -060017096 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017097
17098 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017099 VkImage srcImage;
17100 VkImage dstImage;
17101 VkDeviceMemory srcMem;
17102 VkDeviceMemory destMem;
17103 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017104
17105 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017106 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17107 image_create_info.pNext = NULL;
17108 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17109 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17110 image_create_info.extent.width = 32;
17111 image_create_info.extent.height = 1;
17112 image_create_info.extent.depth = 1;
17113 image_create_info.mipLevels = 1;
17114 image_create_info.arrayLayers = 1;
17115 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17116 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17117 // Note: Some implementations expect color attachment usage for any
17118 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017119 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017120 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017122 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017123 ASSERT_VK_SUCCESS(err);
17124
Karl Schultz6addd812016-02-02 17:17:23 -070017125 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17126 // Note: Some implementations expect color attachment usage for any
17127 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017132 ASSERT_VK_SUCCESS(err);
17133
17134 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017135 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017136 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17137 memAlloc.pNext = NULL;
17138 memAlloc.allocationSize = 0;
17139 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017140
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017141 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017142 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017143 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017144 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017145 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017146 ASSERT_VK_SUCCESS(err);
17147
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017148 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017149 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017150 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017151 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017152 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017153 ASSERT_VK_SUCCESS(err);
17154
17155 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17156 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017157 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017158 ASSERT_VK_SUCCESS(err);
17159
Tony Barbour552f6c02016-12-21 14:34:07 -070017160 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017161 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017162 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17163 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017164 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017165 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017166 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017167 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017168 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017169 resolveRegion.srcOffset.x = 0;
17170 resolveRegion.srcOffset.y = 0;
17171 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017172 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017173 resolveRegion.dstSubresource.mipLevel = 0;
17174 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017175 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017176 resolveRegion.dstOffset.x = 0;
17177 resolveRegion.dstOffset.y = 0;
17178 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017179 resolveRegion.extent.width = 1;
17180 resolveRegion.extent.height = 1;
17181 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017182 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017183 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017184
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017185 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017186
Chia-I Wuf7458c52015-10-26 21:10:41 +080017187 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017188 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017189 vkFreeMemory(m_device->device(), srcMem, NULL);
17190 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017191}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017192
Karl Schultz6addd812016-02-02 17:17:23 -070017193TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017194 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017195 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17196 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017197 // The image format check comes 2nd in validation so we trigger it first,
17198 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017199 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017200
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17202 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017203
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017204 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017205
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017206 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017207 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17208 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017209
17210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17212 ds_pool_ci.pNext = NULL;
17213 ds_pool_ci.maxSets = 1;
17214 ds_pool_ci.poolSizeCount = 1;
17215 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017216
17217 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017218 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017219 ASSERT_VK_SUCCESS(err);
17220
17221 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017222 dsl_binding.binding = 0;
17223 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17224 dsl_binding.descriptorCount = 1;
17225 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17226 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017227
17228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17230 ds_layout_ci.pNext = NULL;
17231 ds_layout_ci.bindingCount = 1;
17232 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017233 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017235 ASSERT_VK_SUCCESS(err);
17236
17237 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017238 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017240 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017241 alloc_info.descriptorPool = ds_pool;
17242 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017244 ASSERT_VK_SUCCESS(err);
17245
Karl Schultz6addd812016-02-02 17:17:23 -070017246 VkImage image_bad;
17247 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017248 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017249 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017250 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017251 const int32_t tex_width = 32;
17252 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017253
17254 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017255 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17256 image_create_info.pNext = NULL;
17257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17258 image_create_info.format = tex_format_bad;
17259 image_create_info.extent.width = tex_width;
17260 image_create_info.extent.height = tex_height;
17261 image_create_info.extent.depth = 1;
17262 image_create_info.mipLevels = 1;
17263 image_create_info.arrayLayers = 1;
17264 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17265 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017266 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017267 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017269 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017270 ASSERT_VK_SUCCESS(err);
17271 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017272 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17273 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017274 ASSERT_VK_SUCCESS(err);
17275
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017276 // ---Bind image memory---
17277 VkMemoryRequirements img_mem_reqs;
17278 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17279 VkMemoryAllocateInfo image_alloc_info = {};
17280 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17281 image_alloc_info.pNext = NULL;
17282 image_alloc_info.memoryTypeIndex = 0;
17283 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017284 bool pass =
17285 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 -070017286 ASSERT_TRUE(pass);
17287 VkDeviceMemory mem;
17288 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17289 ASSERT_VK_SUCCESS(err);
17290 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17291 ASSERT_VK_SUCCESS(err);
17292 // -----------------------
17293
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017294 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017295 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017296 image_view_create_info.image = image_bad;
17297 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17298 image_view_create_info.format = tex_format_bad;
17299 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17300 image_view_create_info.subresourceRange.baseMipLevel = 0;
17301 image_view_create_info.subresourceRange.layerCount = 1;
17302 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017303 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017304
17305 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017306 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017308 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017309
Chia-I Wuf7458c52015-10-26 21:10:41 +080017310 vkDestroyImage(m_device->device(), image_bad, NULL);
17311 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017312 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17313 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017314
17315 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017316}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017317
17318TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017319 TEST_DESCRIPTION(
17320 "Call ClearColorImage w/ a depth|stencil image and "
17321 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017322
17323 ASSERT_NO_FATAL_FAILURE(InitState());
17324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17325
Tony Barbour552f6c02016-12-21 14:34:07 -070017326 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017327
17328 // Color image
17329 VkClearColorValue clear_color;
17330 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17331 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17332 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17333 const int32_t img_width = 32;
17334 const int32_t img_height = 32;
17335 VkImageCreateInfo image_create_info = {};
17336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17337 image_create_info.pNext = NULL;
17338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17339 image_create_info.format = color_format;
17340 image_create_info.extent.width = img_width;
17341 image_create_info.extent.height = img_height;
17342 image_create_info.extent.depth = 1;
17343 image_create_info.mipLevels = 1;
17344 image_create_info.arrayLayers = 1;
17345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17348
17349 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017350 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017352 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017353
17354 // Depth/Stencil image
17355 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017356 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017357 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17358 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17359 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17360 ds_image_create_info.extent.width = 64;
17361 ds_image_create_info.extent.height = 64;
17362 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017363 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 -060017364
17365 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017366 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017368 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 -060017369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017372 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017373 &color_range);
17374
17375 m_errorMonitor->VerifyFound();
17376
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17378 "vkCmdClearColorImage called with "
17379 "image created without "
17380 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017381
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017382 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017383 &color_range);
17384
17385 m_errorMonitor->VerifyFound();
17386
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017387 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17389 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017390
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017391 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17392 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017393
17394 m_errorMonitor->VerifyFound();
17395}
Tobin Ehliscde08892015-09-22 10:11:37 -060017396
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017397// WSI Enabled Tests
17398//
Chris Forbes09368e42016-10-13 11:59:22 +130017399#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017400TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17401
17402#if defined(VK_USE_PLATFORM_XCB_KHR)
17403 VkSurfaceKHR surface = VK_NULL_HANDLE;
17404
17405 VkResult err;
17406 bool pass;
17407 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17408 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17409 // uint32_t swapchain_image_count = 0;
17410 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17411 // uint32_t image_index = 0;
17412 // VkPresentInfoKHR present_info = {};
17413
17414 ASSERT_NO_FATAL_FAILURE(InitState());
17415
17416 // Use the create function from one of the VK_KHR_*_surface extension in
17417 // order to create a surface, testing all known errors in the process,
17418 // before successfully creating a surface:
17419 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17421 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17422 pass = (err != VK_SUCCESS);
17423 ASSERT_TRUE(pass);
17424 m_errorMonitor->VerifyFound();
17425
17426 // Next, try to create a surface with the wrong
17427 // VkXcbSurfaceCreateInfoKHR::sType:
17428 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17429 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17431 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17432 pass = (err != VK_SUCCESS);
17433 ASSERT_TRUE(pass);
17434 m_errorMonitor->VerifyFound();
17435
17436 // Create a native window, and then correctly create a surface:
17437 xcb_connection_t *connection;
17438 xcb_screen_t *screen;
17439 xcb_window_t xcb_window;
17440 xcb_intern_atom_reply_t *atom_wm_delete_window;
17441
17442 const xcb_setup_t *setup;
17443 xcb_screen_iterator_t iter;
17444 int scr;
17445 uint32_t value_mask, value_list[32];
17446 int width = 1;
17447 int height = 1;
17448
17449 connection = xcb_connect(NULL, &scr);
17450 ASSERT_TRUE(connection != NULL);
17451 setup = xcb_get_setup(connection);
17452 iter = xcb_setup_roots_iterator(setup);
17453 while (scr-- > 0)
17454 xcb_screen_next(&iter);
17455 screen = iter.data;
17456
17457 xcb_window = xcb_generate_id(connection);
17458
17459 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17460 value_list[0] = screen->black_pixel;
17461 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17462
17463 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17464 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17465
17466 /* Magic code that will send notification when window is destroyed */
17467 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17468 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17469
17470 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17471 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17472 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17473 free(reply);
17474
17475 xcb_map_window(connection, xcb_window);
17476
17477 // Force the x/y coordinates to 100,100 results are identical in consecutive
17478 // runs
17479 const uint32_t coords[] = { 100, 100 };
17480 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17481
17482 // Finally, try to correctly create a surface:
17483 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17484 xcb_create_info.pNext = NULL;
17485 xcb_create_info.flags = 0;
17486 xcb_create_info.connection = connection;
17487 xcb_create_info.window = xcb_window;
17488 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17489 pass = (err == VK_SUCCESS);
17490 ASSERT_TRUE(pass);
17491
17492 // Check if surface supports presentation:
17493
17494 // 1st, do so without having queried the queue families:
17495 VkBool32 supported = false;
17496 // TODO: Get the following error to come out:
17497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17498 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17499 "function");
17500 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17501 pass = (err != VK_SUCCESS);
17502 // ASSERT_TRUE(pass);
17503 // m_errorMonitor->VerifyFound();
17504
17505 // Next, query a queue family index that's too large:
17506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17507 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17508 pass = (err != VK_SUCCESS);
17509 ASSERT_TRUE(pass);
17510 m_errorMonitor->VerifyFound();
17511
17512 // Finally, do so correctly:
17513 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17514 // SUPPORTED
17515 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17516 pass = (err == VK_SUCCESS);
17517 ASSERT_TRUE(pass);
17518
17519 // Before proceeding, try to create a swapchain without having called
17520 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17521 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17522 swapchain_create_info.pNext = NULL;
17523 swapchain_create_info.flags = 0;
17524 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17525 swapchain_create_info.surface = surface;
17526 swapchain_create_info.imageArrayLayers = 1;
17527 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17528 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17530 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17531 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17532 pass = (err != VK_SUCCESS);
17533 ASSERT_TRUE(pass);
17534 m_errorMonitor->VerifyFound();
17535
17536 // Get the surface capabilities:
17537 VkSurfaceCapabilitiesKHR surface_capabilities;
17538
17539 // Do so correctly (only error logged by this entrypoint is if the
17540 // extension isn't enabled):
17541 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17542 pass = (err == VK_SUCCESS);
17543 ASSERT_TRUE(pass);
17544
17545 // Get the surface formats:
17546 uint32_t surface_format_count;
17547
17548 // First, try without a pointer to surface_format_count:
17549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17550 "specified as NULL");
17551 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17552 pass = (err == VK_SUCCESS);
17553 ASSERT_TRUE(pass);
17554 m_errorMonitor->VerifyFound();
17555
17556 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17557 // correctly done a 1st try (to get the count):
17558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17559 surface_format_count = 0;
17560 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17561 pass = (err == VK_SUCCESS);
17562 ASSERT_TRUE(pass);
17563 m_errorMonitor->VerifyFound();
17564
17565 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17566 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17567 pass = (err == VK_SUCCESS);
17568 ASSERT_TRUE(pass);
17569
17570 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17571 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17572
17573 // Next, do a 2nd try with surface_format_count being set too high:
17574 surface_format_count += 5;
17575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17576 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17577 pass = (err == VK_SUCCESS);
17578 ASSERT_TRUE(pass);
17579 m_errorMonitor->VerifyFound();
17580
17581 // Finally, do a correct 1st and 2nd try:
17582 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17583 pass = (err == VK_SUCCESS);
17584 ASSERT_TRUE(pass);
17585 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17586 pass = (err == VK_SUCCESS);
17587 ASSERT_TRUE(pass);
17588
17589 // Get the surface present modes:
17590 uint32_t surface_present_mode_count;
17591
17592 // First, try without a pointer to surface_format_count:
17593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17594 "specified as NULL");
17595
17596 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17597 pass = (err == VK_SUCCESS);
17598 ASSERT_TRUE(pass);
17599 m_errorMonitor->VerifyFound();
17600
17601 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17602 // correctly done a 1st try (to get the count):
17603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17604 surface_present_mode_count = 0;
17605 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17606 (VkPresentModeKHR *)&surface_present_mode_count);
17607 pass = (err == VK_SUCCESS);
17608 ASSERT_TRUE(pass);
17609 m_errorMonitor->VerifyFound();
17610
17611 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17612 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17613 pass = (err == VK_SUCCESS);
17614 ASSERT_TRUE(pass);
17615
17616 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17617 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17618
17619 // Next, do a 2nd try with surface_format_count being set too high:
17620 surface_present_mode_count += 5;
17621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17622 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17623 pass = (err == VK_SUCCESS);
17624 ASSERT_TRUE(pass);
17625 m_errorMonitor->VerifyFound();
17626
17627 // Finally, do a correct 1st and 2nd try:
17628 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17629 pass = (err == VK_SUCCESS);
17630 ASSERT_TRUE(pass);
17631 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17632 pass = (err == VK_SUCCESS);
17633 ASSERT_TRUE(pass);
17634
17635 // Create a swapchain:
17636
17637 // First, try without a pointer to swapchain_create_info:
17638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17639 "specified as NULL");
17640
17641 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17642 pass = (err != VK_SUCCESS);
17643 ASSERT_TRUE(pass);
17644 m_errorMonitor->VerifyFound();
17645
17646 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17647 // sType:
17648 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17650
17651 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17652 pass = (err != VK_SUCCESS);
17653 ASSERT_TRUE(pass);
17654 m_errorMonitor->VerifyFound();
17655
17656 // Next, call with a NULL swapchain pointer:
17657 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17658 swapchain_create_info.pNext = NULL;
17659 swapchain_create_info.flags = 0;
17660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17661 "specified as NULL");
17662
17663 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17664 pass = (err != VK_SUCCESS);
17665 ASSERT_TRUE(pass);
17666 m_errorMonitor->VerifyFound();
17667
17668 // TODO: Enhance swapchain layer so that
17669 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17670
17671 // Next, call with a queue family index that's too large:
17672 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17673 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17674 swapchain_create_info.queueFamilyIndexCount = 2;
17675 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17677 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17678 pass = (err != VK_SUCCESS);
17679 ASSERT_TRUE(pass);
17680 m_errorMonitor->VerifyFound();
17681
17682 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17683 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17684 swapchain_create_info.queueFamilyIndexCount = 1;
17685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17686 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17687 "pCreateInfo->pQueueFamilyIndices).");
17688 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17689 pass = (err != VK_SUCCESS);
17690 ASSERT_TRUE(pass);
17691 m_errorMonitor->VerifyFound();
17692
17693 // Next, call with an invalid imageSharingMode:
17694 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17695 swapchain_create_info.queueFamilyIndexCount = 1;
17696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17697 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17698 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17699 pass = (err != VK_SUCCESS);
17700 ASSERT_TRUE(pass);
17701 m_errorMonitor->VerifyFound();
17702 // Fix for the future:
17703 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17704 // SUPPORTED
17705 swapchain_create_info.queueFamilyIndexCount = 0;
17706 queueFamilyIndex[0] = 0;
17707 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17708
17709 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17710 // Get the images from a swapchain:
17711 // Acquire an image from a swapchain:
17712 // Present an image to a swapchain:
17713 // Destroy the swapchain:
17714
17715 // TODOs:
17716 //
17717 // - Try destroying the device without first destroying the swapchain
17718 //
17719 // - Try destroying the device without first destroying the surface
17720 //
17721 // - Try destroying the surface without first destroying the swapchain
17722
17723 // Destroy the surface:
17724 vkDestroySurfaceKHR(instance(), surface, NULL);
17725
17726 // Tear down the window:
17727 xcb_destroy_window(connection, xcb_window);
17728 xcb_disconnect(connection);
17729
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017730#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017731 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017732#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017733}
Chris Forbes09368e42016-10-13 11:59:22 +130017734#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017735
17736//
17737// POSITIVE VALIDATION TESTS
17738//
17739// These tests do not expect to encounter ANY validation errors pass only if this is true
17740
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017741TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17742 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17743 ASSERT_NO_FATAL_FAILURE(InitState());
17744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17745
17746 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17747 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17748 command_buffer_allocate_info.commandPool = m_commandPool;
17749 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17750 command_buffer_allocate_info.commandBufferCount = 1;
17751
17752 VkCommandBuffer secondary_command_buffer;
17753 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17754 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17755 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17756 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17757 command_buffer_inheritance_info.renderPass = m_renderPass;
17758 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17759
17760 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17761 command_buffer_begin_info.flags =
17762 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17763 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17764
17765 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17766 VkClearAttachment color_attachment;
17767 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17768 color_attachment.clearValue.color.float32[0] = 0;
17769 color_attachment.clearValue.color.float32[1] = 0;
17770 color_attachment.clearValue.color.float32[2] = 0;
17771 color_attachment.clearValue.color.float32[3] = 0;
17772 color_attachment.colorAttachment = 0;
17773 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17774 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17775}
17776
Tobin Ehlise0006882016-11-03 10:14:28 -060017777TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017778 TEST_DESCRIPTION(
17779 "Perform an image layout transition in a secondary command buffer followed "
17780 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017781 VkResult err;
17782 m_errorMonitor->ExpectSuccess();
17783 ASSERT_NO_FATAL_FAILURE(InitState());
17784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17785 // Allocate a secondary and primary cmd buffer
17786 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17787 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17788 command_buffer_allocate_info.commandPool = m_commandPool;
17789 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17790 command_buffer_allocate_info.commandBufferCount = 1;
17791
17792 VkCommandBuffer secondary_command_buffer;
17793 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17794 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17795 VkCommandBuffer primary_command_buffer;
17796 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17797 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17798 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17799 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17800 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17801 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17802 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17803
17804 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17805 ASSERT_VK_SUCCESS(err);
17806 VkImageObj image(m_device);
17807 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17808 ASSERT_TRUE(image.initialized());
17809 VkImageMemoryBarrier img_barrier = {};
17810 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17811 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17812 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17813 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17814 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17815 img_barrier.image = image.handle();
17816 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17817 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17818 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17819 img_barrier.subresourceRange.baseArrayLayer = 0;
17820 img_barrier.subresourceRange.baseMipLevel = 0;
17821 img_barrier.subresourceRange.layerCount = 1;
17822 img_barrier.subresourceRange.levelCount = 1;
17823 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17824 0, nullptr, 1, &img_barrier);
17825 err = vkEndCommandBuffer(secondary_command_buffer);
17826 ASSERT_VK_SUCCESS(err);
17827
17828 // Now update primary cmd buffer to execute secondary and transitions image
17829 command_buffer_begin_info.pInheritanceInfo = nullptr;
17830 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17831 ASSERT_VK_SUCCESS(err);
17832 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17833 VkImageMemoryBarrier img_barrier2 = {};
17834 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17835 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17836 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17837 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17838 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17839 img_barrier2.image = image.handle();
17840 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17841 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17842 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17843 img_barrier2.subresourceRange.baseArrayLayer = 0;
17844 img_barrier2.subresourceRange.baseMipLevel = 0;
17845 img_barrier2.subresourceRange.layerCount = 1;
17846 img_barrier2.subresourceRange.levelCount = 1;
17847 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17848 nullptr, 1, &img_barrier2);
17849 err = vkEndCommandBuffer(primary_command_buffer);
17850 ASSERT_VK_SUCCESS(err);
17851 VkSubmitInfo submit_info = {};
17852 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17853 submit_info.commandBufferCount = 1;
17854 submit_info.pCommandBuffers = &primary_command_buffer;
17855 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17856 ASSERT_VK_SUCCESS(err);
17857 m_errorMonitor->VerifyNotFound();
17858 err = vkDeviceWaitIdle(m_device->device());
17859 ASSERT_VK_SUCCESS(err);
17860 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17861 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17862}
17863
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017864// This is a positive test. No failures are expected.
17865TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017866 TEST_DESCRIPTION(
17867 "Ensure that the vkUpdateDescriptorSets validation code "
17868 "is ignoring VkWriteDescriptorSet members that are not "
17869 "related to the descriptor type specified by "
17870 "VkWriteDescriptorSet::descriptorType. Correct "
17871 "validation behavior will result in the test running to "
17872 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017873
17874 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17875
17876 ASSERT_NO_FATAL_FAILURE(InitState());
17877
17878 // Image Case
17879 {
17880 m_errorMonitor->ExpectSuccess();
17881
17882 VkImage image;
17883 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17884 const int32_t tex_width = 32;
17885 const int32_t tex_height = 32;
17886 VkImageCreateInfo image_create_info = {};
17887 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17888 image_create_info.pNext = NULL;
17889 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17890 image_create_info.format = tex_format;
17891 image_create_info.extent.width = tex_width;
17892 image_create_info.extent.height = tex_height;
17893 image_create_info.extent.depth = 1;
17894 image_create_info.mipLevels = 1;
17895 image_create_info.arrayLayers = 1;
17896 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17897 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17898 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17899 image_create_info.flags = 0;
17900 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17901 ASSERT_VK_SUCCESS(err);
17902
17903 VkMemoryRequirements memory_reqs;
17904 VkDeviceMemory image_memory;
17905 bool pass;
17906 VkMemoryAllocateInfo memory_info = {};
17907 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17908 memory_info.pNext = NULL;
17909 memory_info.allocationSize = 0;
17910 memory_info.memoryTypeIndex = 0;
17911 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17912 memory_info.allocationSize = memory_reqs.size;
17913 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17914 ASSERT_TRUE(pass);
17915 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17916 ASSERT_VK_SUCCESS(err);
17917 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17918 ASSERT_VK_SUCCESS(err);
17919
17920 VkImageViewCreateInfo image_view_create_info = {};
17921 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17922 image_view_create_info.image = image;
17923 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17924 image_view_create_info.format = tex_format;
17925 image_view_create_info.subresourceRange.layerCount = 1;
17926 image_view_create_info.subresourceRange.baseMipLevel = 0;
17927 image_view_create_info.subresourceRange.levelCount = 1;
17928 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17929
17930 VkImageView view;
17931 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17932 ASSERT_VK_SUCCESS(err);
17933
17934 VkDescriptorPoolSize ds_type_count = {};
17935 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17936 ds_type_count.descriptorCount = 1;
17937
17938 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17939 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17940 ds_pool_ci.pNext = NULL;
17941 ds_pool_ci.maxSets = 1;
17942 ds_pool_ci.poolSizeCount = 1;
17943 ds_pool_ci.pPoolSizes = &ds_type_count;
17944
17945 VkDescriptorPool ds_pool;
17946 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17947 ASSERT_VK_SUCCESS(err);
17948
17949 VkDescriptorSetLayoutBinding dsl_binding = {};
17950 dsl_binding.binding = 0;
17951 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17952 dsl_binding.descriptorCount = 1;
17953 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17954 dsl_binding.pImmutableSamplers = NULL;
17955
17956 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17957 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17958 ds_layout_ci.pNext = NULL;
17959 ds_layout_ci.bindingCount = 1;
17960 ds_layout_ci.pBindings = &dsl_binding;
17961 VkDescriptorSetLayout ds_layout;
17962 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17963 ASSERT_VK_SUCCESS(err);
17964
17965 VkDescriptorSet descriptor_set;
17966 VkDescriptorSetAllocateInfo alloc_info = {};
17967 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17968 alloc_info.descriptorSetCount = 1;
17969 alloc_info.descriptorPool = ds_pool;
17970 alloc_info.pSetLayouts = &ds_layout;
17971 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17972 ASSERT_VK_SUCCESS(err);
17973
17974 VkDescriptorImageInfo image_info = {};
17975 image_info.imageView = view;
17976 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17977
17978 VkWriteDescriptorSet descriptor_write;
17979 memset(&descriptor_write, 0, sizeof(descriptor_write));
17980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17981 descriptor_write.dstSet = descriptor_set;
17982 descriptor_write.dstBinding = 0;
17983 descriptor_write.descriptorCount = 1;
17984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17985 descriptor_write.pImageInfo = &image_info;
17986
17987 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17988 // be
17989 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17990 // This will most likely produce a crash if the parameter_validation
17991 // layer
17992 // does not correctly ignore pBufferInfo.
17993 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17994 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17995
17996 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17997
17998 m_errorMonitor->VerifyNotFound();
17999
18000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18002 vkDestroyImageView(m_device->device(), view, NULL);
18003 vkDestroyImage(m_device->device(), image, NULL);
18004 vkFreeMemory(m_device->device(), image_memory, NULL);
18005 }
18006
18007 // Buffer Case
18008 {
18009 m_errorMonitor->ExpectSuccess();
18010
18011 VkBuffer buffer;
18012 uint32_t queue_family_index = 0;
18013 VkBufferCreateInfo buffer_create_info = {};
18014 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18015 buffer_create_info.size = 1024;
18016 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18017 buffer_create_info.queueFamilyIndexCount = 1;
18018 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18019
18020 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18021 ASSERT_VK_SUCCESS(err);
18022
18023 VkMemoryRequirements memory_reqs;
18024 VkDeviceMemory buffer_memory;
18025 bool pass;
18026 VkMemoryAllocateInfo memory_info = {};
18027 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18028 memory_info.pNext = NULL;
18029 memory_info.allocationSize = 0;
18030 memory_info.memoryTypeIndex = 0;
18031
18032 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18033 memory_info.allocationSize = memory_reqs.size;
18034 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18035 ASSERT_TRUE(pass);
18036
18037 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18038 ASSERT_VK_SUCCESS(err);
18039 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18040 ASSERT_VK_SUCCESS(err);
18041
18042 VkDescriptorPoolSize ds_type_count = {};
18043 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18044 ds_type_count.descriptorCount = 1;
18045
18046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18048 ds_pool_ci.pNext = NULL;
18049 ds_pool_ci.maxSets = 1;
18050 ds_pool_ci.poolSizeCount = 1;
18051 ds_pool_ci.pPoolSizes = &ds_type_count;
18052
18053 VkDescriptorPool ds_pool;
18054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18055 ASSERT_VK_SUCCESS(err);
18056
18057 VkDescriptorSetLayoutBinding dsl_binding = {};
18058 dsl_binding.binding = 0;
18059 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18060 dsl_binding.descriptorCount = 1;
18061 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18062 dsl_binding.pImmutableSamplers = NULL;
18063
18064 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18065 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18066 ds_layout_ci.pNext = NULL;
18067 ds_layout_ci.bindingCount = 1;
18068 ds_layout_ci.pBindings = &dsl_binding;
18069 VkDescriptorSetLayout ds_layout;
18070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18071 ASSERT_VK_SUCCESS(err);
18072
18073 VkDescriptorSet descriptor_set;
18074 VkDescriptorSetAllocateInfo alloc_info = {};
18075 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18076 alloc_info.descriptorSetCount = 1;
18077 alloc_info.descriptorPool = ds_pool;
18078 alloc_info.pSetLayouts = &ds_layout;
18079 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18080 ASSERT_VK_SUCCESS(err);
18081
18082 VkDescriptorBufferInfo buffer_info = {};
18083 buffer_info.buffer = buffer;
18084 buffer_info.offset = 0;
18085 buffer_info.range = 1024;
18086
18087 VkWriteDescriptorSet descriptor_write;
18088 memset(&descriptor_write, 0, sizeof(descriptor_write));
18089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18090 descriptor_write.dstSet = descriptor_set;
18091 descriptor_write.dstBinding = 0;
18092 descriptor_write.descriptorCount = 1;
18093 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18094 descriptor_write.pBufferInfo = &buffer_info;
18095
18096 // Set pImageInfo and pTexelBufferView to invalid values, which should
18097 // be
18098 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18099 // This will most likely produce a crash if the parameter_validation
18100 // layer
18101 // does not correctly ignore pImageInfo.
18102 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18103 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18104
18105 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18106
18107 m_errorMonitor->VerifyNotFound();
18108
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18111 vkDestroyBuffer(m_device->device(), buffer, NULL);
18112 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18113 }
18114
18115 // Texel Buffer Case
18116 {
18117 m_errorMonitor->ExpectSuccess();
18118
18119 VkBuffer buffer;
18120 uint32_t queue_family_index = 0;
18121 VkBufferCreateInfo buffer_create_info = {};
18122 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18123 buffer_create_info.size = 1024;
18124 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18125 buffer_create_info.queueFamilyIndexCount = 1;
18126 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18127
18128 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18129 ASSERT_VK_SUCCESS(err);
18130
18131 VkMemoryRequirements memory_reqs;
18132 VkDeviceMemory buffer_memory;
18133 bool pass;
18134 VkMemoryAllocateInfo memory_info = {};
18135 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18136 memory_info.pNext = NULL;
18137 memory_info.allocationSize = 0;
18138 memory_info.memoryTypeIndex = 0;
18139
18140 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18141 memory_info.allocationSize = memory_reqs.size;
18142 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18143 ASSERT_TRUE(pass);
18144
18145 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18146 ASSERT_VK_SUCCESS(err);
18147 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18148 ASSERT_VK_SUCCESS(err);
18149
18150 VkBufferViewCreateInfo buff_view_ci = {};
18151 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18152 buff_view_ci.buffer = buffer;
18153 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18154 buff_view_ci.range = VK_WHOLE_SIZE;
18155 VkBufferView buffer_view;
18156 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18157
18158 VkDescriptorPoolSize ds_type_count = {};
18159 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18160 ds_type_count.descriptorCount = 1;
18161
18162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18164 ds_pool_ci.pNext = NULL;
18165 ds_pool_ci.maxSets = 1;
18166 ds_pool_ci.poolSizeCount = 1;
18167 ds_pool_ci.pPoolSizes = &ds_type_count;
18168
18169 VkDescriptorPool ds_pool;
18170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18171 ASSERT_VK_SUCCESS(err);
18172
18173 VkDescriptorSetLayoutBinding dsl_binding = {};
18174 dsl_binding.binding = 0;
18175 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18176 dsl_binding.descriptorCount = 1;
18177 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18178 dsl_binding.pImmutableSamplers = NULL;
18179
18180 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18181 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18182 ds_layout_ci.pNext = NULL;
18183 ds_layout_ci.bindingCount = 1;
18184 ds_layout_ci.pBindings = &dsl_binding;
18185 VkDescriptorSetLayout ds_layout;
18186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18187 ASSERT_VK_SUCCESS(err);
18188
18189 VkDescriptorSet descriptor_set;
18190 VkDescriptorSetAllocateInfo alloc_info = {};
18191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18192 alloc_info.descriptorSetCount = 1;
18193 alloc_info.descriptorPool = ds_pool;
18194 alloc_info.pSetLayouts = &ds_layout;
18195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18196 ASSERT_VK_SUCCESS(err);
18197
18198 VkWriteDescriptorSet descriptor_write;
18199 memset(&descriptor_write, 0, sizeof(descriptor_write));
18200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18201 descriptor_write.dstSet = descriptor_set;
18202 descriptor_write.dstBinding = 0;
18203 descriptor_write.descriptorCount = 1;
18204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18205 descriptor_write.pTexelBufferView = &buffer_view;
18206
18207 // Set pImageInfo and pBufferInfo to invalid values, which should be
18208 // ignored for descriptorType ==
18209 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18210 // This will most likely produce a crash if the parameter_validation
18211 // layer
18212 // does not correctly ignore pImageInfo and pBufferInfo.
18213 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18214 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18215
18216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18217
18218 m_errorMonitor->VerifyNotFound();
18219
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18222 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18223 vkDestroyBuffer(m_device->device(), buffer, NULL);
18224 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18225 }
18226}
18227
Tobin Ehlisf7428442016-10-25 07:58:24 -060018228TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18229 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18230
18231 ASSERT_NO_FATAL_FAILURE(InitState());
18232 // Create layout where two binding #s are "1"
18233 static const uint32_t NUM_BINDINGS = 3;
18234 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18235 dsl_binding[0].binding = 1;
18236 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18237 dsl_binding[0].descriptorCount = 1;
18238 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18239 dsl_binding[0].pImmutableSamplers = NULL;
18240 dsl_binding[1].binding = 0;
18241 dsl_binding[1].descriptorCount = 1;
18242 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18243 dsl_binding[1].descriptorCount = 1;
18244 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18245 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018246 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018247 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18248 dsl_binding[2].descriptorCount = 1;
18249 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18250 dsl_binding[2].pImmutableSamplers = NULL;
18251
18252 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18253 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18254 ds_layout_ci.pNext = NULL;
18255 ds_layout_ci.bindingCount = NUM_BINDINGS;
18256 ds_layout_ci.pBindings = dsl_binding;
18257 VkDescriptorSetLayout ds_layout;
18258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18259 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18260 m_errorMonitor->VerifyFound();
18261}
18262
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018263TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018264 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18265
18266 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018267
Tony Barbour552f6c02016-12-21 14:34:07 -070018268 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018269
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018270 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18271
18272 {
18273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18274 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18275 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18276 m_errorMonitor->VerifyFound();
18277 }
18278
18279 {
18280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18281 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18282 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18283 m_errorMonitor->VerifyFound();
18284 }
18285
18286 {
18287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18288 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18289 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18290 m_errorMonitor->VerifyFound();
18291 }
18292
18293 {
18294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18295 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18296 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18297 m_errorMonitor->VerifyFound();
18298 }
18299
18300 {
18301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18302 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18303 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18304 m_errorMonitor->VerifyFound();
18305 }
18306
18307 {
18308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18309 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18311 m_errorMonitor->VerifyFound();
18312 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018313
18314 {
18315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18316 VkRect2D scissor = {{-1, 0}, {16, 16}};
18317 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18318 m_errorMonitor->VerifyFound();
18319 }
18320
18321 {
18322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18323 VkRect2D scissor = {{0, -2}, {16, 16}};
18324 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18325 m_errorMonitor->VerifyFound();
18326 }
18327
18328 {
18329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18330 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18331 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18332 m_errorMonitor->VerifyFound();
18333 }
18334
18335 {
18336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18337 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18338 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18339 m_errorMonitor->VerifyFound();
18340 }
18341
Tony Barbour552f6c02016-12-21 14:34:07 -070018342 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018343}
18344
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018345// This is a positive test. No failures are expected.
18346TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18347 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18348 VkResult err;
18349
18350 ASSERT_NO_FATAL_FAILURE(InitState());
18351 m_errorMonitor->ExpectSuccess();
18352 VkDescriptorPoolSize ds_type_count = {};
18353 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18354 ds_type_count.descriptorCount = 2;
18355
18356 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18357 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18358 ds_pool_ci.pNext = NULL;
18359 ds_pool_ci.maxSets = 1;
18360 ds_pool_ci.poolSizeCount = 1;
18361 ds_pool_ci.pPoolSizes = &ds_type_count;
18362
18363 VkDescriptorPool ds_pool;
18364 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18365 ASSERT_VK_SUCCESS(err);
18366
18367 // Create layout with two uniform buffer descriptors w/ empty binding between them
18368 static const uint32_t NUM_BINDINGS = 3;
18369 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18370 dsl_binding[0].binding = 0;
18371 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18372 dsl_binding[0].descriptorCount = 1;
18373 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18374 dsl_binding[0].pImmutableSamplers = NULL;
18375 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018376 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018377 dsl_binding[2].binding = 2;
18378 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18379 dsl_binding[2].descriptorCount = 1;
18380 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18381 dsl_binding[2].pImmutableSamplers = NULL;
18382
18383 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18384 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18385 ds_layout_ci.pNext = NULL;
18386 ds_layout_ci.bindingCount = NUM_BINDINGS;
18387 ds_layout_ci.pBindings = dsl_binding;
18388 VkDescriptorSetLayout ds_layout;
18389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18390 ASSERT_VK_SUCCESS(err);
18391
18392 VkDescriptorSet descriptor_set = {};
18393 VkDescriptorSetAllocateInfo alloc_info = {};
18394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18395 alloc_info.descriptorSetCount = 1;
18396 alloc_info.descriptorPool = ds_pool;
18397 alloc_info.pSetLayouts = &ds_layout;
18398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18399 ASSERT_VK_SUCCESS(err);
18400
18401 // Create a buffer to be used for update
18402 VkBufferCreateInfo buff_ci = {};
18403 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18404 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18405 buff_ci.size = 256;
18406 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18407 VkBuffer buffer;
18408 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18409 ASSERT_VK_SUCCESS(err);
18410 // Have to bind memory to buffer before descriptor update
18411 VkMemoryAllocateInfo mem_alloc = {};
18412 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18413 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018414 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018415 mem_alloc.memoryTypeIndex = 0;
18416
18417 VkMemoryRequirements mem_reqs;
18418 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18419 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18420 if (!pass) {
18421 vkDestroyBuffer(m_device->device(), buffer, NULL);
18422 return;
18423 }
18424
18425 VkDeviceMemory mem;
18426 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18427 ASSERT_VK_SUCCESS(err);
18428 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18429 ASSERT_VK_SUCCESS(err);
18430
18431 // Only update the descriptor at binding 2
18432 VkDescriptorBufferInfo buff_info = {};
18433 buff_info.buffer = buffer;
18434 buff_info.offset = 0;
18435 buff_info.range = VK_WHOLE_SIZE;
18436 VkWriteDescriptorSet descriptor_write = {};
18437 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18438 descriptor_write.dstBinding = 2;
18439 descriptor_write.descriptorCount = 1;
18440 descriptor_write.pTexelBufferView = nullptr;
18441 descriptor_write.pBufferInfo = &buff_info;
18442 descriptor_write.pImageInfo = nullptr;
18443 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18444 descriptor_write.dstSet = descriptor_set;
18445
18446 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18447
18448 m_errorMonitor->VerifyNotFound();
18449 // Cleanup
18450 vkFreeMemory(m_device->device(), mem, NULL);
18451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18452 vkDestroyBuffer(m_device->device(), buffer, NULL);
18453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18454}
18455
18456// This is a positive test. No failures are expected.
18457TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18458 VkResult err;
18459 bool pass;
18460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018461 TEST_DESCRIPTION(
18462 "Create a buffer, allocate memory, bind memory, destroy "
18463 "the buffer, create an image, and bind the same memory to "
18464 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018465
18466 m_errorMonitor->ExpectSuccess();
18467
18468 ASSERT_NO_FATAL_FAILURE(InitState());
18469
18470 VkBuffer buffer;
18471 VkImage image;
18472 VkDeviceMemory mem;
18473 VkMemoryRequirements mem_reqs;
18474
18475 VkBufferCreateInfo buf_info = {};
18476 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18477 buf_info.pNext = NULL;
18478 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18479 buf_info.size = 256;
18480 buf_info.queueFamilyIndexCount = 0;
18481 buf_info.pQueueFamilyIndices = NULL;
18482 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18483 buf_info.flags = 0;
18484 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18485 ASSERT_VK_SUCCESS(err);
18486
18487 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18488
18489 VkMemoryAllocateInfo alloc_info = {};
18490 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18491 alloc_info.pNext = NULL;
18492 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018493
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018494 // Ensure memory is big enough for both bindings
18495 alloc_info.allocationSize = 0x10000;
18496
18497 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18498 if (!pass) {
18499 vkDestroyBuffer(m_device->device(), buffer, NULL);
18500 return;
18501 }
18502
18503 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18504 ASSERT_VK_SUCCESS(err);
18505
18506 uint8_t *pData;
18507 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18508 ASSERT_VK_SUCCESS(err);
18509
18510 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18511
18512 vkUnmapMemory(m_device->device(), mem);
18513
18514 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18515 ASSERT_VK_SUCCESS(err);
18516
18517 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18518 // memory. In fact, it was never used by the GPU.
18519 // Just be be sure, wait for idle.
18520 vkDestroyBuffer(m_device->device(), buffer, NULL);
18521 vkDeviceWaitIdle(m_device->device());
18522
Tobin Ehlis6a005702016-12-28 15:25:56 -070018523 // Use optimal as some platforms report linear support but then fail image creation
18524 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18525 VkImageFormatProperties image_format_properties;
18526 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18527 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18528 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018529 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018530 vkFreeMemory(m_device->device(), mem, NULL);
18531 return;
18532 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018533 VkImageCreateInfo image_create_info = {};
18534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18535 image_create_info.pNext = NULL;
18536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18537 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18538 image_create_info.extent.width = 64;
18539 image_create_info.extent.height = 64;
18540 image_create_info.extent.depth = 1;
18541 image_create_info.mipLevels = 1;
18542 image_create_info.arrayLayers = 1;
18543 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018544 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018545 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18546 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18547 image_create_info.queueFamilyIndexCount = 0;
18548 image_create_info.pQueueFamilyIndices = NULL;
18549 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18550 image_create_info.flags = 0;
18551
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018552 /* Create a mappable image. It will be the texture if linear images are ok
18553 * to be textures or it will be the staging image if they are not.
18554 */
18555 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18556 ASSERT_VK_SUCCESS(err);
18557
18558 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18559
Tobin Ehlis6a005702016-12-28 15:25:56 -070018560 VkMemoryAllocateInfo mem_alloc = {};
18561 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18562 mem_alloc.pNext = NULL;
18563 mem_alloc.allocationSize = 0;
18564 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018565 mem_alloc.allocationSize = mem_reqs.size;
18566
18567 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18568 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018569 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018570 vkDestroyImage(m_device->device(), image, NULL);
18571 return;
18572 }
18573
18574 // VALIDATION FAILURE:
18575 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18576 ASSERT_VK_SUCCESS(err);
18577
18578 m_errorMonitor->VerifyNotFound();
18579
18580 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018581 vkDestroyImage(m_device->device(), image, NULL);
18582}
18583
Tony Barbourab713912017-02-02 14:17:35 -070018584// This is a positive test. No failures are expected.
18585TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18586 VkResult err;
18587
18588 TEST_DESCRIPTION(
18589 "Call all applicable destroy and free routines with NULL"
18590 "handles, expecting no validation errors");
18591
18592 m_errorMonitor->ExpectSuccess();
18593
18594 ASSERT_NO_FATAL_FAILURE(InitState());
18595 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18596 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18597 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18598 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18599 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18600 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18601 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18602 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18603 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18604 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18605 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18606 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18607 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18608 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18609 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18610 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18611 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18612 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18613 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18614 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18615
18616 VkCommandPool command_pool;
18617 VkCommandPoolCreateInfo pool_create_info{};
18618 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18619 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18620 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18621 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18622 VkCommandBuffer command_buffers[3] = {};
18623 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18624 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18625 command_buffer_allocate_info.commandPool = command_pool;
18626 command_buffer_allocate_info.commandBufferCount = 1;
18627 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18628 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18629 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18630 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18631
18632 VkDescriptorPoolSize ds_type_count = {};
18633 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18634 ds_type_count.descriptorCount = 1;
18635
18636 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18637 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18638 ds_pool_ci.pNext = NULL;
18639 ds_pool_ci.maxSets = 1;
18640 ds_pool_ci.poolSizeCount = 1;
18641 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18642 ds_pool_ci.pPoolSizes = &ds_type_count;
18643
18644 VkDescriptorPool ds_pool;
18645 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18646 ASSERT_VK_SUCCESS(err);
18647
18648 VkDescriptorSetLayoutBinding dsl_binding = {};
18649 dsl_binding.binding = 2;
18650 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18651 dsl_binding.descriptorCount = 1;
18652 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18653 dsl_binding.pImmutableSamplers = NULL;
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 = 1;
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_sets[3] = {};
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_sets[1]);
18670 ASSERT_VK_SUCCESS(err);
18671 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18672 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18674
18675 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18676
18677 m_errorMonitor->VerifyNotFound();
18678}
18679
Tony Barbour626994c2017-02-08 15:29:37 -070018680TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018681 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018682
18683 m_errorMonitor->ExpectSuccess();
18684
18685 ASSERT_NO_FATAL_FAILURE(InitState());
18686 VkCommandBuffer cmd_bufs[4];
18687 VkCommandBufferAllocateInfo alloc_info;
18688 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18689 alloc_info.pNext = NULL;
18690 alloc_info.commandBufferCount = 4;
18691 alloc_info.commandPool = m_commandPool;
18692 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18693 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18694 VkImageObj image(m_device);
18695 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18696 ASSERT_TRUE(image.initialized());
18697 VkCommandBufferBeginInfo cb_binfo;
18698 cb_binfo.pNext = NULL;
18699 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18700 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18701 cb_binfo.flags = 0;
18702 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18703 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18704 VkImageMemoryBarrier img_barrier = {};
18705 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18706 img_barrier.pNext = NULL;
18707 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18708 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18709 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18710 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18711 img_barrier.image = image.handle();
18712 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18713 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18714 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18715 img_barrier.subresourceRange.baseArrayLayer = 0;
18716 img_barrier.subresourceRange.baseMipLevel = 0;
18717 img_barrier.subresourceRange.layerCount = 1;
18718 img_barrier.subresourceRange.levelCount = 1;
18719 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18720 &img_barrier);
18721 vkEndCommandBuffer(cmd_bufs[0]);
18722 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18723 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18724 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18725 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18726 &img_barrier);
18727 vkEndCommandBuffer(cmd_bufs[1]);
18728 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18729 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18730 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18731 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18732 &img_barrier);
18733 vkEndCommandBuffer(cmd_bufs[2]);
18734 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18735 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18736 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18737 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18738 &img_barrier);
18739 vkEndCommandBuffer(cmd_bufs[3]);
18740
18741 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18742 VkSemaphore semaphore1, semaphore2;
18743 VkSemaphoreCreateInfo semaphore_create_info{};
18744 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18745 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18746 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18747 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18748 VkSubmitInfo submit_info[3];
18749 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18750 submit_info[0].pNext = nullptr;
18751 submit_info[0].commandBufferCount = 1;
18752 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18753 submit_info[0].signalSemaphoreCount = 1;
18754 submit_info[0].pSignalSemaphores = &semaphore1;
18755 submit_info[0].waitSemaphoreCount = 0;
18756 submit_info[0].pWaitDstStageMask = nullptr;
18757 submit_info[0].pWaitDstStageMask = flags;
18758 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18759 submit_info[1].pNext = nullptr;
18760 submit_info[1].commandBufferCount = 1;
18761 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18762 submit_info[1].waitSemaphoreCount = 1;
18763 submit_info[1].pWaitSemaphores = &semaphore1;
18764 submit_info[1].signalSemaphoreCount = 1;
18765 submit_info[1].pSignalSemaphores = &semaphore2;
18766 submit_info[1].pWaitDstStageMask = flags;
18767 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18768 submit_info[2].pNext = nullptr;
18769 submit_info[2].commandBufferCount = 2;
18770 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18771 submit_info[2].waitSemaphoreCount = 1;
18772 submit_info[2].pWaitSemaphores = &semaphore2;
18773 submit_info[2].signalSemaphoreCount = 0;
18774 submit_info[2].pSignalSemaphores = nullptr;
18775 submit_info[2].pWaitDstStageMask = flags;
18776 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18777 vkQueueWaitIdle(m_device->m_queue);
18778
18779 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18780 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18781 m_errorMonitor->VerifyNotFound();
18782}
18783
Tobin Ehlis953e8392016-11-17 10:54:13 -070018784TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18785 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18786 // We previously had a bug where dynamic offset of inactive bindings was still being used
18787 VkResult err;
18788 m_errorMonitor->ExpectSuccess();
18789
18790 ASSERT_NO_FATAL_FAILURE(InitState());
18791 ASSERT_NO_FATAL_FAILURE(InitViewport());
18792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18793
18794 VkDescriptorPoolSize ds_type_count = {};
18795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18796 ds_type_count.descriptorCount = 3;
18797
18798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18800 ds_pool_ci.pNext = NULL;
18801 ds_pool_ci.maxSets = 1;
18802 ds_pool_ci.poolSizeCount = 1;
18803 ds_pool_ci.pPoolSizes = &ds_type_count;
18804
18805 VkDescriptorPool ds_pool;
18806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18807 ASSERT_VK_SUCCESS(err);
18808
18809 const uint32_t BINDING_COUNT = 3;
18810 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018811 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018812 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18813 dsl_binding[0].descriptorCount = 1;
18814 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18815 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018816 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018817 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18818 dsl_binding[1].descriptorCount = 1;
18819 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18820 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018821 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018822 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18823 dsl_binding[2].descriptorCount = 1;
18824 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18825 dsl_binding[2].pImmutableSamplers = NULL;
18826
18827 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18828 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18829 ds_layout_ci.pNext = NULL;
18830 ds_layout_ci.bindingCount = BINDING_COUNT;
18831 ds_layout_ci.pBindings = dsl_binding;
18832 VkDescriptorSetLayout ds_layout;
18833 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18834 ASSERT_VK_SUCCESS(err);
18835
18836 VkDescriptorSet descriptor_set;
18837 VkDescriptorSetAllocateInfo alloc_info = {};
18838 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18839 alloc_info.descriptorSetCount = 1;
18840 alloc_info.descriptorPool = ds_pool;
18841 alloc_info.pSetLayouts = &ds_layout;
18842 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18843 ASSERT_VK_SUCCESS(err);
18844
18845 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18846 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18847 pipeline_layout_ci.pNext = NULL;
18848 pipeline_layout_ci.setLayoutCount = 1;
18849 pipeline_layout_ci.pSetLayouts = &ds_layout;
18850
18851 VkPipelineLayout pipeline_layout;
18852 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18853 ASSERT_VK_SUCCESS(err);
18854
18855 // Create two buffers to update the descriptors with
18856 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18857 uint32_t qfi = 0;
18858 VkBufferCreateInfo buffCI = {};
18859 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18860 buffCI.size = 2048;
18861 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18862 buffCI.queueFamilyIndexCount = 1;
18863 buffCI.pQueueFamilyIndices = &qfi;
18864
18865 VkBuffer dyub1;
18866 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18867 ASSERT_VK_SUCCESS(err);
18868 // buffer2
18869 buffCI.size = 1024;
18870 VkBuffer dyub2;
18871 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18872 ASSERT_VK_SUCCESS(err);
18873 // Allocate memory and bind to buffers
18874 VkMemoryAllocateInfo mem_alloc[2] = {};
18875 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18876 mem_alloc[0].pNext = NULL;
18877 mem_alloc[0].memoryTypeIndex = 0;
18878 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18879 mem_alloc[1].pNext = NULL;
18880 mem_alloc[1].memoryTypeIndex = 0;
18881
18882 VkMemoryRequirements mem_reqs1;
18883 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18884 VkMemoryRequirements mem_reqs2;
18885 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18886 mem_alloc[0].allocationSize = mem_reqs1.size;
18887 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18888 mem_alloc[1].allocationSize = mem_reqs2.size;
18889 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18890 if (!pass) {
18891 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18892 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18893 return;
18894 }
18895
18896 VkDeviceMemory mem1;
18897 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18898 ASSERT_VK_SUCCESS(err);
18899 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18900 ASSERT_VK_SUCCESS(err);
18901 VkDeviceMemory mem2;
18902 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18903 ASSERT_VK_SUCCESS(err);
18904 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18905 ASSERT_VK_SUCCESS(err);
18906 // Update descriptors
18907 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18908 buff_info[0].buffer = dyub1;
18909 buff_info[0].offset = 0;
18910 buff_info[0].range = 256;
18911 buff_info[1].buffer = dyub1;
18912 buff_info[1].offset = 256;
18913 buff_info[1].range = 512;
18914 buff_info[2].buffer = dyub2;
18915 buff_info[2].offset = 0;
18916 buff_info[2].range = 512;
18917
18918 VkWriteDescriptorSet descriptor_write;
18919 memset(&descriptor_write, 0, sizeof(descriptor_write));
18920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18921 descriptor_write.dstSet = descriptor_set;
18922 descriptor_write.dstBinding = 0;
18923 descriptor_write.descriptorCount = BINDING_COUNT;
18924 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18925 descriptor_write.pBufferInfo = buff_info;
18926
18927 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18928
Tony Barbour552f6c02016-12-21 14:34:07 -070018929 m_commandBuffer->BeginCommandBuffer();
18930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018931
18932 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018933 char const *vsSource =
18934 "#version 450\n"
18935 "\n"
18936 "out gl_PerVertex { \n"
18937 " vec4 gl_Position;\n"
18938 "};\n"
18939 "void main(){\n"
18940 " gl_Position = vec4(1);\n"
18941 "}\n";
18942 char const *fsSource =
18943 "#version 450\n"
18944 "\n"
18945 "layout(location=0) out vec4 x;\n"
18946 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18947 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18948 "void main(){\n"
18949 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18950 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018951 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18952 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18953 VkPipelineObj pipe(m_device);
18954 pipe.SetViewport(m_viewports);
18955 pipe.SetScissor(m_scissors);
18956 pipe.AddShader(&vs);
18957 pipe.AddShader(&fs);
18958 pipe.AddColorAttachment();
18959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18960
18961 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18962 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18963 // we used to have a bug in this case.
18964 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18965 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18966 &descriptor_set, BINDING_COUNT, dyn_off);
18967 Draw(1, 0, 0, 0);
18968 m_errorMonitor->VerifyNotFound();
18969
18970 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18971 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18972 vkFreeMemory(m_device->device(), mem1, NULL);
18973 vkFreeMemory(m_device->device(), mem2, NULL);
18974
18975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18977 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18978}
18979
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018980TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018981 TEST_DESCRIPTION(
18982 "Ensure that validations handling of non-coherent memory "
18983 "mapping while using VK_WHOLE_SIZE does not cause access "
18984 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018985 VkResult err;
18986 uint8_t *pData;
18987 ASSERT_NO_FATAL_FAILURE(InitState());
18988
18989 VkDeviceMemory mem;
18990 VkMemoryRequirements mem_reqs;
18991 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018992 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018993 VkMemoryAllocateInfo alloc_info = {};
18994 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18995 alloc_info.pNext = NULL;
18996 alloc_info.memoryTypeIndex = 0;
18997
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018998 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018999 alloc_info.allocationSize = allocation_size;
19000
19001 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19002 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 -070019003 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019004 if (!pass) {
19005 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019006 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19007 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019008 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019009 pass = m_device->phy().set_memory_type(
19010 mem_reqs.memoryTypeBits, &alloc_info,
19011 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19012 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019013 if (!pass) {
19014 return;
19015 }
19016 }
19017 }
19018
19019 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19020 ASSERT_VK_SUCCESS(err);
19021
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019022 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019023 m_errorMonitor->ExpectSuccess();
19024 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19025 ASSERT_VK_SUCCESS(err);
19026 VkMappedMemoryRange mmr = {};
19027 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19028 mmr.memory = mem;
19029 mmr.offset = 0;
19030 mmr.size = VK_WHOLE_SIZE;
19031 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19032 ASSERT_VK_SUCCESS(err);
19033 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19034 ASSERT_VK_SUCCESS(err);
19035 m_errorMonitor->VerifyNotFound();
19036 vkUnmapMemory(m_device->device(), mem);
19037
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019038 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019039 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019040 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019041 ASSERT_VK_SUCCESS(err);
19042 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19043 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019044 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019045 mmr.size = VK_WHOLE_SIZE;
19046 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19047 ASSERT_VK_SUCCESS(err);
19048 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19049 ASSERT_VK_SUCCESS(err);
19050 m_errorMonitor->VerifyNotFound();
19051 vkUnmapMemory(m_device->device(), mem);
19052
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019053 // Map with offset and size
19054 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019055 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019056 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019057 ASSERT_VK_SUCCESS(err);
19058 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19059 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019060 mmr.offset = 4 * atom_size;
19061 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019062 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19063 ASSERT_VK_SUCCESS(err);
19064 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19065 ASSERT_VK_SUCCESS(err);
19066 m_errorMonitor->VerifyNotFound();
19067 vkUnmapMemory(m_device->device(), mem);
19068
19069 // Map without offset and flush WHOLE_SIZE with two separate offsets
19070 m_errorMonitor->ExpectSuccess();
19071 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19072 ASSERT_VK_SUCCESS(err);
19073 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19074 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019075 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019076 mmr.size = VK_WHOLE_SIZE;
19077 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19078 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019079 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019080 mmr.size = VK_WHOLE_SIZE;
19081 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19082 ASSERT_VK_SUCCESS(err);
19083 m_errorMonitor->VerifyNotFound();
19084 vkUnmapMemory(m_device->device(), mem);
19085
19086 vkFreeMemory(m_device->device(), mem, NULL);
19087}
19088
19089// This is a positive test. We used to expect error in this case but spec now allows it
19090TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19091 m_errorMonitor->ExpectSuccess();
19092 vk_testing::Fence testFence;
19093 VkFenceCreateInfo fenceInfo = {};
19094 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19095 fenceInfo.pNext = NULL;
19096
19097 ASSERT_NO_FATAL_FAILURE(InitState());
19098 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019099 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019100 VkResult result = vkResetFences(m_device->device(), 1, fences);
19101 ASSERT_VK_SUCCESS(result);
19102
19103 m_errorMonitor->VerifyNotFound();
19104}
19105
19106TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19107 m_errorMonitor->ExpectSuccess();
19108
19109 ASSERT_NO_FATAL_FAILURE(InitState());
19110 VkResult err;
19111
19112 // Record (empty!) command buffer that can be submitted multiple times
19113 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019114 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19115 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019116 m_commandBuffer->BeginCommandBuffer(&cbbi);
19117 m_commandBuffer->EndCommandBuffer();
19118
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019119 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019120 VkFence fence;
19121 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19122 ASSERT_VK_SUCCESS(err);
19123
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019124 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019125 VkSemaphore s1, s2;
19126 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19127 ASSERT_VK_SUCCESS(err);
19128 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19129 ASSERT_VK_SUCCESS(err);
19130
19131 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019132 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019133 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19134 ASSERT_VK_SUCCESS(err);
19135
19136 // Submit CB again, signaling s2.
19137 si.pSignalSemaphores = &s2;
19138 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19139 ASSERT_VK_SUCCESS(err);
19140
19141 // Wait for fence.
19142 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19143 ASSERT_VK_SUCCESS(err);
19144
19145 // CB is still in flight from second submission, but semaphore s1 is no
19146 // longer in flight. delete it.
19147 vkDestroySemaphore(m_device->device(), s1, nullptr);
19148
19149 m_errorMonitor->VerifyNotFound();
19150
19151 // Force device idle and clean up remaining objects
19152 vkDeviceWaitIdle(m_device->device());
19153 vkDestroySemaphore(m_device->device(), s2, nullptr);
19154 vkDestroyFence(m_device->device(), fence, nullptr);
19155}
19156
19157TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19158 m_errorMonitor->ExpectSuccess();
19159
19160 ASSERT_NO_FATAL_FAILURE(InitState());
19161 VkResult err;
19162
19163 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019164 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019165 VkFence f1;
19166 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19167 ASSERT_VK_SUCCESS(err);
19168
19169 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019170 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019171 VkFence f2;
19172 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19173 ASSERT_VK_SUCCESS(err);
19174
19175 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019176 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019177 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19178
19179 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019180 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019181 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19182
19183 // Should have both retired!
19184 vkDestroyFence(m_device->device(), f1, nullptr);
19185 vkDestroyFence(m_device->device(), f2, nullptr);
19186
19187 m_errorMonitor->VerifyNotFound();
19188}
19189
19190TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019191 TEST_DESCRIPTION(
19192 "Verify that creating an image view from an image with valid usage "
19193 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019194
19195 ASSERT_NO_FATAL_FAILURE(InitState());
19196
19197 m_errorMonitor->ExpectSuccess();
19198 // Verify that we can create a view with usage INPUT_ATTACHMENT
19199 VkImageObj image(m_device);
19200 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19201 ASSERT_TRUE(image.initialized());
19202 VkImageView imageView;
19203 VkImageViewCreateInfo ivci = {};
19204 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19205 ivci.image = image.handle();
19206 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19207 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19208 ivci.subresourceRange.layerCount = 1;
19209 ivci.subresourceRange.baseMipLevel = 0;
19210 ivci.subresourceRange.levelCount = 1;
19211 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19212
19213 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19214 m_errorMonitor->VerifyNotFound();
19215 vkDestroyImageView(m_device->device(), imageView, NULL);
19216}
19217
19218// This is a positive test. No failures are expected.
19219TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019220 TEST_DESCRIPTION(
19221 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19222 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019223
19224 ASSERT_NO_FATAL_FAILURE(InitState());
19225
19226 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019227 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019228
19229 m_errorMonitor->ExpectSuccess();
19230
19231 VkImage image;
19232 VkImageCreateInfo image_create_info = {};
19233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19234 image_create_info.pNext = NULL;
19235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19236 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19237 image_create_info.extent.width = 64;
19238 image_create_info.extent.height = 64;
19239 image_create_info.extent.depth = 1;
19240 image_create_info.mipLevels = 1;
19241 image_create_info.arrayLayers = 1;
19242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19243 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19244 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19245 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19246 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19247 ASSERT_VK_SUCCESS(err);
19248
19249 VkMemoryRequirements memory_reqs;
19250 VkDeviceMemory memory_one, memory_two;
19251 bool pass;
19252 VkMemoryAllocateInfo memory_info = {};
19253 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19254 memory_info.pNext = NULL;
19255 memory_info.allocationSize = 0;
19256 memory_info.memoryTypeIndex = 0;
19257 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19258 // Find an image big enough to allow sparse mapping of 2 memory regions
19259 // Increase the image size until it is at least twice the
19260 // size of the required alignment, to ensure we can bind both
19261 // allocated memory blocks to the image on aligned offsets.
19262 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19263 vkDestroyImage(m_device->device(), image, nullptr);
19264 image_create_info.extent.width *= 2;
19265 image_create_info.extent.height *= 2;
19266 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19267 ASSERT_VK_SUCCESS(err);
19268 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19269 }
19270 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19271 // at the end of the first
19272 memory_info.allocationSize = memory_reqs.alignment;
19273 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19274 ASSERT_TRUE(pass);
19275 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19276 ASSERT_VK_SUCCESS(err);
19277 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19278 ASSERT_VK_SUCCESS(err);
19279 VkSparseMemoryBind binds[2];
19280 binds[0].flags = 0;
19281 binds[0].memory = memory_one;
19282 binds[0].memoryOffset = 0;
19283 binds[0].resourceOffset = 0;
19284 binds[0].size = memory_info.allocationSize;
19285 binds[1].flags = 0;
19286 binds[1].memory = memory_two;
19287 binds[1].memoryOffset = 0;
19288 binds[1].resourceOffset = memory_info.allocationSize;
19289 binds[1].size = memory_info.allocationSize;
19290
19291 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19292 opaqueBindInfo.image = image;
19293 opaqueBindInfo.bindCount = 2;
19294 opaqueBindInfo.pBinds = binds;
19295
19296 VkFence fence = VK_NULL_HANDLE;
19297 VkBindSparseInfo bindSparseInfo = {};
19298 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19299 bindSparseInfo.imageOpaqueBindCount = 1;
19300 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19301
19302 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19303 vkQueueWaitIdle(m_device->m_queue);
19304 vkDestroyImage(m_device->device(), image, NULL);
19305 vkFreeMemory(m_device->device(), memory_one, NULL);
19306 vkFreeMemory(m_device->device(), memory_two, NULL);
19307 m_errorMonitor->VerifyNotFound();
19308}
19309
19310TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019311 TEST_DESCRIPTION(
19312 "Ensure that CmdBeginRenderPass with an attachment's "
19313 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19314 "the command buffer has prior knowledge of that "
19315 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019316
19317 m_errorMonitor->ExpectSuccess();
19318
19319 ASSERT_NO_FATAL_FAILURE(InitState());
19320
19321 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019322 VkAttachmentDescription attachment = {0,
19323 VK_FORMAT_R8G8B8A8_UNORM,
19324 VK_SAMPLE_COUNT_1_BIT,
19325 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19326 VK_ATTACHMENT_STORE_OP_STORE,
19327 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19328 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19329 VK_IMAGE_LAYOUT_UNDEFINED,
19330 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019331
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019332 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019333
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019334 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019335
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019336 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019337
19338 VkRenderPass rp;
19339 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19340 ASSERT_VK_SUCCESS(err);
19341
19342 // A compatible framebuffer.
19343 VkImageObj image(m_device);
19344 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19345 ASSERT_TRUE(image.initialized());
19346
19347 VkImageViewCreateInfo ivci = {
19348 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19349 nullptr,
19350 0,
19351 image.handle(),
19352 VK_IMAGE_VIEW_TYPE_2D,
19353 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019354 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19355 VK_COMPONENT_SWIZZLE_IDENTITY},
19356 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019357 };
19358 VkImageView view;
19359 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19360 ASSERT_VK_SUCCESS(err);
19361
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019362 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019363 VkFramebuffer fb;
19364 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19365 ASSERT_VK_SUCCESS(err);
19366
19367 // Record a single command buffer which uses this renderpass twice. The
19368 // bug is triggered at the beginning of the second renderpass, when the
19369 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019370 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 -070019371 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019372 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19373 vkCmdEndRenderPass(m_commandBuffer->handle());
19374 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19375
19376 m_errorMonitor->VerifyNotFound();
19377
19378 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019379 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019380
19381 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19382 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19383 vkDestroyImageView(m_device->device(), view, nullptr);
19384}
19385
19386TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019387 TEST_DESCRIPTION(
19388 "This test should pass. Create a Framebuffer and "
19389 "command buffer, bind them together, then destroy "
19390 "command pool and framebuffer and verify there are no "
19391 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019392
19393 m_errorMonitor->ExpectSuccess();
19394
19395 ASSERT_NO_FATAL_FAILURE(InitState());
19396
19397 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019398 VkAttachmentDescription attachment = {0,
19399 VK_FORMAT_R8G8B8A8_UNORM,
19400 VK_SAMPLE_COUNT_1_BIT,
19401 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19402 VK_ATTACHMENT_STORE_OP_STORE,
19403 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19404 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19405 VK_IMAGE_LAYOUT_UNDEFINED,
19406 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019407
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019408 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019410 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019411
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019412 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019413
19414 VkRenderPass rp;
19415 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19416 ASSERT_VK_SUCCESS(err);
19417
19418 // A compatible framebuffer.
19419 VkImageObj image(m_device);
19420 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19421 ASSERT_TRUE(image.initialized());
19422
19423 VkImageViewCreateInfo ivci = {
19424 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19425 nullptr,
19426 0,
19427 image.handle(),
19428 VK_IMAGE_VIEW_TYPE_2D,
19429 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019430 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19431 VK_COMPONENT_SWIZZLE_IDENTITY},
19432 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019433 };
19434 VkImageView view;
19435 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19436 ASSERT_VK_SUCCESS(err);
19437
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019438 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019439 VkFramebuffer fb;
19440 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19441 ASSERT_VK_SUCCESS(err);
19442
19443 // Explicitly create a command buffer to bind the FB to so that we can then
19444 // destroy the command pool in order to implicitly free command buffer
19445 VkCommandPool command_pool;
19446 VkCommandPoolCreateInfo pool_create_info{};
19447 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19448 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19449 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19450 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19451
19452 VkCommandBuffer command_buffer;
19453 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19454 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19455 command_buffer_allocate_info.commandPool = command_pool;
19456 command_buffer_allocate_info.commandBufferCount = 1;
19457 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19458 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19459
19460 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019461 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 -060019462 VkCommandBufferBeginInfo begin_info{};
19463 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19464 vkBeginCommandBuffer(command_buffer, &begin_info);
19465
19466 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19467 vkCmdEndRenderPass(command_buffer);
19468 vkEndCommandBuffer(command_buffer);
19469 vkDestroyImageView(m_device->device(), view, nullptr);
19470 // Destroy command pool to implicitly free command buffer
19471 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19472 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19473 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19474 m_errorMonitor->VerifyNotFound();
19475}
19476
19477TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019478 TEST_DESCRIPTION(
19479 "Ensure that CmdBeginRenderPass applies the layout "
19480 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019481
19482 m_errorMonitor->ExpectSuccess();
19483
19484 ASSERT_NO_FATAL_FAILURE(InitState());
19485
19486 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019487 VkAttachmentDescription attachment = {0,
19488 VK_FORMAT_R8G8B8A8_UNORM,
19489 VK_SAMPLE_COUNT_1_BIT,
19490 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19491 VK_ATTACHMENT_STORE_OP_STORE,
19492 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19493 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19494 VK_IMAGE_LAYOUT_UNDEFINED,
19495 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019496
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019497 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019498
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019499 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019500
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019501 VkSubpassDependency dep = {0,
19502 0,
19503 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19504 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19505 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19506 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19507 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019508
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019509 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019510
19511 VkResult err;
19512 VkRenderPass rp;
19513 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19514 ASSERT_VK_SUCCESS(err);
19515
19516 // A compatible framebuffer.
19517 VkImageObj image(m_device);
19518 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19519 ASSERT_TRUE(image.initialized());
19520
19521 VkImageViewCreateInfo ivci = {
19522 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19523 nullptr,
19524 0,
19525 image.handle(),
19526 VK_IMAGE_VIEW_TYPE_2D,
19527 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019528 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19529 VK_COMPONENT_SWIZZLE_IDENTITY},
19530 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019531 };
19532 VkImageView view;
19533 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19534 ASSERT_VK_SUCCESS(err);
19535
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019536 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019537 VkFramebuffer fb;
19538 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19539 ASSERT_VK_SUCCESS(err);
19540
19541 // Record a single command buffer which issues a pipeline barrier w/
19542 // image memory barrier for the attachment. This detects the previously
19543 // missing tracking of the subpass layout by throwing a validation error
19544 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019545 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 -070019546 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019547 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19548
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019549 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19550 nullptr,
19551 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19552 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19553 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19554 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19555 VK_QUEUE_FAMILY_IGNORED,
19556 VK_QUEUE_FAMILY_IGNORED,
19557 image.handle(),
19558 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019559 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019560 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19561 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019562
19563 vkCmdEndRenderPass(m_commandBuffer->handle());
19564 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019565 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019566
19567 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19568 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19569 vkDestroyImageView(m_device->device(), view, nullptr);
19570}
19571
19572TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019573 TEST_DESCRIPTION(
19574 "Validate that when an imageView of a depth/stencil image "
19575 "is used as a depth/stencil framebuffer attachment, the "
19576 "aspectMask is ignored and both depth and stencil image "
19577 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019578
19579 VkFormatProperties format_properties;
19580 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19581 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19582 return;
19583 }
19584
19585 m_errorMonitor->ExpectSuccess();
19586
19587 ASSERT_NO_FATAL_FAILURE(InitState());
19588
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019589 VkAttachmentDescription attachment = {0,
19590 VK_FORMAT_D32_SFLOAT_S8_UINT,
19591 VK_SAMPLE_COUNT_1_BIT,
19592 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19593 VK_ATTACHMENT_STORE_OP_STORE,
19594 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19595 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19596 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19597 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019598
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019599 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019600
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019601 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019602
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019603 VkSubpassDependency dep = {0,
19604 0,
19605 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19606 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19607 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19608 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19609 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019610
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019611 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019612
19613 VkResult err;
19614 VkRenderPass rp;
19615 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19616 ASSERT_VK_SUCCESS(err);
19617
19618 VkImageObj image(m_device);
19619 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019620 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019621 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019622 ASSERT_TRUE(image.initialized());
19623 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19624
19625 VkImageViewCreateInfo ivci = {
19626 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19627 nullptr,
19628 0,
19629 image.handle(),
19630 VK_IMAGE_VIEW_TYPE_2D,
19631 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019632 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19633 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019634 };
19635 VkImageView view;
19636 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19637 ASSERT_VK_SUCCESS(err);
19638
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019639 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019640 VkFramebuffer fb;
19641 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19642 ASSERT_VK_SUCCESS(err);
19643
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019644 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 -070019645 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019646 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19647
19648 VkImageMemoryBarrier imb = {};
19649 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19650 imb.pNext = nullptr;
19651 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19652 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19653 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19654 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19655 imb.srcQueueFamilyIndex = 0;
19656 imb.dstQueueFamilyIndex = 0;
19657 imb.image = image.handle();
19658 imb.subresourceRange.aspectMask = 0x6;
19659 imb.subresourceRange.baseMipLevel = 0;
19660 imb.subresourceRange.levelCount = 0x1;
19661 imb.subresourceRange.baseArrayLayer = 0;
19662 imb.subresourceRange.layerCount = 0x1;
19663
19664 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019665 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19666 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019667
19668 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019669 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019670 QueueCommandBuffer(false);
19671 m_errorMonitor->VerifyNotFound();
19672
19673 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19674 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19675 vkDestroyImageView(m_device->device(), view, nullptr);
19676}
19677
19678TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019679 TEST_DESCRIPTION(
19680 "Ensure that layout transitions work correctly without "
19681 "errors, when an attachment reference is "
19682 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019683
19684 m_errorMonitor->ExpectSuccess();
19685
19686 ASSERT_NO_FATAL_FAILURE(InitState());
19687
19688 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019689 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019690
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019691 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019692
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019693 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019694
19695 VkRenderPass rp;
19696 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19697 ASSERT_VK_SUCCESS(err);
19698
19699 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019700 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019701 VkFramebuffer fb;
19702 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19703 ASSERT_VK_SUCCESS(err);
19704
19705 // Record a command buffer which just begins and ends the renderpass. The
19706 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019707 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 -070019708 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019709 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19710 vkCmdEndRenderPass(m_commandBuffer->handle());
19711 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019712 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019713
19714 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19715 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19716}
19717
19718// This is a positive test. No errors are expected.
19719TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019720 TEST_DESCRIPTION(
19721 "Create a stencil-only attachment with a LOAD_OP set to "
19722 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019723 VkResult result = VK_SUCCESS;
19724 VkImageFormatProperties formatProps;
19725 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019726 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19727 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019728 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19729 return;
19730 }
19731
19732 ASSERT_NO_FATAL_FAILURE(InitState());
19733 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19734 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019735 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019736 VkAttachmentDescription att = {};
19737 VkAttachmentReference ref = {};
19738 att.format = depth_stencil_fmt;
19739 att.samples = VK_SAMPLE_COUNT_1_BIT;
19740 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19741 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19742 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19743 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19744 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19745 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19746
19747 VkClearValue clear;
19748 clear.depthStencil.depth = 1.0;
19749 clear.depthStencil.stencil = 0;
19750 ref.attachment = 0;
19751 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19752
19753 VkSubpassDescription subpass = {};
19754 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19755 subpass.flags = 0;
19756 subpass.inputAttachmentCount = 0;
19757 subpass.pInputAttachments = NULL;
19758 subpass.colorAttachmentCount = 0;
19759 subpass.pColorAttachments = NULL;
19760 subpass.pResolveAttachments = NULL;
19761 subpass.pDepthStencilAttachment = &ref;
19762 subpass.preserveAttachmentCount = 0;
19763 subpass.pPreserveAttachments = NULL;
19764
19765 VkRenderPass rp;
19766 VkRenderPassCreateInfo rp_info = {};
19767 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19768 rp_info.attachmentCount = 1;
19769 rp_info.pAttachments = &att;
19770 rp_info.subpassCount = 1;
19771 rp_info.pSubpasses = &subpass;
19772 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19773 ASSERT_VK_SUCCESS(result);
19774
19775 VkImageView *depthView = m_depthStencil->BindInfo();
19776 VkFramebufferCreateInfo fb_info = {};
19777 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19778 fb_info.pNext = NULL;
19779 fb_info.renderPass = rp;
19780 fb_info.attachmentCount = 1;
19781 fb_info.pAttachments = depthView;
19782 fb_info.width = 100;
19783 fb_info.height = 100;
19784 fb_info.layers = 1;
19785 VkFramebuffer fb;
19786 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19787 ASSERT_VK_SUCCESS(result);
19788
19789 VkRenderPassBeginInfo rpbinfo = {};
19790 rpbinfo.clearValueCount = 1;
19791 rpbinfo.pClearValues = &clear;
19792 rpbinfo.pNext = NULL;
19793 rpbinfo.renderPass = rp;
19794 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19795 rpbinfo.renderArea.extent.width = 100;
19796 rpbinfo.renderArea.extent.height = 100;
19797 rpbinfo.renderArea.offset.x = 0;
19798 rpbinfo.renderArea.offset.y = 0;
19799 rpbinfo.framebuffer = fb;
19800
19801 VkFence fence = {};
19802 VkFenceCreateInfo fence_ci = {};
19803 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19804 fence_ci.pNext = nullptr;
19805 fence_ci.flags = 0;
19806 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19807 ASSERT_VK_SUCCESS(result);
19808
19809 m_commandBuffer->BeginCommandBuffer();
19810 m_commandBuffer->BeginRenderPass(rpbinfo);
19811 m_commandBuffer->EndRenderPass();
19812 m_commandBuffer->EndCommandBuffer();
19813 m_commandBuffer->QueueCommandBuffer(fence);
19814
19815 VkImageObj destImage(m_device);
19816 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 -070019817 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019818 VkImageMemoryBarrier barrier = {};
19819 VkImageSubresourceRange range;
19820 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19821 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19822 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19823 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19824 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19825 barrier.image = m_depthStencil->handle();
19826 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19827 range.baseMipLevel = 0;
19828 range.levelCount = 1;
19829 range.baseArrayLayer = 0;
19830 range.layerCount = 1;
19831 barrier.subresourceRange = range;
19832 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19833 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19834 cmdbuf.BeginCommandBuffer();
19835 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 -070019836 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019837 barrier.srcAccessMask = 0;
19838 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19839 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19840 barrier.image = destImage.handle();
19841 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19842 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 -070019843 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019844 VkImageCopy cregion;
19845 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19846 cregion.srcSubresource.mipLevel = 0;
19847 cregion.srcSubresource.baseArrayLayer = 0;
19848 cregion.srcSubresource.layerCount = 1;
19849 cregion.srcOffset.x = 0;
19850 cregion.srcOffset.y = 0;
19851 cregion.srcOffset.z = 0;
19852 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19853 cregion.dstSubresource.mipLevel = 0;
19854 cregion.dstSubresource.baseArrayLayer = 0;
19855 cregion.dstSubresource.layerCount = 1;
19856 cregion.dstOffset.x = 0;
19857 cregion.dstOffset.y = 0;
19858 cregion.dstOffset.z = 0;
19859 cregion.extent.width = 100;
19860 cregion.extent.height = 100;
19861 cregion.extent.depth = 1;
19862 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019863 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019864 cmdbuf.EndCommandBuffer();
19865
19866 VkSubmitInfo submit_info;
19867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19868 submit_info.pNext = NULL;
19869 submit_info.waitSemaphoreCount = 0;
19870 submit_info.pWaitSemaphores = NULL;
19871 submit_info.pWaitDstStageMask = NULL;
19872 submit_info.commandBufferCount = 1;
19873 submit_info.pCommandBuffers = &cmdbuf.handle();
19874 submit_info.signalSemaphoreCount = 0;
19875 submit_info.pSignalSemaphores = NULL;
19876
19877 m_errorMonitor->ExpectSuccess();
19878 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19879 m_errorMonitor->VerifyNotFound();
19880
19881 vkQueueWaitIdle(m_device->m_queue);
19882 vkDestroyFence(m_device->device(), fence, nullptr);
19883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19884 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19885}
19886
19887// This is a positive test. No errors should be generated.
19888TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19889 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19890
19891 m_errorMonitor->ExpectSuccess();
19892 ASSERT_NO_FATAL_FAILURE(InitState());
19893
19894 VkEvent event;
19895 VkEventCreateInfo event_create_info{};
19896 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19897 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19898
19899 VkCommandPool command_pool;
19900 VkCommandPoolCreateInfo pool_create_info{};
19901 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19902 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19903 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19904 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19905
19906 VkCommandBuffer command_buffer;
19907 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19908 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19909 command_buffer_allocate_info.commandPool = command_pool;
19910 command_buffer_allocate_info.commandBufferCount = 1;
19911 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19912 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19913
19914 VkQueue queue = VK_NULL_HANDLE;
19915 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19916
19917 {
19918 VkCommandBufferBeginInfo begin_info{};
19919 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19920 vkBeginCommandBuffer(command_buffer, &begin_info);
19921
19922 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 -070019923 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019924 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19925 vkEndCommandBuffer(command_buffer);
19926 }
19927 {
19928 VkSubmitInfo submit_info{};
19929 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19930 submit_info.commandBufferCount = 1;
19931 submit_info.pCommandBuffers = &command_buffer;
19932 submit_info.signalSemaphoreCount = 0;
19933 submit_info.pSignalSemaphores = nullptr;
19934 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19935 }
19936 { vkSetEvent(m_device->device(), event); }
19937
19938 vkQueueWaitIdle(queue);
19939
19940 vkDestroyEvent(m_device->device(), event, nullptr);
19941 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19942 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19943
19944 m_errorMonitor->VerifyNotFound();
19945}
19946// This is a positive test. No errors should be generated.
19947TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19948 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19949
19950 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019951 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019952
19953 m_errorMonitor->ExpectSuccess();
19954
19955 VkQueryPool query_pool;
19956 VkQueryPoolCreateInfo query_pool_create_info{};
19957 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19958 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19959 query_pool_create_info.queryCount = 1;
19960 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19961
19962 VkCommandPool command_pool;
19963 VkCommandPoolCreateInfo pool_create_info{};
19964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19968
19969 VkCommandBuffer command_buffer;
19970 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19971 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19972 command_buffer_allocate_info.commandPool = command_pool;
19973 command_buffer_allocate_info.commandBufferCount = 1;
19974 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19975 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19976
19977 VkCommandBuffer secondary_command_buffer;
19978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19980
19981 VkQueue queue = VK_NULL_HANDLE;
19982 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19983
19984 uint32_t qfi = 0;
19985 VkBufferCreateInfo buff_create_info = {};
19986 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19987 buff_create_info.size = 1024;
19988 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19989 buff_create_info.queueFamilyIndexCount = 1;
19990 buff_create_info.pQueueFamilyIndices = &qfi;
19991
19992 VkResult err;
19993 VkBuffer buffer;
19994 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19995 ASSERT_VK_SUCCESS(err);
19996 VkMemoryAllocateInfo mem_alloc = {};
19997 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19998 mem_alloc.pNext = NULL;
19999 mem_alloc.allocationSize = 1024;
20000 mem_alloc.memoryTypeIndex = 0;
20001
20002 VkMemoryRequirements memReqs;
20003 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20004 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20005 if (!pass) {
20006 vkDestroyBuffer(m_device->device(), buffer, NULL);
20007 return;
20008 }
20009
20010 VkDeviceMemory mem;
20011 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20012 ASSERT_VK_SUCCESS(err);
20013 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20014 ASSERT_VK_SUCCESS(err);
20015
20016 VkCommandBufferInheritanceInfo hinfo = {};
20017 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20018 hinfo.renderPass = VK_NULL_HANDLE;
20019 hinfo.subpass = 0;
20020 hinfo.framebuffer = VK_NULL_HANDLE;
20021 hinfo.occlusionQueryEnable = VK_FALSE;
20022 hinfo.queryFlags = 0;
20023 hinfo.pipelineStatistics = 0;
20024
20025 {
20026 VkCommandBufferBeginInfo begin_info{};
20027 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20028 begin_info.pInheritanceInfo = &hinfo;
20029 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20030
20031 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20032 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20033
20034 vkEndCommandBuffer(secondary_command_buffer);
20035
20036 begin_info.pInheritanceInfo = nullptr;
20037 vkBeginCommandBuffer(command_buffer, &begin_info);
20038
20039 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20040 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20041
20042 vkEndCommandBuffer(command_buffer);
20043 }
20044 {
20045 VkSubmitInfo submit_info{};
20046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20047 submit_info.commandBufferCount = 1;
20048 submit_info.pCommandBuffers = &command_buffer;
20049 submit_info.signalSemaphoreCount = 0;
20050 submit_info.pSignalSemaphores = nullptr;
20051 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20052 }
20053
20054 vkQueueWaitIdle(queue);
20055
20056 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20057 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20058 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20059 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20060 vkDestroyBuffer(m_device->device(), buffer, NULL);
20061 vkFreeMemory(m_device->device(), mem, NULL);
20062
20063 m_errorMonitor->VerifyNotFound();
20064}
20065
20066// This is a positive test. No errors should be generated.
20067TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20068 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20069
20070 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020071 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020072
20073 m_errorMonitor->ExpectSuccess();
20074
20075 VkQueryPool query_pool;
20076 VkQueryPoolCreateInfo query_pool_create_info{};
20077 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20078 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20079 query_pool_create_info.queryCount = 1;
20080 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20081
20082 VkCommandPool command_pool;
20083 VkCommandPoolCreateInfo pool_create_info{};
20084 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20085 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20086 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20087 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20088
20089 VkCommandBuffer command_buffer[2];
20090 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20091 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20092 command_buffer_allocate_info.commandPool = command_pool;
20093 command_buffer_allocate_info.commandBufferCount = 2;
20094 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20095 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20096
20097 VkQueue queue = VK_NULL_HANDLE;
20098 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20099
20100 uint32_t qfi = 0;
20101 VkBufferCreateInfo buff_create_info = {};
20102 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20103 buff_create_info.size = 1024;
20104 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20105 buff_create_info.queueFamilyIndexCount = 1;
20106 buff_create_info.pQueueFamilyIndices = &qfi;
20107
20108 VkResult err;
20109 VkBuffer buffer;
20110 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20111 ASSERT_VK_SUCCESS(err);
20112 VkMemoryAllocateInfo mem_alloc = {};
20113 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20114 mem_alloc.pNext = NULL;
20115 mem_alloc.allocationSize = 1024;
20116 mem_alloc.memoryTypeIndex = 0;
20117
20118 VkMemoryRequirements memReqs;
20119 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20120 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20121 if (!pass) {
20122 vkDestroyBuffer(m_device->device(), buffer, NULL);
20123 return;
20124 }
20125
20126 VkDeviceMemory mem;
20127 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20128 ASSERT_VK_SUCCESS(err);
20129 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20130 ASSERT_VK_SUCCESS(err);
20131
20132 {
20133 VkCommandBufferBeginInfo begin_info{};
20134 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20135 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20136
20137 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20138 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20139
20140 vkEndCommandBuffer(command_buffer[0]);
20141
20142 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20143
20144 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20145
20146 vkEndCommandBuffer(command_buffer[1]);
20147 }
20148 {
20149 VkSubmitInfo submit_info{};
20150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20151 submit_info.commandBufferCount = 2;
20152 submit_info.pCommandBuffers = command_buffer;
20153 submit_info.signalSemaphoreCount = 0;
20154 submit_info.pSignalSemaphores = nullptr;
20155 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20156 }
20157
20158 vkQueueWaitIdle(queue);
20159
20160 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20161 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20162 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20163 vkDestroyBuffer(m_device->device(), buffer, NULL);
20164 vkFreeMemory(m_device->device(), mem, NULL);
20165
20166 m_errorMonitor->VerifyNotFound();
20167}
20168
Tony Barbourc46924f2016-11-04 11:49:52 -060020169TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020170 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20171
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020172 ASSERT_NO_FATAL_FAILURE(InitState());
20173 VkEvent event;
20174 VkEventCreateInfo event_create_info{};
20175 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20176 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20177
20178 VkCommandPool command_pool;
20179 VkCommandPoolCreateInfo pool_create_info{};
20180 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20181 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20182 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20183 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20184
20185 VkCommandBuffer command_buffer;
20186 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20187 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20188 command_buffer_allocate_info.commandPool = command_pool;
20189 command_buffer_allocate_info.commandBufferCount = 1;
20190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20191 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20192
20193 VkQueue queue = VK_NULL_HANDLE;
20194 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20195
20196 {
20197 VkCommandBufferBeginInfo begin_info{};
20198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20199 vkBeginCommandBuffer(command_buffer, &begin_info);
20200
20201 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 vkEndCommandBuffer(command_buffer);
20203 }
20204 {
20205 VkSubmitInfo submit_info{};
20206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20207 submit_info.commandBufferCount = 1;
20208 submit_info.pCommandBuffers = &command_buffer;
20209 submit_info.signalSemaphoreCount = 0;
20210 submit_info.pSignalSemaphores = nullptr;
20211 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20212 }
20213 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20215 "that is already in use by a "
20216 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020217 vkSetEvent(m_device->device(), event);
20218 m_errorMonitor->VerifyFound();
20219 }
20220
20221 vkQueueWaitIdle(queue);
20222
20223 vkDestroyEvent(m_device->device(), event, nullptr);
20224 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20225 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20226}
20227
20228// This is a positive test. No errors should be generated.
20229TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020230 TEST_DESCRIPTION(
20231 "Two command buffers with two separate fences are each "
20232 "run through a Submit & WaitForFences cycle 3 times. This "
20233 "previously revealed a bug so running this positive test "
20234 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020235 m_errorMonitor->ExpectSuccess();
20236
20237 ASSERT_NO_FATAL_FAILURE(InitState());
20238 VkQueue queue = VK_NULL_HANDLE;
20239 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20240
20241 static const uint32_t NUM_OBJECTS = 2;
20242 static const uint32_t NUM_FRAMES = 3;
20243 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20244 VkFence fences[NUM_OBJECTS] = {};
20245
20246 VkCommandPool cmd_pool;
20247 VkCommandPoolCreateInfo cmd_pool_ci = {};
20248 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20249 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20250 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20251 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20252 ASSERT_VK_SUCCESS(err);
20253
20254 VkCommandBufferAllocateInfo cmd_buf_info = {};
20255 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20256 cmd_buf_info.commandPool = cmd_pool;
20257 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20258 cmd_buf_info.commandBufferCount = 1;
20259
20260 VkFenceCreateInfo fence_ci = {};
20261 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20262 fence_ci.pNext = nullptr;
20263 fence_ci.flags = 0;
20264
20265 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20266 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20267 ASSERT_VK_SUCCESS(err);
20268 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20269 ASSERT_VK_SUCCESS(err);
20270 }
20271
20272 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20273 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20274 // Create empty cmd buffer
20275 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20276 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20277
20278 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20279 ASSERT_VK_SUCCESS(err);
20280 err = vkEndCommandBuffer(cmd_buffers[obj]);
20281 ASSERT_VK_SUCCESS(err);
20282
20283 VkSubmitInfo submit_info = {};
20284 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20285 submit_info.commandBufferCount = 1;
20286 submit_info.pCommandBuffers = &cmd_buffers[obj];
20287 // Submit cmd buffer and wait for fence
20288 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20289 ASSERT_VK_SUCCESS(err);
20290 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20291 ASSERT_VK_SUCCESS(err);
20292 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20293 ASSERT_VK_SUCCESS(err);
20294 }
20295 }
20296 m_errorMonitor->VerifyNotFound();
20297 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20298 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20299 vkDestroyFence(m_device->device(), fences[i], nullptr);
20300 }
20301}
20302// This is a positive test. No errors should be generated.
20303TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020304 TEST_DESCRIPTION(
20305 "Two command buffers, each in a separate QueueSubmit call "
20306 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020307
20308 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020309 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020310
20311 m_errorMonitor->ExpectSuccess();
20312
20313 VkSemaphore semaphore;
20314 VkSemaphoreCreateInfo semaphore_create_info{};
20315 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20316 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20317
20318 VkCommandPool command_pool;
20319 VkCommandPoolCreateInfo pool_create_info{};
20320 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20321 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20322 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20323 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20324
20325 VkCommandBuffer command_buffer[2];
20326 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20327 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20328 command_buffer_allocate_info.commandPool = command_pool;
20329 command_buffer_allocate_info.commandBufferCount = 2;
20330 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20331 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20332
20333 VkQueue queue = VK_NULL_HANDLE;
20334 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20335
20336 {
20337 VkCommandBufferBeginInfo begin_info{};
20338 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20339 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20340
20341 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 -070020342 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020343
20344 VkViewport viewport{};
20345 viewport.maxDepth = 1.0f;
20346 viewport.minDepth = 0.0f;
20347 viewport.width = 512;
20348 viewport.height = 512;
20349 viewport.x = 0;
20350 viewport.y = 0;
20351 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20352 vkEndCommandBuffer(command_buffer[0]);
20353 }
20354 {
20355 VkCommandBufferBeginInfo begin_info{};
20356 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20357 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20358
20359 VkViewport viewport{};
20360 viewport.maxDepth = 1.0f;
20361 viewport.minDepth = 0.0f;
20362 viewport.width = 512;
20363 viewport.height = 512;
20364 viewport.x = 0;
20365 viewport.y = 0;
20366 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20367 vkEndCommandBuffer(command_buffer[1]);
20368 }
20369 {
20370 VkSubmitInfo submit_info{};
20371 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20372 submit_info.commandBufferCount = 1;
20373 submit_info.pCommandBuffers = &command_buffer[0];
20374 submit_info.signalSemaphoreCount = 1;
20375 submit_info.pSignalSemaphores = &semaphore;
20376 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20377 }
20378 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020379 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020380 VkSubmitInfo submit_info{};
20381 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20382 submit_info.commandBufferCount = 1;
20383 submit_info.pCommandBuffers = &command_buffer[1];
20384 submit_info.waitSemaphoreCount = 1;
20385 submit_info.pWaitSemaphores = &semaphore;
20386 submit_info.pWaitDstStageMask = flags;
20387 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20388 }
20389
20390 vkQueueWaitIdle(m_device->m_queue);
20391
20392 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20393 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20394 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20395
20396 m_errorMonitor->VerifyNotFound();
20397}
20398
20399// This is a positive test. No errors should be generated.
20400TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020401 TEST_DESCRIPTION(
20402 "Two command buffers, each in a separate QueueSubmit call "
20403 "submitted on separate queues, the second having a fence"
20404 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020405
20406 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020407 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020408
20409 m_errorMonitor->ExpectSuccess();
20410
20411 VkFence fence;
20412 VkFenceCreateInfo fence_create_info{};
20413 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20414 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20415
20416 VkSemaphore semaphore;
20417 VkSemaphoreCreateInfo semaphore_create_info{};
20418 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20419 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20420
20421 VkCommandPool command_pool;
20422 VkCommandPoolCreateInfo pool_create_info{};
20423 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20424 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20425 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20426 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20427
20428 VkCommandBuffer command_buffer[2];
20429 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20430 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20431 command_buffer_allocate_info.commandPool = command_pool;
20432 command_buffer_allocate_info.commandBufferCount = 2;
20433 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20434 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20435
20436 VkQueue queue = VK_NULL_HANDLE;
20437 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20438
20439 {
20440 VkCommandBufferBeginInfo begin_info{};
20441 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20442 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20443
20444 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 -070020445 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020446
20447 VkViewport viewport{};
20448 viewport.maxDepth = 1.0f;
20449 viewport.minDepth = 0.0f;
20450 viewport.width = 512;
20451 viewport.height = 512;
20452 viewport.x = 0;
20453 viewport.y = 0;
20454 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20455 vkEndCommandBuffer(command_buffer[0]);
20456 }
20457 {
20458 VkCommandBufferBeginInfo begin_info{};
20459 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20460 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20461
20462 VkViewport viewport{};
20463 viewport.maxDepth = 1.0f;
20464 viewport.minDepth = 0.0f;
20465 viewport.width = 512;
20466 viewport.height = 512;
20467 viewport.x = 0;
20468 viewport.y = 0;
20469 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20470 vkEndCommandBuffer(command_buffer[1]);
20471 }
20472 {
20473 VkSubmitInfo submit_info{};
20474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20475 submit_info.commandBufferCount = 1;
20476 submit_info.pCommandBuffers = &command_buffer[0];
20477 submit_info.signalSemaphoreCount = 1;
20478 submit_info.pSignalSemaphores = &semaphore;
20479 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20480 }
20481 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020482 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020483 VkSubmitInfo submit_info{};
20484 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20485 submit_info.commandBufferCount = 1;
20486 submit_info.pCommandBuffers = &command_buffer[1];
20487 submit_info.waitSemaphoreCount = 1;
20488 submit_info.pWaitSemaphores = &semaphore;
20489 submit_info.pWaitDstStageMask = flags;
20490 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20491 }
20492
20493 vkQueueWaitIdle(m_device->m_queue);
20494
20495 vkDestroyFence(m_device->device(), fence, nullptr);
20496 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20497 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20498 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20499
20500 m_errorMonitor->VerifyNotFound();
20501}
20502
20503// This is a positive test. No errors should be generated.
20504TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020505 TEST_DESCRIPTION(
20506 "Two command buffers, each in a separate QueueSubmit call "
20507 "submitted on separate queues, the second having a fence"
20508 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020509
20510 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020511 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020512
20513 m_errorMonitor->ExpectSuccess();
20514
20515 VkFence fence;
20516 VkFenceCreateInfo fence_create_info{};
20517 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20518 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20519
20520 VkSemaphore semaphore;
20521 VkSemaphoreCreateInfo semaphore_create_info{};
20522 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20523 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20524
20525 VkCommandPool command_pool;
20526 VkCommandPoolCreateInfo pool_create_info{};
20527 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20528 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20529 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20530 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20531
20532 VkCommandBuffer command_buffer[2];
20533 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20534 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20535 command_buffer_allocate_info.commandPool = command_pool;
20536 command_buffer_allocate_info.commandBufferCount = 2;
20537 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20538 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20539
20540 VkQueue queue = VK_NULL_HANDLE;
20541 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20542
20543 {
20544 VkCommandBufferBeginInfo begin_info{};
20545 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20546 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20547
20548 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 -070020549 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020550
20551 VkViewport viewport{};
20552 viewport.maxDepth = 1.0f;
20553 viewport.minDepth = 0.0f;
20554 viewport.width = 512;
20555 viewport.height = 512;
20556 viewport.x = 0;
20557 viewport.y = 0;
20558 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20559 vkEndCommandBuffer(command_buffer[0]);
20560 }
20561 {
20562 VkCommandBufferBeginInfo begin_info{};
20563 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20564 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20565
20566 VkViewport viewport{};
20567 viewport.maxDepth = 1.0f;
20568 viewport.minDepth = 0.0f;
20569 viewport.width = 512;
20570 viewport.height = 512;
20571 viewport.x = 0;
20572 viewport.y = 0;
20573 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20574 vkEndCommandBuffer(command_buffer[1]);
20575 }
20576 {
20577 VkSubmitInfo submit_info{};
20578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20579 submit_info.commandBufferCount = 1;
20580 submit_info.pCommandBuffers = &command_buffer[0];
20581 submit_info.signalSemaphoreCount = 1;
20582 submit_info.pSignalSemaphores = &semaphore;
20583 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20584 }
20585 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020586 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020587 VkSubmitInfo submit_info{};
20588 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20589 submit_info.commandBufferCount = 1;
20590 submit_info.pCommandBuffers = &command_buffer[1];
20591 submit_info.waitSemaphoreCount = 1;
20592 submit_info.pWaitSemaphores = &semaphore;
20593 submit_info.pWaitDstStageMask = flags;
20594 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20595 }
20596
20597 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20598 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20599
20600 vkDestroyFence(m_device->device(), fence, nullptr);
20601 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20602 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20603 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20604
20605 m_errorMonitor->VerifyNotFound();
20606}
20607
20608TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020609 ASSERT_NO_FATAL_FAILURE(InitState());
20610 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020611 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020612 return;
20613 }
20614
20615 VkResult err;
20616
20617 m_errorMonitor->ExpectSuccess();
20618
20619 VkQueue q0 = m_device->m_queue;
20620 VkQueue q1 = nullptr;
20621 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20622 ASSERT_NE(q1, nullptr);
20623
20624 // An (empty) command buffer. We must have work in the first submission --
20625 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020626 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020627 VkCommandPool pool;
20628 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20629 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020630 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20631 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020632 VkCommandBuffer cb;
20633 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20634 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020635 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020636 err = vkBeginCommandBuffer(cb, &cbbi);
20637 ASSERT_VK_SUCCESS(err);
20638 err = vkEndCommandBuffer(cb);
20639 ASSERT_VK_SUCCESS(err);
20640
20641 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020642 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020643 VkSemaphore s;
20644 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20645 ASSERT_VK_SUCCESS(err);
20646
20647 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020648 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020649
20650 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20651 ASSERT_VK_SUCCESS(err);
20652
20653 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020654 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020655 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020656
20657 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20658 ASSERT_VK_SUCCESS(err);
20659
20660 // Wait for q0 idle
20661 err = vkQueueWaitIdle(q0);
20662 ASSERT_VK_SUCCESS(err);
20663
20664 // Command buffer should have been completed (it was on q0); reset the pool.
20665 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20666
20667 m_errorMonitor->VerifyNotFound();
20668
20669 // Force device completely idle and clean up resources
20670 vkDeviceWaitIdle(m_device->device());
20671 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20672 vkDestroySemaphore(m_device->device(), s, nullptr);
20673}
20674
20675// This is a positive test. No errors should be generated.
20676TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
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 WaitForFences call.");
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 ASSERT_NO_FATAL_FAILURE(InitState());
20688 VkFence fence;
20689 VkFenceCreateInfo fence_create_info{};
20690 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20691 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20692
20693 VkSemaphore semaphore;
20694 VkSemaphoreCreateInfo semaphore_create_info{};
20695 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20696 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20697
20698 VkCommandPool command_pool;
20699 VkCommandPoolCreateInfo pool_create_info{};
20700 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20701 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20702 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20703 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20704
20705 VkCommandBuffer command_buffer[2];
20706 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20707 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20708 command_buffer_allocate_info.commandPool = command_pool;
20709 command_buffer_allocate_info.commandBufferCount = 2;
20710 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20711 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20712
20713 VkQueue queue = VK_NULL_HANDLE;
20714 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20715
20716 {
20717 VkCommandBufferBeginInfo begin_info{};
20718 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20719 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20720
20721 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 -070020722 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020723
20724 VkViewport viewport{};
20725 viewport.maxDepth = 1.0f;
20726 viewport.minDepth = 0.0f;
20727 viewport.width = 512;
20728 viewport.height = 512;
20729 viewport.x = 0;
20730 viewport.y = 0;
20731 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20732 vkEndCommandBuffer(command_buffer[0]);
20733 }
20734 {
20735 VkCommandBufferBeginInfo begin_info{};
20736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20737 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20738
20739 VkViewport viewport{};
20740 viewport.maxDepth = 1.0f;
20741 viewport.minDepth = 0.0f;
20742 viewport.width = 512;
20743 viewport.height = 512;
20744 viewport.x = 0;
20745 viewport.y = 0;
20746 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20747 vkEndCommandBuffer(command_buffer[1]);
20748 }
20749 {
20750 VkSubmitInfo submit_info{};
20751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20752 submit_info.commandBufferCount = 1;
20753 submit_info.pCommandBuffers = &command_buffer[0];
20754 submit_info.signalSemaphoreCount = 1;
20755 submit_info.pSignalSemaphores = &semaphore;
20756 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20757 }
20758 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020759 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020760 VkSubmitInfo submit_info{};
20761 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20762 submit_info.commandBufferCount = 1;
20763 submit_info.pCommandBuffers = &command_buffer[1];
20764 submit_info.waitSemaphoreCount = 1;
20765 submit_info.pWaitSemaphores = &semaphore;
20766 submit_info.pWaitDstStageMask = flags;
20767 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20768 }
20769
20770 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20771
20772 vkDestroyFence(m_device->device(), fence, nullptr);
20773 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20774 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20775 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20776
20777 m_errorMonitor->VerifyNotFound();
20778}
20779
20780// This is a positive test. No errors should be generated.
20781TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020782 TEST_DESCRIPTION(
20783 "Two command buffers, each in a separate QueueSubmit call "
20784 "on the same queue, sharing a signal/wait semaphore, the "
20785 "second having a fence, "
20786 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020787
20788 m_errorMonitor->ExpectSuccess();
20789
20790 ASSERT_NO_FATAL_FAILURE(InitState());
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 {
20817 VkCommandBufferBeginInfo begin_info{};
20818 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20819 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20820
20821 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 -070020822 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020823
20824 VkViewport viewport{};
20825 viewport.maxDepth = 1.0f;
20826 viewport.minDepth = 0.0f;
20827 viewport.width = 512;
20828 viewport.height = 512;
20829 viewport.x = 0;
20830 viewport.y = 0;
20831 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20832 vkEndCommandBuffer(command_buffer[0]);
20833 }
20834 {
20835 VkCommandBufferBeginInfo begin_info{};
20836 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20837 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20838
20839 VkViewport viewport{};
20840 viewport.maxDepth = 1.0f;
20841 viewport.minDepth = 0.0f;
20842 viewport.width = 512;
20843 viewport.height = 512;
20844 viewport.x = 0;
20845 viewport.y = 0;
20846 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20847 vkEndCommandBuffer(command_buffer[1]);
20848 }
20849 {
20850 VkSubmitInfo submit_info{};
20851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20852 submit_info.commandBufferCount = 1;
20853 submit_info.pCommandBuffers = &command_buffer[0];
20854 submit_info.signalSemaphoreCount = 1;
20855 submit_info.pSignalSemaphores = &semaphore;
20856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20857 }
20858 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020859 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020860 VkSubmitInfo submit_info{};
20861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20862 submit_info.commandBufferCount = 1;
20863 submit_info.pCommandBuffers = &command_buffer[1];
20864 submit_info.waitSemaphoreCount = 1;
20865 submit_info.pWaitSemaphores = &semaphore;
20866 submit_info.pWaitDstStageMask = flags;
20867 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20868 }
20869
20870 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20871
20872 vkDestroyFence(m_device->device(), fence, nullptr);
20873 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20874 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20875 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20876
20877 m_errorMonitor->VerifyNotFound();
20878}
20879
20880// This is a positive test. No errors should be generated.
20881TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020882 TEST_DESCRIPTION(
20883 "Two command buffers, each in a separate QueueSubmit call "
20884 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20885 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020886
20887 m_errorMonitor->ExpectSuccess();
20888
20889 ASSERT_NO_FATAL_FAILURE(InitState());
20890 VkFence fence;
20891 VkFenceCreateInfo fence_create_info{};
20892 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20893 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20894
20895 VkCommandPool command_pool;
20896 VkCommandPoolCreateInfo pool_create_info{};
20897 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20898 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20899 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20900 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20901
20902 VkCommandBuffer command_buffer[2];
20903 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20904 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20905 command_buffer_allocate_info.commandPool = command_pool;
20906 command_buffer_allocate_info.commandBufferCount = 2;
20907 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20908 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20909
20910 {
20911 VkCommandBufferBeginInfo begin_info{};
20912 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20913 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20914
20915 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 -070020916 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020917
20918 VkViewport viewport{};
20919 viewport.maxDepth = 1.0f;
20920 viewport.minDepth = 0.0f;
20921 viewport.width = 512;
20922 viewport.height = 512;
20923 viewport.x = 0;
20924 viewport.y = 0;
20925 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20926 vkEndCommandBuffer(command_buffer[0]);
20927 }
20928 {
20929 VkCommandBufferBeginInfo begin_info{};
20930 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20931 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20932
20933 VkViewport viewport{};
20934 viewport.maxDepth = 1.0f;
20935 viewport.minDepth = 0.0f;
20936 viewport.width = 512;
20937 viewport.height = 512;
20938 viewport.x = 0;
20939 viewport.y = 0;
20940 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20941 vkEndCommandBuffer(command_buffer[1]);
20942 }
20943 {
20944 VkSubmitInfo submit_info{};
20945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20946 submit_info.commandBufferCount = 1;
20947 submit_info.pCommandBuffers = &command_buffer[0];
20948 submit_info.signalSemaphoreCount = 0;
20949 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20951 }
20952 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020953 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020954 VkSubmitInfo submit_info{};
20955 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20956 submit_info.commandBufferCount = 1;
20957 submit_info.pCommandBuffers = &command_buffer[1];
20958 submit_info.waitSemaphoreCount = 0;
20959 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20960 submit_info.pWaitDstStageMask = flags;
20961 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20962 }
20963
20964 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20965
20966 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20967 ASSERT_VK_SUCCESS(err);
20968
20969 vkDestroyFence(m_device->device(), fence, nullptr);
20970 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20971 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20972
20973 m_errorMonitor->VerifyNotFound();
20974}
20975
20976// This is a positive test. No errors should be generated.
20977TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020978 TEST_DESCRIPTION(
20979 "Two command buffers, each in a separate QueueSubmit call "
20980 "on the same queue, the second having a fence, followed "
20981 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020982
20983 m_errorMonitor->ExpectSuccess();
20984
20985 ASSERT_NO_FATAL_FAILURE(InitState());
20986 VkFence fence;
20987 VkFenceCreateInfo fence_create_info{};
20988 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20989 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20990
20991 VkCommandPool command_pool;
20992 VkCommandPoolCreateInfo pool_create_info{};
20993 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20994 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20995 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20996 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20997
20998 VkCommandBuffer command_buffer[2];
20999 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21000 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21001 command_buffer_allocate_info.commandPool = command_pool;
21002 command_buffer_allocate_info.commandBufferCount = 2;
21003 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21004 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21005
21006 {
21007 VkCommandBufferBeginInfo begin_info{};
21008 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21009 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21010
21011 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 -070021012 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021013
21014 VkViewport viewport{};
21015 viewport.maxDepth = 1.0f;
21016 viewport.minDepth = 0.0f;
21017 viewport.width = 512;
21018 viewport.height = 512;
21019 viewport.x = 0;
21020 viewport.y = 0;
21021 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21022 vkEndCommandBuffer(command_buffer[0]);
21023 }
21024 {
21025 VkCommandBufferBeginInfo begin_info{};
21026 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21027 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21028
21029 VkViewport viewport{};
21030 viewport.maxDepth = 1.0f;
21031 viewport.minDepth = 0.0f;
21032 viewport.width = 512;
21033 viewport.height = 512;
21034 viewport.x = 0;
21035 viewport.y = 0;
21036 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21037 vkEndCommandBuffer(command_buffer[1]);
21038 }
21039 {
21040 VkSubmitInfo submit_info{};
21041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21042 submit_info.commandBufferCount = 1;
21043 submit_info.pCommandBuffers = &command_buffer[0];
21044 submit_info.signalSemaphoreCount = 0;
21045 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21047 }
21048 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021049 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021050 VkSubmitInfo submit_info{};
21051 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21052 submit_info.commandBufferCount = 1;
21053 submit_info.pCommandBuffers = &command_buffer[1];
21054 submit_info.waitSemaphoreCount = 0;
21055 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21056 submit_info.pWaitDstStageMask = flags;
21057 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21058 }
21059
21060 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21061
21062 vkDestroyFence(m_device->device(), fence, nullptr);
21063 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21064 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21065
21066 m_errorMonitor->VerifyNotFound();
21067}
21068
21069// This is a positive test. No errors should be generated.
21070TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021071 TEST_DESCRIPTION(
21072 "Two command buffers each in a separate SubmitInfo sent in a single "
21073 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021074 ASSERT_NO_FATAL_FAILURE(InitState());
21075
21076 m_errorMonitor->ExpectSuccess();
21077
21078 VkFence fence;
21079 VkFenceCreateInfo fence_create_info{};
21080 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21081 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21082
21083 VkSemaphore semaphore;
21084 VkSemaphoreCreateInfo semaphore_create_info{};
21085 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21086 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21087
21088 VkCommandPool command_pool;
21089 VkCommandPoolCreateInfo pool_create_info{};
21090 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21091 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21092 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21093 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21094
21095 VkCommandBuffer command_buffer[2];
21096 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21097 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21098 command_buffer_allocate_info.commandPool = command_pool;
21099 command_buffer_allocate_info.commandBufferCount = 2;
21100 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21101 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21102
21103 {
21104 VkCommandBufferBeginInfo begin_info{};
21105 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21106 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21107
21108 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 -070021109 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021110
21111 VkViewport viewport{};
21112 viewport.maxDepth = 1.0f;
21113 viewport.minDepth = 0.0f;
21114 viewport.width = 512;
21115 viewport.height = 512;
21116 viewport.x = 0;
21117 viewport.y = 0;
21118 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21119 vkEndCommandBuffer(command_buffer[0]);
21120 }
21121 {
21122 VkCommandBufferBeginInfo begin_info{};
21123 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21124 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21125
21126 VkViewport viewport{};
21127 viewport.maxDepth = 1.0f;
21128 viewport.minDepth = 0.0f;
21129 viewport.width = 512;
21130 viewport.height = 512;
21131 viewport.x = 0;
21132 viewport.y = 0;
21133 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21134 vkEndCommandBuffer(command_buffer[1]);
21135 }
21136 {
21137 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021138 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021139
21140 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21141 submit_info[0].pNext = NULL;
21142 submit_info[0].commandBufferCount = 1;
21143 submit_info[0].pCommandBuffers = &command_buffer[0];
21144 submit_info[0].signalSemaphoreCount = 1;
21145 submit_info[0].pSignalSemaphores = &semaphore;
21146 submit_info[0].waitSemaphoreCount = 0;
21147 submit_info[0].pWaitSemaphores = NULL;
21148 submit_info[0].pWaitDstStageMask = 0;
21149
21150 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21151 submit_info[1].pNext = NULL;
21152 submit_info[1].commandBufferCount = 1;
21153 submit_info[1].pCommandBuffers = &command_buffer[1];
21154 submit_info[1].waitSemaphoreCount = 1;
21155 submit_info[1].pWaitSemaphores = &semaphore;
21156 submit_info[1].pWaitDstStageMask = flags;
21157 submit_info[1].signalSemaphoreCount = 0;
21158 submit_info[1].pSignalSemaphores = NULL;
21159 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21160 }
21161
21162 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21163
21164 vkDestroyFence(m_device->device(), fence, nullptr);
21165 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21166 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21167 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21168
21169 m_errorMonitor->VerifyNotFound();
21170}
21171
21172TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21173 m_errorMonitor->ExpectSuccess();
21174
21175 ASSERT_NO_FATAL_FAILURE(InitState());
21176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21177
Tony Barbour552f6c02016-12-21 14:34:07 -070021178 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021179
21180 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21181 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21182 m_errorMonitor->VerifyNotFound();
21183 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21184 m_errorMonitor->VerifyNotFound();
21185 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21186 m_errorMonitor->VerifyNotFound();
21187
21188 m_commandBuffer->EndCommandBuffer();
21189 m_errorMonitor->VerifyNotFound();
21190}
21191
21192TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021193 TEST_DESCRIPTION(
21194 "Positive test where we create a renderpass with an "
21195 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21196 "has a valid layout, and a second subpass then uses a "
21197 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021198 m_errorMonitor->ExpectSuccess();
21199 ASSERT_NO_FATAL_FAILURE(InitState());
21200
21201 VkAttachmentReference attach[2] = {};
21202 attach[0].attachment = 0;
21203 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21204 attach[1].attachment = 0;
21205 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21206 VkSubpassDescription subpasses[2] = {};
21207 // First subpass clears DS attach on load
21208 subpasses[0].pDepthStencilAttachment = &attach[0];
21209 // 2nd subpass reads in DS as input attachment
21210 subpasses[1].inputAttachmentCount = 1;
21211 subpasses[1].pInputAttachments = &attach[1];
21212 VkAttachmentDescription attach_desc = {};
21213 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21214 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21215 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21216 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21217 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21218 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21219 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21220 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21221 VkRenderPassCreateInfo rpci = {};
21222 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21223 rpci.attachmentCount = 1;
21224 rpci.pAttachments = &attach_desc;
21225 rpci.subpassCount = 2;
21226 rpci.pSubpasses = subpasses;
21227
21228 // Now create RenderPass and verify no errors
21229 VkRenderPass rp;
21230 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21231 m_errorMonitor->VerifyNotFound();
21232
21233 vkDestroyRenderPass(m_device->device(), rp, NULL);
21234}
21235
Tobin Ehlis01103de2017-02-16 13:22:47 -070021236TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21237 TEST_DESCRIPTION(
21238 "Create a render pass with depth-stencil attachment where layout transition "
21239 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21240 "transition has correctly occurred at queue submit time with no validation errors.");
21241
21242 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21243 VkImageFormatProperties format_props;
21244 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21245 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21246 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21247 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21248 return;
21249 }
21250
21251 m_errorMonitor->ExpectSuccess();
21252 ASSERT_NO_FATAL_FAILURE(InitState());
21253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21254
21255 // A renderpass with one depth/stencil attachment.
21256 VkAttachmentDescription attachment = {0,
21257 ds_format,
21258 VK_SAMPLE_COUNT_1_BIT,
21259 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21260 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21261 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21262 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21263 VK_IMAGE_LAYOUT_UNDEFINED,
21264 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21265
21266 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21267
21268 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21269
21270 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21271
21272 VkRenderPass rp;
21273 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21274 ASSERT_VK_SUCCESS(err);
21275 // A compatible ds image.
21276 VkImageObj image(m_device);
21277 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21278 ASSERT_TRUE(image.initialized());
21279
21280 VkImageViewCreateInfo ivci = {
21281 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21282 nullptr,
21283 0,
21284 image.handle(),
21285 VK_IMAGE_VIEW_TYPE_2D,
21286 ds_format,
21287 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21288 VK_COMPONENT_SWIZZLE_IDENTITY},
21289 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21290 };
21291 VkImageView view;
21292 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21293 ASSERT_VK_SUCCESS(err);
21294
21295 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21296 VkFramebuffer fb;
21297 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21298 ASSERT_VK_SUCCESS(err);
21299
21300 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21301 m_commandBuffer->BeginCommandBuffer();
21302 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21303 vkCmdEndRenderPass(m_commandBuffer->handle());
21304 m_commandBuffer->EndCommandBuffer();
21305 QueueCommandBuffer(false);
21306 m_errorMonitor->VerifyNotFound();
21307
21308 // Cleanup
21309 vkDestroyImageView(m_device->device(), view, NULL);
21310 vkDestroyRenderPass(m_device->device(), rp, NULL);
21311 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21312}
21313
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021314TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021315 TEST_DESCRIPTION(
21316 "Test that pipeline validation accepts matrices passed "
21317 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021318 m_errorMonitor->ExpectSuccess();
21319
21320 ASSERT_NO_FATAL_FAILURE(InitState());
21321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21322
21323 VkVertexInputBindingDescription input_binding;
21324 memset(&input_binding, 0, sizeof(input_binding));
21325
21326 VkVertexInputAttributeDescription input_attribs[2];
21327 memset(input_attribs, 0, sizeof(input_attribs));
21328
21329 for (int i = 0; i < 2; i++) {
21330 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21331 input_attribs[i].location = i;
21332 }
21333
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021334 char const *vsSource =
21335 "#version 450\n"
21336 "\n"
21337 "layout(location=0) in mat2x4 x;\n"
21338 "out gl_PerVertex {\n"
21339 " vec4 gl_Position;\n"
21340 "};\n"
21341 "void main(){\n"
21342 " gl_Position = x[0] + x[1];\n"
21343 "}\n";
21344 char const *fsSource =
21345 "#version 450\n"
21346 "\n"
21347 "layout(location=0) out vec4 color;\n"
21348 "void main(){\n"
21349 " color = vec4(1);\n"
21350 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021351
21352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21354
21355 VkPipelineObj pipe(m_device);
21356 pipe.AddColorAttachment();
21357 pipe.AddShader(&vs);
21358 pipe.AddShader(&fs);
21359
21360 pipe.AddVertexInputBindings(&input_binding, 1);
21361 pipe.AddVertexInputAttribs(input_attribs, 2);
21362
21363 VkDescriptorSetObj descriptorSet(m_device);
21364 descriptorSet.AppendDummy();
21365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21366
21367 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21368
21369 /* expect success */
21370 m_errorMonitor->VerifyNotFound();
21371}
21372
21373TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21374 m_errorMonitor->ExpectSuccess();
21375
21376 ASSERT_NO_FATAL_FAILURE(InitState());
21377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21378
21379 VkVertexInputBindingDescription input_binding;
21380 memset(&input_binding, 0, sizeof(input_binding));
21381
21382 VkVertexInputAttributeDescription input_attribs[2];
21383 memset(input_attribs, 0, sizeof(input_attribs));
21384
21385 for (int i = 0; i < 2; i++) {
21386 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21387 input_attribs[i].location = i;
21388 }
21389
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021390 char const *vsSource =
21391 "#version 450\n"
21392 "\n"
21393 "layout(location=0) in vec4 x[2];\n"
21394 "out gl_PerVertex {\n"
21395 " vec4 gl_Position;\n"
21396 "};\n"
21397 "void main(){\n"
21398 " gl_Position = x[0] + x[1];\n"
21399 "}\n";
21400 char const *fsSource =
21401 "#version 450\n"
21402 "\n"
21403 "layout(location=0) out vec4 color;\n"
21404 "void main(){\n"
21405 " color = vec4(1);\n"
21406 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021407
21408 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21409 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21410
21411 VkPipelineObj pipe(m_device);
21412 pipe.AddColorAttachment();
21413 pipe.AddShader(&vs);
21414 pipe.AddShader(&fs);
21415
21416 pipe.AddVertexInputBindings(&input_binding, 1);
21417 pipe.AddVertexInputAttribs(input_attribs, 2);
21418
21419 VkDescriptorSetObj descriptorSet(m_device);
21420 descriptorSet.AppendDummy();
21421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21422
21423 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21424
21425 m_errorMonitor->VerifyNotFound();
21426}
21427
21428TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021429 TEST_DESCRIPTION(
21430 "Test that pipeline validation accepts consuming a vertex attribute "
21431 "through multiple vertex shader inputs, each consuming a different "
21432 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021433 m_errorMonitor->ExpectSuccess();
21434
21435 ASSERT_NO_FATAL_FAILURE(InitState());
21436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21437
21438 VkVertexInputBindingDescription input_binding;
21439 memset(&input_binding, 0, sizeof(input_binding));
21440
21441 VkVertexInputAttributeDescription input_attribs[3];
21442 memset(input_attribs, 0, sizeof(input_attribs));
21443
21444 for (int i = 0; i < 3; i++) {
21445 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21446 input_attribs[i].location = i;
21447 }
21448
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021449 char const *vsSource =
21450 "#version 450\n"
21451 "\n"
21452 "layout(location=0) in vec4 x;\n"
21453 "layout(location=1) in vec3 y1;\n"
21454 "layout(location=1, component=3) in float y2;\n"
21455 "layout(location=2) in vec4 z;\n"
21456 "out gl_PerVertex {\n"
21457 " vec4 gl_Position;\n"
21458 "};\n"
21459 "void main(){\n"
21460 " gl_Position = x + vec4(y1, y2) + z;\n"
21461 "}\n";
21462 char const *fsSource =
21463 "#version 450\n"
21464 "\n"
21465 "layout(location=0) out vec4 color;\n"
21466 "void main(){\n"
21467 " color = vec4(1);\n"
21468 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021469
21470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21472
21473 VkPipelineObj pipe(m_device);
21474 pipe.AddColorAttachment();
21475 pipe.AddShader(&vs);
21476 pipe.AddShader(&fs);
21477
21478 pipe.AddVertexInputBindings(&input_binding, 1);
21479 pipe.AddVertexInputAttribs(input_attribs, 3);
21480
21481 VkDescriptorSetObj descriptorSet(m_device);
21482 descriptorSet.AppendDummy();
21483 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21484
21485 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21486
21487 m_errorMonitor->VerifyNotFound();
21488}
21489
21490TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21491 m_errorMonitor->ExpectSuccess();
21492
21493 ASSERT_NO_FATAL_FAILURE(InitState());
21494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21495
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021496 char const *vsSource =
21497 "#version 450\n"
21498 "out gl_PerVertex {\n"
21499 " vec4 gl_Position;\n"
21500 "};\n"
21501 "void main(){\n"
21502 " gl_Position = vec4(0);\n"
21503 "}\n";
21504 char const *fsSource =
21505 "#version 450\n"
21506 "\n"
21507 "layout(location=0) out vec4 color;\n"
21508 "void main(){\n"
21509 " color = vec4(1);\n"
21510 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021511
21512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21514
21515 VkPipelineObj pipe(m_device);
21516 pipe.AddColorAttachment();
21517 pipe.AddShader(&vs);
21518 pipe.AddShader(&fs);
21519
21520 VkDescriptorSetObj descriptorSet(m_device);
21521 descriptorSet.AppendDummy();
21522 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21523
21524 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21525
21526 m_errorMonitor->VerifyNotFound();
21527}
21528
21529TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021530 TEST_DESCRIPTION(
21531 "Test that pipeline validation accepts the relaxed type matching rules "
21532 "set out in 14.1.3: fundamental type must match, and producer side must "
21533 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021534 m_errorMonitor->ExpectSuccess();
21535
21536 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21537
21538 ASSERT_NO_FATAL_FAILURE(InitState());
21539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21540
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021541 char const *vsSource =
21542 "#version 450\n"
21543 "out gl_PerVertex {\n"
21544 " vec4 gl_Position;\n"
21545 "};\n"
21546 "layout(location=0) out vec3 x;\n"
21547 "layout(location=1) out ivec3 y;\n"
21548 "layout(location=2) out vec3 z;\n"
21549 "void main(){\n"
21550 " gl_Position = vec4(0);\n"
21551 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21552 "}\n";
21553 char const *fsSource =
21554 "#version 450\n"
21555 "\n"
21556 "layout(location=0) out vec4 color;\n"
21557 "layout(location=0) in float x;\n"
21558 "layout(location=1) flat in int y;\n"
21559 "layout(location=2) in vec2 z;\n"
21560 "void main(){\n"
21561 " color = vec4(1 + x + y + z.x);\n"
21562 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021563
21564 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21565 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21566
21567 VkPipelineObj pipe(m_device);
21568 pipe.AddColorAttachment();
21569 pipe.AddShader(&vs);
21570 pipe.AddShader(&fs);
21571
21572 VkDescriptorSetObj descriptorSet(m_device);
21573 descriptorSet.AppendDummy();
21574 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21575
21576 VkResult err = VK_SUCCESS;
21577 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21578 ASSERT_VK_SUCCESS(err);
21579
21580 m_errorMonitor->VerifyNotFound();
21581}
21582
21583TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021584 TEST_DESCRIPTION(
21585 "Test that pipeline validation accepts per-vertex variables "
21586 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021587 m_errorMonitor->ExpectSuccess();
21588
21589 ASSERT_NO_FATAL_FAILURE(InitState());
21590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21591
21592 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021593 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021594 return;
21595 }
21596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021597 char const *vsSource =
21598 "#version 450\n"
21599 "void main(){}\n";
21600 char const *tcsSource =
21601 "#version 450\n"
21602 "layout(location=0) out int x[];\n"
21603 "layout(vertices=3) out;\n"
21604 "void main(){\n"
21605 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21606 " gl_TessLevelInner[0] = 1;\n"
21607 " x[gl_InvocationID] = gl_InvocationID;\n"
21608 "}\n";
21609 char const *tesSource =
21610 "#version 450\n"
21611 "layout(triangles, equal_spacing, cw) in;\n"
21612 "layout(location=0) in int x[];\n"
21613 "out gl_PerVertex { vec4 gl_Position; };\n"
21614 "void main(){\n"
21615 " gl_Position.xyz = gl_TessCoord;\n"
21616 " gl_Position.w = x[0] + x[1] + x[2];\n"
21617 "}\n";
21618 char const *fsSource =
21619 "#version 450\n"
21620 "layout(location=0) out vec4 color;\n"
21621 "void main(){\n"
21622 " color = vec4(1);\n"
21623 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021624
21625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21626 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21627 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21628 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21629
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021630 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21631 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021633 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021634
21635 VkPipelineObj pipe(m_device);
21636 pipe.SetInputAssembly(&iasci);
21637 pipe.SetTessellation(&tsci);
21638 pipe.AddColorAttachment();
21639 pipe.AddShader(&vs);
21640 pipe.AddShader(&tcs);
21641 pipe.AddShader(&tes);
21642 pipe.AddShader(&fs);
21643
21644 VkDescriptorSetObj descriptorSet(m_device);
21645 descriptorSet.AppendDummy();
21646 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21647
21648 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21649
21650 m_errorMonitor->VerifyNotFound();
21651}
21652
21653TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021654 TEST_DESCRIPTION(
21655 "Test that pipeline validation accepts a user-defined "
21656 "interface block passed into the geometry shader. This "
21657 "is interesting because the 'extra' array level is not "
21658 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021659 m_errorMonitor->ExpectSuccess();
21660
21661 ASSERT_NO_FATAL_FAILURE(InitState());
21662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21663
21664 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021665 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021666 return;
21667 }
21668
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021669 char const *vsSource =
21670 "#version 450\n"
21671 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21672 "void main(){\n"
21673 " vs_out.x = vec4(1);\n"
21674 "}\n";
21675 char const *gsSource =
21676 "#version 450\n"
21677 "layout(triangles) in;\n"
21678 "layout(triangle_strip, max_vertices=3) out;\n"
21679 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21680 "out gl_PerVertex { vec4 gl_Position; };\n"
21681 "void main() {\n"
21682 " gl_Position = gs_in[0].x;\n"
21683 " EmitVertex();\n"
21684 "}\n";
21685 char const *fsSource =
21686 "#version 450\n"
21687 "layout(location=0) out vec4 color;\n"
21688 "void main(){\n"
21689 " color = vec4(1);\n"
21690 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021691
21692 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21693 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_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(&gs);
21700 pipe.AddShader(&fs);
21701
21702 VkDescriptorSetObj descriptorSet(m_device);
21703 descriptorSet.AppendDummy();
21704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21705
21706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21707
21708 m_errorMonitor->VerifyNotFound();
21709}
21710
21711TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021712 TEST_DESCRIPTION(
21713 "Test that pipeline validation accepts basic use of 64bit vertex "
21714 "attributes. This is interesting because they consume multiple "
21715 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021716 m_errorMonitor->ExpectSuccess();
21717
21718 ASSERT_NO_FATAL_FAILURE(InitState());
21719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21720
21721 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021722 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021723 return;
21724 }
21725
21726 VkVertexInputBindingDescription input_bindings[1];
21727 memset(input_bindings, 0, sizeof(input_bindings));
21728
21729 VkVertexInputAttributeDescription input_attribs[4];
21730 memset(input_attribs, 0, sizeof(input_attribs));
21731 input_attribs[0].location = 0;
21732 input_attribs[0].offset = 0;
21733 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21734 input_attribs[1].location = 2;
21735 input_attribs[1].offset = 32;
21736 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21737 input_attribs[2].location = 4;
21738 input_attribs[2].offset = 64;
21739 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21740 input_attribs[3].location = 6;
21741 input_attribs[3].offset = 96;
21742 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021744 char const *vsSource =
21745 "#version 450\n"
21746 "\n"
21747 "layout(location=0) in dmat4 x;\n"
21748 "out gl_PerVertex {\n"
21749 " vec4 gl_Position;\n"
21750 "};\n"
21751 "void main(){\n"
21752 " gl_Position = vec4(x[0][0]);\n"
21753 "}\n";
21754 char const *fsSource =
21755 "#version 450\n"
21756 "\n"
21757 "layout(location=0) out vec4 color;\n"
21758 "void main(){\n"
21759 " color = vec4(1);\n"
21760 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021761
21762 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21763 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21764
21765 VkPipelineObj pipe(m_device);
21766 pipe.AddColorAttachment();
21767 pipe.AddShader(&vs);
21768 pipe.AddShader(&fs);
21769
21770 pipe.AddVertexInputBindings(input_bindings, 1);
21771 pipe.AddVertexInputAttribs(input_attribs, 4);
21772
21773 VkDescriptorSetObj descriptorSet(m_device);
21774 descriptorSet.AppendDummy();
21775 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21776
21777 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21778
21779 m_errorMonitor->VerifyNotFound();
21780}
21781
21782TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21783 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21784 m_errorMonitor->ExpectSuccess();
21785
21786 ASSERT_NO_FATAL_FAILURE(InitState());
21787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021788 char const *vsSource =
21789 "#version 450\n"
21790 "\n"
21791 "out gl_PerVertex {\n"
21792 " vec4 gl_Position;\n"
21793 "};\n"
21794 "void main(){\n"
21795 " gl_Position = vec4(1);\n"
21796 "}\n";
21797 char const *fsSource =
21798 "#version 450\n"
21799 "\n"
21800 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21801 "layout(location=0) out vec4 color;\n"
21802 "void main() {\n"
21803 " color = subpassLoad(x);\n"
21804 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021805
21806 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21807 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21808
21809 VkPipelineObj pipe(m_device);
21810 pipe.AddShader(&vs);
21811 pipe.AddShader(&fs);
21812 pipe.AddColorAttachment();
21813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21814
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021815 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21816 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021817 VkDescriptorSetLayout dsl;
21818 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21819 ASSERT_VK_SUCCESS(err);
21820
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021821 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021822 VkPipelineLayout pl;
21823 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21824 ASSERT_VK_SUCCESS(err);
21825
21826 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021827 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21828 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21829 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21830 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21831 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 -060021832 };
21833 VkAttachmentReference color = {
21834 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21835 };
21836 VkAttachmentReference input = {
21837 1, VK_IMAGE_LAYOUT_GENERAL,
21838 };
21839
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021840 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021841
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021842 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021843 VkRenderPass rp;
21844 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21845 ASSERT_VK_SUCCESS(err);
21846
21847 // should be OK. would go wrong here if it's going to...
21848 pipe.CreateVKPipeline(pl, rp);
21849
21850 m_errorMonitor->VerifyNotFound();
21851
21852 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21853 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21854 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21855}
21856
21857TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021858 TEST_DESCRIPTION(
21859 "Test that pipeline validation accepts a compute pipeline which declares a "
21860 "descriptor-backed resource which is not provided, but the shader does not "
21861 "statically use it. This is interesting because it requires compute pipelines "
21862 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021863 m_errorMonitor->ExpectSuccess();
21864
21865 ASSERT_NO_FATAL_FAILURE(InitState());
21866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021867 char const *csSource =
21868 "#version 450\n"
21869 "\n"
21870 "layout(local_size_x=1) in;\n"
21871 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21872 "void main(){\n"
21873 " // x is not used.\n"
21874 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021875
21876 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21877
21878 VkDescriptorSetObj descriptorSet(m_device);
21879 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21880
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021881 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21882 nullptr,
21883 0,
21884 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21885 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21886 descriptorSet.GetPipelineLayout(),
21887 VK_NULL_HANDLE,
21888 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021889
21890 VkPipeline pipe;
21891 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21892
21893 m_errorMonitor->VerifyNotFound();
21894
21895 if (err == VK_SUCCESS) {
21896 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21897 }
21898}
21899
21900TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021901 TEST_DESCRIPTION(
21902 "Test that pipeline validation accepts a shader consuming only the "
21903 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021904 m_errorMonitor->ExpectSuccess();
21905
21906 ASSERT_NO_FATAL_FAILURE(InitState());
21907
21908 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021909 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21910 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21911 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021912 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021913 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021914 VkDescriptorSetLayout dsl;
21915 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21916 ASSERT_VK_SUCCESS(err);
21917
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021918 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021919 VkPipelineLayout pl;
21920 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21921 ASSERT_VK_SUCCESS(err);
21922
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021923 char const *csSource =
21924 "#version 450\n"
21925 "\n"
21926 "layout(local_size_x=1) in;\n"
21927 "layout(set=0, binding=0) uniform sampler s;\n"
21928 "layout(set=0, binding=1) uniform texture2D t;\n"
21929 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21930 "void main() {\n"
21931 " x = texture(sampler2D(t, s), vec2(0));\n"
21932 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021933 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21934
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021935 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21936 nullptr,
21937 0,
21938 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21939 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21940 pl,
21941 VK_NULL_HANDLE,
21942 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021943
21944 VkPipeline pipe;
21945 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21946
21947 m_errorMonitor->VerifyNotFound();
21948
21949 if (err == VK_SUCCESS) {
21950 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21951 }
21952
21953 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21954 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21955}
21956
21957TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021958 TEST_DESCRIPTION(
21959 "Test that pipeline validation accepts a shader consuming only the "
21960 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021961 m_errorMonitor->ExpectSuccess();
21962
21963 ASSERT_NO_FATAL_FAILURE(InitState());
21964
21965 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021966 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21967 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21968 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021969 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021970 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021971 VkDescriptorSetLayout dsl;
21972 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21973 ASSERT_VK_SUCCESS(err);
21974
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021975 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021976 VkPipelineLayout pl;
21977 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21978 ASSERT_VK_SUCCESS(err);
21979
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021980 char const *csSource =
21981 "#version 450\n"
21982 "\n"
21983 "layout(local_size_x=1) in;\n"
21984 "layout(set=0, binding=0) uniform texture2D t;\n"
21985 "layout(set=0, binding=1) uniform sampler s;\n"
21986 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21987 "void main() {\n"
21988 " x = texture(sampler2D(t, s), vec2(0));\n"
21989 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021990 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21991
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021992 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21993 nullptr,
21994 0,
21995 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21996 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21997 pl,
21998 VK_NULL_HANDLE,
21999 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022000
22001 VkPipeline pipe;
22002 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22003
22004 m_errorMonitor->VerifyNotFound();
22005
22006 if (err == VK_SUCCESS) {
22007 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22008 }
22009
22010 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22011 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22012}
22013
22014TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022015 TEST_DESCRIPTION(
22016 "Test that pipeline validation accepts a shader consuming "
22017 "both the sampler and the image of a combined image+sampler "
22018 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022019 m_errorMonitor->ExpectSuccess();
22020
22021 ASSERT_NO_FATAL_FAILURE(InitState());
22022
22023 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022024 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22025 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022026 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022027 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022028 VkDescriptorSetLayout dsl;
22029 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22030 ASSERT_VK_SUCCESS(err);
22031
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022032 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022033 VkPipelineLayout pl;
22034 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22035 ASSERT_VK_SUCCESS(err);
22036
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022037 char const *csSource =
22038 "#version 450\n"
22039 "\n"
22040 "layout(local_size_x=1) in;\n"
22041 "layout(set=0, binding=0) uniform texture2D t;\n"
22042 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22043 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22044 "void main() {\n"
22045 " x = texture(sampler2D(t, s), vec2(0));\n"
22046 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022047 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22048
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022049 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22050 nullptr,
22051 0,
22052 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22053 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22054 pl,
22055 VK_NULL_HANDLE,
22056 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022057
22058 VkPipeline pipe;
22059 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22060
22061 m_errorMonitor->VerifyNotFound();
22062
22063 if (err == VK_SUCCESS) {
22064 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22065 }
22066
22067 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22068 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22069}
22070
22071TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22072 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22073
22074 ASSERT_NO_FATAL_FAILURE(InitState());
22075
22076 // Positive test to check parameter_validation and unique_objects support
22077 // for NV_dedicated_allocation
22078 uint32_t extension_count = 0;
22079 bool supports_nv_dedicated_allocation = false;
22080 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22081 ASSERT_VK_SUCCESS(err);
22082
22083 if (extension_count > 0) {
22084 std::vector<VkExtensionProperties> available_extensions(extension_count);
22085
22086 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22087 ASSERT_VK_SUCCESS(err);
22088
22089 for (const auto &extension_props : available_extensions) {
22090 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22091 supports_nv_dedicated_allocation = true;
22092 }
22093 }
22094 }
22095
22096 if (supports_nv_dedicated_allocation) {
22097 m_errorMonitor->ExpectSuccess();
22098
22099 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22100 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22101 dedicated_buffer_create_info.pNext = nullptr;
22102 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22103
22104 uint32_t queue_family_index = 0;
22105 VkBufferCreateInfo buffer_create_info = {};
22106 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22107 buffer_create_info.pNext = &dedicated_buffer_create_info;
22108 buffer_create_info.size = 1024;
22109 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22110 buffer_create_info.queueFamilyIndexCount = 1;
22111 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22112
22113 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022114 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022115 ASSERT_VK_SUCCESS(err);
22116
22117 VkMemoryRequirements memory_reqs;
22118 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22119
22120 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22121 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22122 dedicated_memory_info.pNext = nullptr;
22123 dedicated_memory_info.buffer = buffer;
22124 dedicated_memory_info.image = VK_NULL_HANDLE;
22125
22126 VkMemoryAllocateInfo memory_info = {};
22127 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22128 memory_info.pNext = &dedicated_memory_info;
22129 memory_info.allocationSize = memory_reqs.size;
22130
22131 bool pass;
22132 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22133 ASSERT_TRUE(pass);
22134
22135 VkDeviceMemory buffer_memory;
22136 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22137 ASSERT_VK_SUCCESS(err);
22138
22139 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22140 ASSERT_VK_SUCCESS(err);
22141
22142 vkDestroyBuffer(m_device->device(), buffer, NULL);
22143 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22144
22145 m_errorMonitor->VerifyNotFound();
22146 }
22147}
22148
22149TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22150 VkResult err;
22151
22152 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22153
22154 ASSERT_NO_FATAL_FAILURE(InitState());
22155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22156
22157 std::vector<const char *> device_extension_names;
22158 auto features = m_device->phy().features();
22159 // Artificially disable support for non-solid fill modes
22160 features.fillModeNonSolid = false;
22161 // The sacrificial device object
22162 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22163
22164 VkRenderpassObj render_pass(&test_device);
22165
22166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22168 pipeline_layout_ci.setLayoutCount = 0;
22169 pipeline_layout_ci.pSetLayouts = NULL;
22170
22171 VkPipelineLayout pipeline_layout;
22172 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22173 ASSERT_VK_SUCCESS(err);
22174
22175 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22176 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22177 rs_ci.pNext = nullptr;
22178 rs_ci.lineWidth = 1.0f;
22179 rs_ci.rasterizerDiscardEnable = true;
22180
22181 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22182 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22183
22184 // Set polygonMode=FILL. No error is expected
22185 m_errorMonitor->ExpectSuccess();
22186 {
22187 VkPipelineObj pipe(&test_device);
22188 pipe.AddShader(&vs);
22189 pipe.AddShader(&fs);
22190 pipe.AddColorAttachment();
22191 // Set polygonMode to a good value
22192 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22193 pipe.SetRasterization(&rs_ci);
22194 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22195 }
22196 m_errorMonitor->VerifyNotFound();
22197
22198 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22199}
22200
22201TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22202 VkResult err;
22203 ASSERT_NO_FATAL_FAILURE(InitState());
22204 ASSERT_NO_FATAL_FAILURE(InitViewport());
22205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22206
22207 VkPipelineLayout pipeline_layout;
22208 VkPushConstantRange pc_range = {};
22209 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22210 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22211 pipeline_layout_ci.pushConstantRangeCount = 1;
22212 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22213
22214 //
22215 // Check for invalid push constant ranges in pipeline layouts.
22216 //
22217 struct PipelineLayoutTestCase {
22218 VkPushConstantRange const range;
22219 char const *msg;
22220 };
22221
22222 // Check for overlapping ranges
22223 const uint32_t ranges_per_test = 5;
22224 struct OverlappingRangeTestCase {
22225 VkPushConstantRange const ranges[ranges_per_test];
22226 char const *msg;
22227 };
22228
22229 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022230 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22231 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22232 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22233 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22234 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22235 ""},
22236 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22237 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22238 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22239 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22240 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22241 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022242 for (const auto &iter : overlapping_range_tests_pos) {
22243 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22244 m_errorMonitor->ExpectSuccess();
22245 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22246 m_errorMonitor->VerifyNotFound();
22247 if (VK_SUCCESS == err) {
22248 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22249 }
22250 }
22251
22252 //
22253 // CmdPushConstants tests
22254 //
22255 const uint8_t dummy_values[100] = {};
22256
Tony Barbour552f6c02016-12-21 14:34:07 -070022257 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022258
22259 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022260 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22261 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22262 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22263 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22264 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22265 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022266
22267 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22268 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022269 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22270 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022271 };
22272
22273 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22274 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22275 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22276 ASSERT_VK_SUCCESS(err);
22277 for (const auto &iter : cmd_overlap_tests_pos) {
22278 m_errorMonitor->ExpectSuccess();
22279 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022280 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022281 m_errorMonitor->VerifyNotFound();
22282 }
22283 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22284
Tony Barbour552f6c02016-12-21 14:34:07 -070022285 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022286}
22287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022288#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022289TEST_F(VkPositiveLayerTest, LongFenceChain)
22290{
22291 m_errorMonitor->ExpectSuccess();
22292
22293 ASSERT_NO_FATAL_FAILURE(InitState());
22294 VkResult err;
22295
22296 std::vector<VkFence> fences;
22297
22298 const int chainLength = 32768;
22299
22300 for (int i = 0; i < chainLength; i++) {
22301 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22302 VkFence fence;
22303 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22304 ASSERT_VK_SUCCESS(err);
22305
22306 fences.push_back(fence);
22307
22308 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22309 0, nullptr, 0, nullptr };
22310 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22311 ASSERT_VK_SUCCESS(err);
22312
22313 }
22314
22315 // BOOM, stack overflow.
22316 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22317
22318 for (auto fence : fences)
22319 vkDestroyFence(m_device->device(), fence, nullptr);
22320
22321 m_errorMonitor->VerifyNotFound();
22322}
22323#endif
22324
Cody Northrop1242dfd2016-07-13 17:24:59 -060022325#if defined(ANDROID) && defined(VALIDATION_APK)
22326static bool initialized = false;
22327static bool active = false;
22328
22329// Convert Intents to argv
22330// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022331std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022332 std::vector<std::string> args;
22333 JavaVM &vm = *app.activity->vm;
22334 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022335 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022336
22337 JNIEnv &env = *p_env;
22338 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022339 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022340 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022341 jmethodID get_string_extra_method =
22342 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022343 jvalue get_string_extra_args;
22344 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022345 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022346
22347 std::string args_str;
22348 if (extra_str) {
22349 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22350 args_str = extra_utf;
22351 env.ReleaseStringUTFChars(extra_str, extra_utf);
22352 env.DeleteLocalRef(extra_str);
22353 }
22354
22355 env.DeleteLocalRef(get_string_extra_args.l);
22356 env.DeleteLocalRef(intent);
22357 vm.DetachCurrentThread();
22358
22359 // split args_str
22360 std::stringstream ss(args_str);
22361 std::string arg;
22362 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022363 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022364 }
22365
22366 return args;
22367}
22368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022369static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022371static void processCommand(struct android_app *app, int32_t cmd) {
22372 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022373 case APP_CMD_INIT_WINDOW: {
22374 if (app->window) {
22375 initialized = true;
22376 }
22377 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022378 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022379 case APP_CMD_GAINED_FOCUS: {
22380 active = true;
22381 break;
22382 }
22383 case APP_CMD_LOST_FOCUS: {
22384 active = false;
22385 break;
22386 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022387 }
22388}
22389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022390void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022391 app_dummy();
22392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022393 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022394
22395 int vulkanSupport = InitVulkan();
22396 if (vulkanSupport == 0) {
22397 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22398 return;
22399 }
22400
22401 app->onAppCmd = processCommand;
22402 app->onInputEvent = processInput;
22403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022404 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022405 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022406 struct android_poll_source *source;
22407 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022408 if (source) {
22409 source->process(app, source);
22410 }
22411
22412 if (app->destroyRequested != 0) {
22413 VkTestFramework::Finish();
22414 return;
22415 }
22416 }
22417
22418 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022419 // Use the following key to send arguments to gtest, i.e.
22420 // --es args "--gtest_filter=-VkLayerTest.foo"
22421 const char key[] = "args";
22422 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022424 std::string filter = "";
22425 if (args.size() > 0) {
22426 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22427 filter += args[0];
22428 } else {
22429 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22430 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022432 int argc = 2;
22433 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22434 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022436 // Route output to files until we can override the gtest output
22437 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22438 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022440 ::testing::InitGoogleTest(&argc, argv);
22441 VkTestFramework::InitArgs(&argc, argv);
22442 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022444 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022446 if (result != 0) {
22447 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22448 } else {
22449 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22450 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022452 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022454 fclose(stdout);
22455 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022457 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022458 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022459 }
22460 }
22461}
22462#endif
22463
Tony Barbour300a6082015-04-07 13:44:53 -060022464int main(int argc, char **argv) {
22465 int result;
22466
Cody Northrop8e54a402016-03-08 22:25:52 -070022467#ifdef ANDROID
22468 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022469 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022470#endif
22471
Tony Barbour300a6082015-04-07 13:44:53 -060022472 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022473 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022474
22475 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22476
22477 result = RUN_ALL_TESTS();
22478
Tony Barbour6918cd52015-04-09 12:58:51 -060022479 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022480 return result;
22481}