blob: 759b7318e640bb3fa671a822b00bc3d6eda813d2 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tobin Ehliscdf95132017-03-15 13:50:56 -0600358 bool m_enable_maintenance1_ext = false;
Tony Barbour300a6082015-04-07 13:44:53 -0600359
360 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600361 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600362 std::vector<const char *> instance_extension_names;
363 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600364
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700365 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600366 /*
367 * Since CreateDbgMsgCallback is an instance level extension call
368 * any extension / layer that utilizes that feature also needs
369 * to be enabled at create instance time.
370 */
Karl Schultz6addd812016-02-02 17:17:23 -0700371 // Use Threading layer first to protect others from
372 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700373 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600374 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700376 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600403 if (m_enable_maintenance1_ext) {
404 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
405 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600406
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 this->app_info.pApplicationName = "layer_tests";
410 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600411 this->app_info.pEngineName = "unittest";
412 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600413 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600414
Tony Barbour15524c32015-04-29 17:34:29 -0600415 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600417 }
418
419 virtual void TearDown() {
420 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600421 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600422 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600423 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600424
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600425 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600426};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429 // Create identity matrix
430 int i;
431 struct vktriangle_vs_uniform data;
432
433 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 glm::mat4 View = glm::mat4(1.0f);
435 glm::mat4 Model = glm::mat4(1.0f);
436 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700438 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500439
440 memcpy(&data.mvp, &MVP[0][0], matrixSize);
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 };
445
Karl Schultz6addd812016-02-02 17:17:23 -0700446 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 data.position[i][0] = tri_data[i].posX;
448 data.position[i][1] = tri_data[i].posY;
449 data.position[i][2] = tri_data[i].posZ;
450 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700451 data.color[i][0] = tri_data[i].r;
452 data.color[i][1] = tri_data[i].g;
453 data.color[i][2] = tri_data[i].b;
454 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500455 }
456
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 ASSERT_NO_FATAL_FAILURE(InitViewport());
458
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200459 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
460 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
465 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800466 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 pipelineobj.AddShader(&vs);
468 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 if (failMask & BsoFailLineWidth) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600472 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600473 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
474 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 }
476 if (failMask & BsoFailDepthBias) {
477 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600481 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600482 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600483 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700484 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700485 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600486 if (failMask & BsoFailViewport) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
488 }
489 if (failMask & BsoFailScissor) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
491 }
492 if (failMask & BsoFailBlend) {
493 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600494 VkPipelineColorBlendAttachmentState att_state = {};
495 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
496 att_state.blendEnable = VK_TRUE;
497 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600498 }
499 if (failMask & BsoFailDepthBounds) {
500 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
501 }
502 if (failMask & BsoFailStencilReadMask) {
503 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
504 }
505 if (failMask & BsoFailStencilWriteMask) {
506 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
507 }
508 if (failMask & BsoFailStencilReference) {
509 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
510 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
512 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700516 m_commandBuffer->BeginCommandBuffer();
517 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518
Tony Barbourfe3351b2015-07-28 10:17:20 -0600519 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520
521 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600522 if (failMask & BsoFailIndexBuffer) {
523 // Use DrawIndexed w/o an index buffer bound
524 DrawIndexed(3, 1, 0, 0, 0);
525 } else {
526 Draw(3, 1, 0, 0);
527 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Mark Muellerd4914412016-06-13 17:52:06 -0600529 if (failMask & BsoFailCmdClearAttachments) {
530 VkClearAttachment color_attachment = {};
531 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700532 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600533 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600536 }
537
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700539 m_commandBuffer->EndRenderPass();
540 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600541 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542}
543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
545 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600547 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500550 }
551
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700553 // Make sure depthWriteEnable is set so that Depth fail test will work
554 // correctly
555 // Make sure stencilTestEnable is set so that Stencil fail test will work
556 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600557 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800558 stencil.failOp = VK_STENCIL_OP_KEEP;
559 stencil.passOp = VK_STENCIL_OP_KEEP;
560 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
561 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600562
563 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
564 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600565 ds_ci.pNext = NULL;
566 ds_ci.depthTestEnable = VK_FALSE;
567 ds_ci.depthWriteEnable = VK_TRUE;
568 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
569 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 if (failMask & BsoFailDepthBounds) {
571 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600572 ds_ci.maxDepthBounds = 0.0f;
573 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600574 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600575 ds_ci.stencilTestEnable = VK_TRUE;
576 ds_ci.front = stencil;
577 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600578
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600579 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600580 pipelineobj.SetViewport(m_viewports);
581 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600583 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600584 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800585 commandBuffer->BindPipeline(pipelineobj);
586 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500587}
588
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600589class VkMaintenance1LayerTest : public VkLayerTest {
590 public:
591 protected:
592 VkMaintenance1LayerTest(){ m_enable_maintenance1_ext = true; }
593};
594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600595class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700596 public:
597 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600598};
599
Ian Elliott2c1daf52016-05-12 09:41:46 -0600600class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700601 public:
602 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600604};
605
Mark Muellerdfe37552016-07-07 14:47:42 -0600606class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700607 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 enum eTestEnFlags {
609 eDoubleDelete,
610 eInvalidDeviceOffset,
611 eInvalidMemoryOffset,
612 eBindNullBuffer,
613 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600614 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600615 };
616
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600618
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
620 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 return true;
622 }
623 VkDeviceSize offset_limit = 0;
624 if (eInvalidMemoryOffset == aTestFlag) {
625 VkBuffer vulkanBuffer;
626 VkBufferCreateInfo buffer_create_info = {};
627 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
628 buffer_create_info.size = 32;
629 buffer_create_info.usage = aBufferUsage;
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600632 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600633
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600634 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
636 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600637 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
638 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600639 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 }
644 if (eOffsetAlignment < offset_limit) {
645 return true;
646 }
647 return false;
648 }
649
650 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
652 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 if (eBindNullBuffer == aTestFlag) {
654 VulkanMemory = 0;
655 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
656 } else {
657 VkBufferCreateInfo buffer_create_info = {};
658 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
659 buffer_create_info.size = 32;
660 buffer_create_info.usage = aBufferUsage;
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663
664 CreateCurrent = true;
665
666 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 VkMemoryAllocateInfo memory_allocate_info = {};
670 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800671 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
673 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 if (!pass) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 return;
677 }
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600680 AllocateCurrent = true;
681 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
683 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600684 BoundCurrent = true;
685
686 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
687 }
688 }
689
690 ~VkBufferTest() {
691 if (CreateCurrent) {
692 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
693 }
694 if (AllocateCurrent) {
695 if (InvalidDeleteEn) {
696 union {
697 VkDeviceMemory device_memory;
698 unsigned long long index_access;
699 } bad_index;
700
701 bad_index.device_memory = VulkanMemory;
702 bad_index.index_access++;
703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600705 }
706 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
707 }
708 }
709
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600710 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600711
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600713
714 void TestDoubleDestroy() {
715 // Destroy the buffer but leave the flag set, which will cause
716 // the buffer to be destroyed again in the destructor.
717 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
718 }
719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700720 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600721 bool AllocateCurrent;
722 bool BoundCurrent;
723 bool CreateCurrent;
724 bool InvalidDeleteEn;
725
726 VkBuffer VulkanBuffer;
727 VkDevice VulkanDevice;
728 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729};
730
731class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600733 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600734 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700735 : BoundCurrent(false),
736 AttributeCount(aAttributeCount),
737 BindingCount(aBindingCount),
738 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600740 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
741 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700742 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600743
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600744 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
745 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
748 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
749 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
750 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
751 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600752
753 unsigned i = 0;
754 do {
755 VertexInputAttributeDescription[i].binding = BindId;
756 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
758 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 i++;
760 } while (AttributeCount < i);
761
762 i = 0;
763 do {
764 VertexInputBindingDescription[i].binding = BindId;
765 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 i++;
768 } while (BindingCount < i);
769 }
770
771 ~VkVerticesObj() {
772 if (VertexInputAttributeDescription) {
773 delete[] VertexInputAttributeDescription;
774 }
775 if (VertexInputBindingDescription) {
776 delete[] VertexInputBindingDescription;
777 }
778 }
779
780 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600781 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
782 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 return true;
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 VkDeviceSize *offsetList;
788 unsigned offsetCount;
789
790 if (aOffsetCount) {
791 offsetList = aOffsetList;
792 offsetCount = aOffsetCount;
793 } else {
794 offsetList = new VkDeviceSize[1]();
795 offsetCount = 1;
796 }
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600799 BoundCurrent = true;
800
801 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600802 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600803 }
804 }
805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700806 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600807 static uint32_t BindIdGenerator;
808
809 bool BoundCurrent;
810 unsigned AttributeCount;
811 unsigned BindingCount;
812 uint32_t BindId;
813
814 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
815 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
816 VkVertexInputBindingDescription *VertexInputBindingDescription;
817 VkConstantBufferObj VulkanMemoryBuffer;
818};
819
820uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500821// ********************************************************************************************************************
822// ********************************************************************************************************************
823// ********************************************************************************************************************
824// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700826 TEST_DESCRIPTION(
827 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
828 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600833 // Specify NULL for a pointer to a handle
834 // Expected to trigger an error with
835 // parameter_validation::validate_required_pointer
836 vkGetPhysicalDeviceFeatures(gpu(), NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
840 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600841 // Specify NULL for pointer to array count
842 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600843 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify 0 for a required array count
848 // Expected to trigger an error with parameter_validation::validate_array
849 VkViewport view_port = {};
850 m_commandBuffer->SetViewport(0, 0, &view_port);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600854 // Specify NULL for a required array
855 // Expected to trigger an error with parameter_validation::validate_array
856 m_commandBuffer->SetViewport(0, 1, NULL);
857 m_errorMonitor->VerifyFound();
858
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600860 // Specify VK_NULL_HANDLE for a required handle
861 // Expected to trigger an error with
862 // parameter_validation::validate_required_handle
863 vkUnmapMemory(device(), VK_NULL_HANDLE);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
867 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify VK_NULL_HANDLE for a required handle array entry
869 // Expected to trigger an error with
870 // parameter_validation::validate_required_handle_array
871 VkFence fence = VK_NULL_HANDLE;
872 vkResetFences(device(), 1, &fence);
873 m_errorMonitor->VerifyFound();
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600876 // Specify NULL for a required struct pointer
877 // Expected to trigger an error with
878 // parameter_validation::validate_struct_type
879 VkDeviceMemory memory = VK_NULL_HANDLE;
880 vkAllocateMemory(device(), NULL, NULL, &memory);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600884 // Specify 0 for a required VkFlags parameter
885 // Expected to trigger an error with parameter_validation::validate_flags
886 m_commandBuffer->SetStencilReference(0, 0);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify 0 for a required VkFlags array entry
891 // Expected to trigger an error with
892 // parameter_validation::validate_flags_array
893 VkSemaphore semaphore = VK_NULL_HANDLE;
894 VkPipelineStageFlags stageFlags = 0;
895 VkSubmitInfo submitInfo = {};
896 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
897 submitInfo.waitSemaphoreCount = 1;
898 submitInfo.pWaitSemaphores = &semaphore;
899 submitInfo.pWaitDstStageMask = &stageFlags;
900 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
901 m_errorMonitor->VerifyFound();
902}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600903
Dustin Gravesfce74c02016-05-10 11:42:58 -0600904TEST_F(VkLayerTest, ReservedParameter) {
905 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600910 // Specify 0 for a reserved VkFlags parameter
911 // Expected to trigger an error with
912 // parameter_validation::validate_reserved_flags
913 VkEvent event_handle = VK_NULL_HANDLE;
914 VkEventCreateInfo event_info = {};
915 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
916 event_info.flags = 1;
917 vkCreateEvent(device(), &event_info, NULL, &event_handle);
918 m_errorMonitor->VerifyFound();
919}
920
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600921TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700922 TEST_DESCRIPTION(
923 "Specify an invalid VkStructureType for a Vulkan "
924 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type
933 VkMemoryAllocateInfo alloc_info = {};
934 VkDeviceMemory memory = VK_NULL_HANDLE;
935 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
936 m_errorMonitor->VerifyFound();
937
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939 // Zero struct memory, effectively setting sType to
940 // VK_STRUCTURE_TYPE_APPLICATION_INFO
941 // Expected to trigger an error with
942 // parameter_validation::validate_struct_type_array
943 VkSubmitInfo submit_info = {};
944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
945 m_errorMonitor->VerifyFound();
946}
947
948TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600950
951 ASSERT_NO_FATAL_FAILURE(InitState());
952
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600954 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600955 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600956 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600957 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600958 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600959 // Zero-initialization will provide the correct sType
960 VkApplicationInfo app_info = {};
961 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
962 event_alloc_info.pNext = &app_info;
963 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
967 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
969 // a function that has allowed pNext structure types and specify
970 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600971 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600972 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600973 VkMemoryAllocateInfo memory_alloc_info = {};
974 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
975 memory_alloc_info.pNext = &app_info;
976 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600977 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600978}
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600981 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600982
983 ASSERT_NO_FATAL_FAILURE(InitState());
984
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
986 "does not fall within the begin..end "
987 "range of the core VkFormat "
988 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkFormat value
990 // Expected to trigger an error with
991 // parameter_validation::validate_ranged_enum
992 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkFlags bitmask value
998 // Expected to trigger an error with parameter_validation::validate_flags
999 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1001 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001002 m_errorMonitor->VerifyFound();
1003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001005 // Specify an invalid VkFlags array entry
1006 // Expected to trigger an error with
1007 // parameter_validation::validate_flags_array
1008 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001010 VkSubmitInfo submit_info = {};
1011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1012 submit_info.waitSemaphoreCount = 1;
1013 submit_info.pWaitSemaphores = &semaphore;
1014 submit_info.pWaitDstStageMask = &stage_flags;
1015 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkBool32 value
1020 // Expected to trigger a warning with
1021 // parameter_validation::validate_bool32
1022 VkSampler sampler = VK_NULL_HANDLE;
1023 VkSamplerCreateInfo sampler_info = {};
1024 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1025 sampler_info.pNext = NULL;
1026 sampler_info.magFilter = VK_FILTER_NEAREST;
1027 sampler_info.minFilter = VK_FILTER_NEAREST;
1028 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1029 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1030 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1031 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1032 sampler_info.mipLodBias = 1.0;
1033 sampler_info.maxAnisotropy = 1;
1034 sampler_info.compareEnable = VK_FALSE;
1035 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1036 sampler_info.minLod = 1.0;
1037 sampler_info.maxLod = 1.0;
1038 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1039 sampler_info.unnormalizedCoordinates = VK_FALSE;
1040 // Not VK_TRUE or VK_FALSE
1041 sampler_info.anisotropyEnable = 3;
1042 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1043 m_errorMonitor->VerifyFound();
1044}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045
1046TEST_F(VkLayerTest, FailedReturnValue) {
1047 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1048
1049 ASSERT_NO_FATAL_FAILURE(InitState());
1050
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001051 // Find an unsupported image format
1052 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1053 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1054 VkFormat format = static_cast<VkFormat>(f);
1055 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001057 unsupported = format;
1058 break;
1059 }
1060 }
1061
1062 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1064 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Specify an unsupported VkFormat value to generate a
1066 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1067 // Expected to trigger a warning from
1068 // parameter_validation::validate_result
1069 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1071 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001072 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1073 m_errorMonitor->VerifyFound();
1074 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001075}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077TEST_F(VkLayerTest, UpdateBufferAlignment) {
1078 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080
1081 ASSERT_NO_FATAL_FAILURE(InitState());
1082
1083 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1084 vk_testing::Buffer buffer;
1085 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1086
Tony Barbour552f6c02016-12-21 14:34:07 -07001087 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using dataSize that is < 0
1099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using dataSize that is > 65536
1105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001106 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001107 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1108 m_errorMonitor->VerifyFound();
1109
Tony Barbour552f6c02016-12-21 14:34:07 -07001110 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111}
1112
1113TEST_F(VkLayerTest, FillBufferAlignment) {
1114 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1115
1116 ASSERT_NO_FATAL_FAILURE(InitState());
1117
1118 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1119 vk_testing::Buffer buffer;
1120 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123
1124 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
1129 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1132 m_errorMonitor->VerifyFound();
1133
1134 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1137 m_errorMonitor->VerifyFound();
1138
Tony Barbour552f6c02016-12-21 14:34:07 -07001139 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140}
Dustin Graves40f35822016-06-23 11:12:53 -06001141
Cortd889ff92016-07-27 09:51:27 -07001142TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1143 VkResult err;
1144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001145 TEST_DESCRIPTION(
1146 "Attempt to use a non-solid polygon fill mode in a "
1147 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001148
1149 ASSERT_NO_FATAL_FAILURE(InitState());
1150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1151
1152 std::vector<const char *> device_extension_names;
1153 auto features = m_device->phy().features();
1154 // Artificially disable support for non-solid fill modes
1155 features.fillModeNonSolid = false;
1156 // The sacrificial device object
1157 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1158
1159 VkRenderpassObj render_pass(&test_device);
1160
1161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1163 pipeline_layout_ci.setLayoutCount = 0;
1164 pipeline_layout_ci.pSetLayouts = NULL;
1165
1166 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001168 ASSERT_VK_SUCCESS(err);
1169
1170 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1171 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1172 rs_ci.pNext = nullptr;
1173 rs_ci.lineWidth = 1.0f;
1174 rs_ci.rasterizerDiscardEnable = true;
1175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001176 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1177 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001178
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001179 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1181 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001182 {
1183 VkPipelineObj pipe(&test_device);
1184 pipe.AddShader(&vs);
1185 pipe.AddShader(&fs);
1186 pipe.AddColorAttachment();
1187 // Introduce failure by setting unsupported polygon mode
1188 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1189 pipe.SetRasterization(&rs_ci);
1190 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1191 }
1192 m_errorMonitor->VerifyFound();
1193
1194 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1196 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001197 {
1198 VkPipelineObj pipe(&test_device);
1199 pipe.AddShader(&vs);
1200 pipe.AddShader(&fs);
1201 pipe.AddColorAttachment();
1202 // Introduce failure by setting unsupported polygon mode
1203 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1204 pipe.SetRasterization(&rs_ci);
1205 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1206 }
1207 m_errorMonitor->VerifyFound();
1208
Cortd889ff92016-07-27 09:51:27 -07001209 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1210}
1211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001212#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214{
1215 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001216 VkFenceCreateInfo fenceInfo = {};
1217 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1218 fenceInfo.pNext = NULL;
1219 fenceInfo.flags = 0;
1220
Mike Weiblencce7ec72016-10-17 19:33:05 -06001221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001222
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001224
1225 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1226 vk_testing::Buffer buffer;
1227 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228
Tony Barbourfe3351b2015-07-28 10:17:20 -06001229 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001230 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001231 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232
1233 testFence.init(*m_device, fenceInfo);
1234
1235 // Bypass framework since it does the waits automatically
1236 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001237 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1239 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001240 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001241 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001242 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001243 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001246 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001247
1248 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001249 ASSERT_VK_SUCCESS( err );
1250
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001253
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001254 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001255}
1256
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258{
1259 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001260 VkFenceCreateInfo fenceInfo = {};
1261 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1262 fenceInfo.pNext = NULL;
1263 fenceInfo.flags = 0;
1264
Mike Weiblencce7ec72016-10-17 19:33:05 -06001265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001266
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267 ASSERT_NO_FATAL_FAILURE(InitState());
1268 ASSERT_NO_FATAL_FAILURE(InitViewport());
1269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1270
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001272 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001273 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274
1275 testFence.init(*m_device, fenceInfo);
1276
1277 // Bypass framework since it does the waits automatically
1278 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001279 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1281 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001282 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001283 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001284 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001287 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001288 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001289
1290 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 ASSERT_VK_SUCCESS( err );
1292
Jon Ashburnf19916e2016-01-11 13:12:43 -07001293 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 VkCommandBufferBeginInfo info = {};
1295 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1296 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001297 info.renderPass = VK_NULL_HANDLE;
1298 info.subpass = 0;
1299 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001300 info.occlusionQueryEnable = VK_FALSE;
1301 info.queryFlags = 0;
1302 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001303
1304 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001305 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001307 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001310
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001311TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1312 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1313
1314 ASSERT_NO_FATAL_FAILURE(InitState());
1315
1316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1317 VkBuffer buffer;
1318 VkBufferCreateInfo buf_info = {};
1319 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1320 buf_info.pNext = NULL;
1321 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1322 buf_info.size = 2048;
1323 buf_info.queueFamilyIndexCount = 0;
1324 buf_info.pQueueFamilyIndices = NULL;
1325 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1326 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1327 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1328 m_errorMonitor->VerifyFound();
1329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1331 VkImage image;
1332 VkImageCreateInfo image_create_info = {};
1333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1334 image_create_info.pNext = NULL;
1335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1336 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1337 image_create_info.extent.width = 512;
1338 image_create_info.extent.height = 64;
1339 image_create_info.extent.depth = 1;
1340 image_create_info.mipLevels = 1;
1341 image_create_info.arrayLayers = 1;
1342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1350 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1351 m_errorMonitor->VerifyFound();
1352}
1353
Dave Houlton829c0d82017-01-24 15:09:17 -07001354TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1355 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1356
1357 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001358 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001359 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1360
1361 // Mask out device features we don't want
1362 VkPhysicalDeviceFeatures desired_features = available_features;
1363 desired_features.sparseResidencyImage2D = VK_FALSE;
1364 desired_features.sparseResidencyImage3D = VK_FALSE;
1365 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1366
1367 VkImage image = VK_NULL_HANDLE;
1368 VkResult result = VK_RESULT_MAX_ENUM;
1369 VkImageCreateInfo image_create_info = {};
1370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1371 image_create_info.pNext = NULL;
1372 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1373 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1374 image_create_info.extent.width = 512;
1375 image_create_info.extent.height = 1;
1376 image_create_info.extent.depth = 1;
1377 image_create_info.mipLevels = 1;
1378 image_create_info.arrayLayers = 1;
1379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1381 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1383 image_create_info.queueFamilyIndexCount = 0;
1384 image_create_info.pQueueFamilyIndices = NULL;
1385 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1386 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1387
1388 // 1D image w/ sparse residency is an error
1389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1390 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392 if (VK_SUCCESS == result) {
1393 vkDestroyImage(m_device->device(), image, NULL);
1394 image = VK_NULL_HANDLE;
1395 }
1396
1397 // 2D image w/ sparse residency when feature isn't available
1398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1399 image_create_info.extent.height = 64;
1400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1401 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1402 m_errorMonitor->VerifyFound();
1403 if (VK_SUCCESS == result) {
1404 vkDestroyImage(m_device->device(), image, NULL);
1405 image = VK_NULL_HANDLE;
1406 }
1407
1408 // 3D image w/ sparse residency when feature isn't available
1409 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1410 image_create_info.extent.depth = 8;
1411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1412 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1413 m_errorMonitor->VerifyFound();
1414 if (VK_SUCCESS == result) {
1415 vkDestroyImage(m_device->device(), image, NULL);
1416 image = VK_NULL_HANDLE;
1417 }
1418}
1419
1420TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1421 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1422
1423 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001424 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001425 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1426
1427 // These tests all require that the device support sparse residency for 2D images
1428 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1429 return;
1430 }
1431
1432 // Mask out device features we don't want
1433 VkPhysicalDeviceFeatures desired_features = available_features;
1434 desired_features.sparseResidency2Samples = VK_FALSE;
1435 desired_features.sparseResidency4Samples = VK_FALSE;
1436 desired_features.sparseResidency8Samples = VK_FALSE;
1437 desired_features.sparseResidency16Samples = VK_FALSE;
1438 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1439
1440 VkImage image = VK_NULL_HANDLE;
1441 VkResult result = VK_RESULT_MAX_ENUM;
1442 VkImageCreateInfo image_create_info = {};
1443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1444 image_create_info.pNext = NULL;
1445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1446 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1447 image_create_info.extent.width = 64;
1448 image_create_info.extent.height = 64;
1449 image_create_info.extent.depth = 1;
1450 image_create_info.mipLevels = 1;
1451 image_create_info.arrayLayers = 1;
1452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1454 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1455 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1456 image_create_info.queueFamilyIndexCount = 0;
1457 image_create_info.pQueueFamilyIndices = NULL;
1458 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1459 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1460
1461 // 2D image w/ sparse residency and linear tiling is an error
1462 m_errorMonitor->SetDesiredFailureMsg(
1463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1464 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1465 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1466 m_errorMonitor->VerifyFound();
1467 if (VK_SUCCESS == result) {
1468 vkDestroyImage(m_device->device(), image, NULL);
1469 image = VK_NULL_HANDLE;
1470 }
1471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1472
1473 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1474 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482
1483 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1485 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1486 m_errorMonitor->VerifyFound();
1487 if (VK_SUCCESS == result) {
1488 vkDestroyImage(m_device->device(), image, NULL);
1489 image = VK_NULL_HANDLE;
1490 }
1491
1492 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1494 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1495 m_errorMonitor->VerifyFound();
1496 if (VK_SUCCESS == result) {
1497 vkDestroyImage(m_device->device(), image, NULL);
1498 image = VK_NULL_HANDLE;
1499 }
1500
1501 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1503 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1504 m_errorMonitor->VerifyFound();
1505 if (VK_SUCCESS == result) {
1506 vkDestroyImage(m_device->device(), image, NULL);
1507 image = VK_NULL_HANDLE;
1508 }
1509}
1510
Tobin Ehlisf11be982016-05-11 13:52:53 -06001511TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 TEST_DESCRIPTION(
1513 "Create a buffer and image, allocate memory, and bind the "
1514 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001515 VkResult err;
1516 bool pass;
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518
Tobin Ehlis077ded32016-05-12 17:39:13 -06001519 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001520 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001521 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001522 VkDeviceMemory mem; // buffer will be bound first
1523 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001524 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001525 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkBufferCreateInfo buf_info = {};
1528 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1529 buf_info.pNext = NULL;
1530 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1531 buf_info.size = 256;
1532 buf_info.queueFamilyIndexCount = 0;
1533 buf_info.pQueueFamilyIndices = NULL;
1534 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1535 buf_info.flags = 0;
1536 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1537 ASSERT_VK_SUCCESS(err);
1538
Tobin Ehlis077ded32016-05-12 17:39:13 -06001539 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540
1541 VkImageCreateInfo image_create_info = {};
1542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1543 image_create_info.pNext = NULL;
1544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1545 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1546 image_create_info.extent.width = 64;
1547 image_create_info.extent.height = 64;
1548 image_create_info.extent.depth = 1;
1549 image_create_info.mipLevels = 1;
1550 image_create_info.arrayLayers = 1;
1551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001552 // Image tiling must be optimal to trigger error when aliasing linear buffer
1553 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1556 image_create_info.queueFamilyIndexCount = 0;
1557 image_create_info.pQueueFamilyIndices = NULL;
1558 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1559 image_create_info.flags = 0;
1560
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1562 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1564 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001565
Tobin Ehlis077ded32016-05-12 17:39:13 -06001566 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1567
1568 VkMemoryAllocateInfo alloc_info = {};
1569 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1570 alloc_info.pNext = NULL;
1571 alloc_info.memoryTypeIndex = 0;
1572 // Ensure memory is big enough for both bindings
1573 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1575 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001576 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001577 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001579 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001580 return;
1581 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1583 ASSERT_VK_SUCCESS(err);
1584 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1585 ASSERT_VK_SUCCESS(err);
1586
Rene Lindsayd14f5572016-12-16 14:57:18 -07001587 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1588
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1592 m_errorMonitor->VerifyFound();
1593
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001594 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 // aliasing buffer2
1596 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1597 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001598 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001603 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001604 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001605 m_errorMonitor->VerifyFound();
1606
1607 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001608 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001609 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001610 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001611 vkFreeMemory(m_device->device(), mem, NULL);
1612 vkFreeMemory(m_device->device(), mem_img, NULL);
1613}
1614
Tobin Ehlis35372522016-05-12 08:32:31 -06001615TEST_F(VkLayerTest, InvalidMemoryMapping) {
1616 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1617 VkResult err;
1618 bool pass;
1619 ASSERT_NO_FATAL_FAILURE(InitState());
1620
1621 VkBuffer buffer;
1622 VkDeviceMemory mem;
1623 VkMemoryRequirements mem_reqs;
1624
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001625 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1626
Tobin Ehlis35372522016-05-12 08:32:31 -06001627 VkBufferCreateInfo buf_info = {};
1628 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1629 buf_info.pNext = NULL;
1630 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1631 buf_info.size = 256;
1632 buf_info.queueFamilyIndexCount = 0;
1633 buf_info.pQueueFamilyIndices = NULL;
1634 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1635 buf_info.flags = 0;
1636 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1637 ASSERT_VK_SUCCESS(err);
1638
1639 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1640 VkMemoryAllocateInfo alloc_info = {};
1641 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1642 alloc_info.pNext = NULL;
1643 alloc_info.memoryTypeIndex = 0;
1644
1645 // Ensure memory is big enough for both bindings
1646 static const VkDeviceSize allocation_size = 0x10000;
1647 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 if (!pass) {
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
1651 return;
1652 }
1653 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 uint8_t *pData;
1657 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001659 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1660 m_errorMonitor->VerifyFound();
1661 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001663 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1665 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1666 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001667 m_errorMonitor->VerifyFound();
1668
1669 // Unmap the memory to avoid re-map error
1670 vkUnmapMemory(m_device->device(), mem);
1671 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1673 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1674 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 m_errorMonitor->VerifyFound();
1676 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1678 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 m_errorMonitor->VerifyFound();
1680 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 vkUnmapMemory(m_device->device(), mem);
1683 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 ASSERT_VK_SUCCESS(err);
1688 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001689 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001695
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 // Now flush range that oversteps mapped range
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001701 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1707 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001708 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001710 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001711 mmr.size = VK_WHOLE_SIZE;
1712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1714 m_errorMonitor->VerifyFound();
1715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001716#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001717 // Some platforms have an atomsize of 1 which makes the test meaningless
1718 if (atom_size > 3) {
1719 // Now with an offset NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = 3; // Not a multiple of atom_size
1724 mmr.size = VK_WHOLE_SIZE;
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Now with a size NOT a multiple of the device limit
1730 vkUnmapMemory(m_device->device(), mem);
1731 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1732 ASSERT_VK_SUCCESS(err);
1733 mmr.offset = atom_size;
1734 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
1738 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001739#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1741 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 if (!pass) {
1743 vkFreeMemory(m_device->device(), mem, NULL);
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 return;
1746 }
1747 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1748 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1749
1750 vkDestroyBuffer(m_device->device(), buffer, NULL);
1751 vkFreeMemory(m_device->device(), mem, NULL);
1752}
1753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001754#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001755TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1756 VkResult err;
1757 bool pass;
1758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1760 // following declaration (which is temporarily being moved below):
1761 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001762 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001765 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001766 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001768
1769 ASSERT_NO_FATAL_FAILURE(InitState());
1770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1772#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1773 // Use the functions from the VK_KHR_android_surface extension without
1774 // enabling that extension:
1775
1776 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001777 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1779 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001780 pass = (err != VK_SUCCESS);
1781 ASSERT_TRUE(pass);
1782 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001783#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784
Ian Elliott3f06ce52016-04-29 14:46:21 -06001785#if defined(VK_USE_PLATFORM_MIR_KHR)
1786 // Use the functions from the VK_KHR_mir_surface extension without enabling
1787 // that extension:
1788
1789 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001790 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1793 pass = (err != VK_SUCCESS);
1794 ASSERT_TRUE(pass);
1795 m_errorMonitor->VerifyFound();
1796
1797 // Tell whether an mir_connection supports presentation:
1798 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1800 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001802#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001803
Ian Elliott3f06ce52016-04-29 14:46:21 -06001804#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1805 // Use the functions from the VK_KHR_wayland_surface extension without
1806 // enabling that extension:
1807
1808 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001809 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1811 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812 pass = (err != VK_SUCCESS);
1813 ASSERT_TRUE(pass);
1814 m_errorMonitor->VerifyFound();
1815
1816 // Tell whether an wayland_display supports presentation:
1817 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1819 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001821#endif // VK_USE_PLATFORM_WAYLAND_KHR
1822#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823
Ian Elliott3f06ce52016-04-29 14:46:21 -06001824#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001825 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1826 // TO NON-LINUX PLATFORMS:
1827 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 // Use the functions from the VK_KHR_win32_surface extension without
1829 // enabling that extension:
1830
1831 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001832 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1834 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 pass = (err != VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837 m_errorMonitor->VerifyFound();
1838
1839 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001841 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001842 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001843// Set this (for now, until all platforms are supported and tested):
1844#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001846#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1848 // TO NON-LINUX PLATFORMS:
1849 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001850#endif
1851#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001852 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1853 // that extension:
1854
1855 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001856 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1859 pass = (err != VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861 m_errorMonitor->VerifyFound();
1862
1863 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001864 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001865 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1867 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001868 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001869// Set this (for now, until all platforms are supported and tested):
1870#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001871#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001872
Ian Elliott12630812016-04-29 14:35:43 -06001873#if defined(VK_USE_PLATFORM_XLIB_KHR)
1874 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1875 // that extension:
1876
1877 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001878 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001880 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1881 pass = (err != VK_SUCCESS);
1882 ASSERT_TRUE(pass);
1883 m_errorMonitor->VerifyFound();
1884
1885 // Tell whether an Xlib VisualID supports presentation:
1886 Display *dpy = NULL;
1887 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001889 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1890 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001891// Set this (for now, until all platforms are supported and tested):
1892#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001893#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895// Use the functions from the VK_KHR_surface extension without enabling
1896// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001897
Ian Elliott489eec02016-05-05 14:12:44 -06001898#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001899 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 vkDestroySurfaceKHR(instance(), surface, NULL);
1902 m_errorMonitor->VerifyFound();
1903
1904 // Check if surface supports presentation:
1905 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001907 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1908 pass = (err != VK_SUCCESS);
1909 ASSERT_TRUE(pass);
1910 m_errorMonitor->VerifyFound();
1911
1912 // Check surface capabilities:
1913 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1915 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 pass = (err != VK_SUCCESS);
1917 ASSERT_TRUE(pass);
1918 m_errorMonitor->VerifyFound();
1919
1920 // Check surface formats:
1921 uint32_t format_count = 0;
1922 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1924 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface present modes:
1930 uint32_t present_mode_count = 0;
1931 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1933 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 pass = (err != VK_SUCCESS);
1935 ASSERT_TRUE(pass);
1936 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001937#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001938
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 // Use the functions from the VK_KHR_swapchain extension without enabling
1940 // that extension:
1941
1942 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1945 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001947 pass = (err != VK_SUCCESS);
1948 ASSERT_TRUE(pass);
1949 m_errorMonitor->VerifyFound();
1950
1951 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1953 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001954 pass = (err != VK_SUCCESS);
1955 ASSERT_TRUE(pass);
1956 m_errorMonitor->VerifyFound();
1957
Chris Forbeseb7d5502016-09-13 18:19:21 +12001958 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1959 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1960 VkFence fence;
1961 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1962
Ian Elliott1c32c772016-04-28 14:47:13 -06001963 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001965 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 pass = (err != VK_SUCCESS);
1967 ASSERT_TRUE(pass);
1968 m_errorMonitor->VerifyFound();
1969
Chris Forbeseb7d5502016-09-13 18:19:21 +12001970 vkDestroyFence(m_device->device(), fence, nullptr);
1971
Ian Elliott1c32c772016-04-28 14:47:13 -06001972 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001973 //
1974 // NOTE: Currently can't test this because a real swapchain is needed (as
1975 // opposed to the fake one we created) in order for the layer to lookup the
1976 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001977
1978 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1981 m_errorMonitor->VerifyFound();
1982}
Chris Forbes09368e42016-10-13 11:59:22 +13001983#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1986 VkResult err;
1987 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1990 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001991
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
1994 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001995 VkImage image;
1996 VkDeviceMemory mem;
1997 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001998
Karl Schultz6addd812016-02-02 17:17:23 -07001999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2000 const int32_t tex_width = 32;
2001 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002
Tony Barboureb254902015-07-15 12:50:33 -06002003 VkImageCreateInfo image_create_info = {};
2004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002005 image_create_info.pNext = NULL;
2006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2007 image_create_info.format = tex_format;
2008 image_create_info.extent.width = tex_width;
2009 image_create_info.extent.height = tex_height;
2010 image_create_info.extent.depth = 1;
2011 image_create_info.mipLevels = 1;
2012 image_create_info.arrayLayers = 1;
2013 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2016 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002018
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002019 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002020 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002021 mem_alloc.pNext = NULL;
2022 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002023
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002025 ASSERT_VK_SUCCESS(err);
2026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Mark Lobodzinski23065352015-05-29 09:32:35 -05002029 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002032 if (!pass) { // If we can't find any unmappable memory this test doesn't
2033 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002034 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002035 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002036 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002037
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002038 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040 ASSERT_VK_SUCCESS(err);
2041
2042 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map memory as if to initialize the image
2047 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002049
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002051
Chia-I Wuf7458c52015-10-26 21:10:41 +08002052 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002053 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002054}
2055
Karl Schultz6addd812016-02-02 17:17:23 -07002056TEST_F(VkLayerTest, RebindMemory) {
2057 VkResult err;
2058 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002061
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
2064 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002065 VkImage image;
2066 VkDeviceMemory mem1;
2067 VkDeviceMemory mem2;
2068 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2071 const int32_t tex_width = 32;
2072 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002073
Tony Barboureb254902015-07-15 12:50:33 -06002074 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2076 image_create_info.pNext = NULL;
2077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2078 image_create_info.format = tex_format;
2079 image_create_info.extent.width = tex_width;
2080 image_create_info.extent.height = tex_height;
2081 image_create_info.extent.depth = 1;
2082 image_create_info.mipLevels = 1;
2083 image_create_info.arrayLayers = 1;
2084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2085 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2087 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002089 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2091 mem_alloc.pNext = NULL;
2092 mem_alloc.allocationSize = 0;
2093 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002094
Karl Schultz6addd812016-02-02 17:17:23 -07002095 // Introduce failure, do NOT set memProps to
2096 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002097 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
2100
Karl Schultz6addd812016-02-02 17:17:23 -07002101 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
2103 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002105 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002108 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002114 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002115 ASSERT_VK_SUCCESS(err);
2116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 // Introduce validation failure, try to bind a different memory object to
2118 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002119 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002122
Chia-I Wuf7458c52015-10-26 21:10:41 +08002123 vkDestroyImage(m_device->device(), image, NULL);
2124 vkFreeMemory(m_device->device(), mem1, NULL);
2125 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002129 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2132 "submitted in SIGNALED state. Fences "
2133 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002134
2135 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002136 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2137 fenceInfo.pNext = NULL;
2138 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002139
Tony Barbour300a6082015-04-07 13:44:53 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitViewport());
2142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2143
Tony Barbour552f6c02016-12-21 14:34:07 -07002144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002145 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002146 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002147
2148 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002150 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2152 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002153 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002154 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002155 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002156 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002157 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002158 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002159 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002160
2161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002162 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002165}
Chris Forbes4e44c912016-06-16 10:20:00 +12002166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002168 TEST_DESCRIPTION(
2169 "Specify wrong usage for image then create conflicting view of image "
2170 "Initialize buffer with wrong usage then perform copy expecting errors "
2171 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002173
2174 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002175
Tony Barbourf887b162017-03-09 10:06:46 -07002176 auto format = find_depth_stencil_format(m_device);
2177 if (!format) {
2178 printf(" No Depth + Stencil format found. Skipped.\n");
2179 return;
2180 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002181
Tony Barbourf92621a2016-05-02 14:28:12 -06002182 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002183 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002184 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002185 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002186
Tony Barbourf92621a2016-05-02 14:28:12 -06002187 VkImageView dsv;
2188 VkImageViewCreateInfo dsvci = {};
2189 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2190 dsvci.image = image.handle();
2191 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002192 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002193 dsvci.subresourceRange.layerCount = 1;
2194 dsvci.subresourceRange.baseMipLevel = 0;
2195 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 // Create a view with depth / stencil aspect for image with different usage
2199 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002201 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002202
2203 // Initialize buffer with TRANSFER_DST usage
2204 vk_testing::Buffer buffer;
2205 VkMemoryPropertyFlags reqs = 0;
2206 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2207 VkBufferImageCopy region = {};
2208 region.bufferRowLength = 128;
2209 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002210 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 region.imageSubresource.layerCount = 1;
2212 region.imageExtent.height = 16;
2213 region.imageExtent.width = 16;
2214 region.imageExtent.depth = 1;
2215
Mark Lobodzinski80871462017-02-16 10:37:27 -07002216 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002217 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
Chris Forbesda581202016-10-06 18:25:26 +13002219 // two separate errors from this call:
2220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2224 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002225 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002226}
Tony Barbour75d79f02016-08-30 09:39:07 -06002227
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228TEST_F(VkLayerTest, LeakAnObject) {
2229 VkResult err;
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232
2233 // Note that we have to create a new device since destroying the
2234 // framework's device causes Teardown() to fail and just calling Teardown
2235 // will destroy the errorMonitor.
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002238
2239 ASSERT_NO_FATAL_FAILURE(InitState());
2240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002241 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<VkDeviceQueueCreateInfo> queue_info;
2243 queue_info.reserve(queue_props.size());
2244 std::vector<std::vector<float>> queue_priorities;
2245 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2246 VkDeviceQueueCreateInfo qi = {};
2247 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2248 qi.pNext = NULL;
2249 qi.queueFamilyIndex = i;
2250 qi.queueCount = queue_props[i].queueCount;
2251 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2252 qi.pQueuePriorities = queue_priorities[i].data();
2253 queue_info.push_back(qi);
2254 }
2255
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002257
2258 // The sacrificial device object
2259 VkDevice testDevice;
2260 VkDeviceCreateInfo device_create_info = {};
2261 auto features = m_device->phy().features();
2262 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2263 device_create_info.pNext = NULL;
2264 device_create_info.queueCreateInfoCount = queue_info.size();
2265 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002266 device_create_info.enabledLayerCount = 0;
2267 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002268 device_create_info.pEnabledFeatures = &features;
2269 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 VkFence fence;
2273 VkFenceCreateInfo fence_create_info = {};
2274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2275 fence_create_info.pNext = NULL;
2276 fence_create_info.flags = 0;
2277 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2278 ASSERT_VK_SUCCESS(err);
2279
2280 // Induce failure by not calling vkDestroyFence
2281 vkDestroyDevice(testDevice, NULL);
2282 m_errorMonitor->VerifyFound();
2283}
2284
2285TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002286 TEST_DESCRIPTION(
2287 "Allocate command buffers from one command pool and "
2288 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291
Cody Northropc31a84f2016-08-22 10:41:47 -06002292 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 VkCommandPool command_pool_one;
2294 VkCommandPool command_pool_two;
2295
2296 VkCommandPoolCreateInfo pool_create_info{};
2297 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2298 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2299 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002301 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002303 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002305 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002306 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002307 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002308 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002309 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002311 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002313 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
2315 m_errorMonitor->VerifyFound();
2316
2317 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2318 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2319}
2320
2321TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2322 VkResult err;
2323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002324 TEST_DESCRIPTION(
2325 "Allocate descriptor sets from one DS pool and "
2326 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2332
2333 VkDescriptorPoolSize ds_type_count = {};
2334 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2335 ds_type_count.descriptorCount = 1;
2336
2337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2339 ds_pool_ci.pNext = NULL;
2340 ds_pool_ci.flags = 0;
2341 ds_pool_ci.maxSets = 1;
2342 ds_pool_ci.poolSizeCount = 1;
2343 ds_pool_ci.pPoolSizes = &ds_type_count;
2344
2345 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_VK_SUCCESS(err);
2348
2349 // Create a second descriptor pool
2350 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 ASSERT_VK_SUCCESS(err);
2353
2354 VkDescriptorSetLayoutBinding dsl_binding = {};
2355 dsl_binding.binding = 0;
2356 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2357 dsl_binding.descriptorCount = 1;
2358 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2359 dsl_binding.pImmutableSamplers = NULL;
2360
2361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2363 ds_layout_ci.pNext = NULL;
2364 ds_layout_ci.bindingCount = 1;
2365 ds_layout_ci.pBindings = &dsl_binding;
2366
2367 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369 ASSERT_VK_SUCCESS(err);
2370
2371 VkDescriptorSet descriptorSet;
2372 VkDescriptorSetAllocateInfo alloc_info = {};
2373 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2374 alloc_info.descriptorSetCount = 1;
2375 alloc_info.descriptorPool = ds_pool_one;
2376 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378 ASSERT_VK_SUCCESS(err);
2379
2380 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2381
2382 m_errorMonitor->VerifyFound();
2383
2384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2385 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2386 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2387}
2388
2389TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002393
2394 ASSERT_NO_FATAL_FAILURE(InitState());
2395
2396 // Pass bogus handle into GetImageMemoryRequirements
2397 VkMemoryRequirements mem_reqs;
2398 uint64_t fakeImageHandle = 0xCADECADE;
2399 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2400
2401 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2402
2403 m_errorMonitor->VerifyFound();
2404}
2405
Mike Schuchardt17838902017-02-21 09:48:06 -07002406TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2407 TEST_DESCRIPTION(
2408 "Try to destroy a render pass object using a device other than the one it was created on. "
2409 "This should generate a distinct error from the invalid handle error.");
2410 // Create first device and renderpass
2411 ASSERT_NO_FATAL_FAILURE(InitState());
2412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2413
2414 // Create second device
2415 float priorities[] = {1.0f};
2416 VkDeviceQueueCreateInfo queue_info{};
2417 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2418 queue_info.pNext = NULL;
2419 queue_info.flags = 0;
2420 queue_info.queueFamilyIndex = 0;
2421 queue_info.queueCount = 1;
2422 queue_info.pQueuePriorities = &priorities[0];
2423
2424 VkDeviceCreateInfo device_create_info = {};
2425 auto features = m_device->phy().features();
2426 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2427 device_create_info.pNext = NULL;
2428 device_create_info.queueCreateInfoCount = 1;
2429 device_create_info.pQueueCreateInfos = &queue_info;
2430 device_create_info.enabledLayerCount = 0;
2431 device_create_info.ppEnabledLayerNames = NULL;
2432 device_create_info.pEnabledFeatures = &features;
2433
2434 VkDevice second_device;
2435 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2436
2437 // Try to destroy the renderpass from the first device using the second device
2438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2439 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2440 m_errorMonitor->VerifyFound();
2441
2442 vkDestroyDevice(second_device, NULL);
2443}
2444
Karl Schultz6addd812016-02-02 17:17:23 -07002445TEST_F(VkLayerTest, PipelineNotBound) {
2446 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002448 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002449
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002451
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002455 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2457 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458
2459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2461 ds_pool_ci.pNext = NULL;
2462 ds_pool_ci.maxSets = 1;
2463 ds_pool_ci.poolSizeCount = 1;
2464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002465
2466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002471 dsl_binding.binding = 0;
2472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 dsl_binding.descriptorCount = 1;
2474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2475 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002476
2477 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002478 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2479 ds_layout_ci.pNext = NULL;
2480 ds_layout_ci.bindingCount = 1;
2481 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002482
2483 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002490 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002491 alloc_info.descriptorPool = ds_pool;
2492 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
2496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2498 pipeline_layout_ci.pNext = NULL;
2499 pipeline_layout_ci.setLayoutCount = 1;
2500 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
2502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002504 ASSERT_VK_SUCCESS(err);
2505
Mark Youngad779052016-01-06 14:26:04 -07002506 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
Tony Barbour552f6c02016-12-21 14:34:07 -07002508 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002511 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002512
Chia-I Wuf7458c52015-10-26 21:10:41 +08002513 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2514 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002516}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002517
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002518TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2519 VkResult err;
2520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002521 TEST_DESCRIPTION(
2522 "Test validation check for an invalid memory type index "
2523 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002524
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002525 ASSERT_NO_FATAL_FAILURE(InitState());
2526
2527 // Create an image, allocate memory, set a bad typeIndex and then try to
2528 // bind it
2529 VkImage image;
2530 VkDeviceMemory mem;
2531 VkMemoryRequirements mem_reqs;
2532 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2533 const int32_t tex_width = 32;
2534 const int32_t tex_height = 32;
2535
2536 VkImageCreateInfo image_create_info = {};
2537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2538 image_create_info.pNext = NULL;
2539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2540 image_create_info.format = tex_format;
2541 image_create_info.extent.width = tex_width;
2542 image_create_info.extent.height = tex_height;
2543 image_create_info.extent.depth = 1;
2544 image_create_info.mipLevels = 1;
2545 image_create_info.arrayLayers = 1;
2546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2547 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2549 image_create_info.flags = 0;
2550
2551 VkMemoryAllocateInfo mem_alloc = {};
2552 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2553 mem_alloc.pNext = NULL;
2554 mem_alloc.allocationSize = 0;
2555 mem_alloc.memoryTypeIndex = 0;
2556
2557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2558 ASSERT_VK_SUCCESS(err);
2559
2560 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2561 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562
2563 // Introduce Failure, select invalid TypeIndex
2564 VkPhysicalDeviceMemoryProperties memory_info;
2565
2566 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2567 unsigned int i;
2568 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2569 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2570 mem_alloc.memoryTypeIndex = i;
2571 break;
2572 }
2573 }
2574 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002575 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002576 vkDestroyImage(m_device->device(), image, NULL);
2577 return;
2578 }
2579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002581
2582 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2583 ASSERT_VK_SUCCESS(err);
2584
2585 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2586 (void)err;
2587
2588 m_errorMonitor->VerifyFound();
2589
2590 vkDestroyImage(m_device->device(), image, NULL);
2591 vkFreeMemory(m_device->device(), mem, NULL);
2592}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002593
Karl Schultz6addd812016-02-02 17:17:23 -07002594TEST_F(VkLayerTest, BindInvalidMemory) {
2595 VkResult err;
2596 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002597
2598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002599
Cortf801b982017-01-17 18:10:21 -08002600 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002601 const int32_t tex_width = 256;
2602 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
2604 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2606 image_create_info.pNext = NULL;
2607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2608 image_create_info.format = tex_format;
2609 image_create_info.extent.width = tex_width;
2610 image_create_info.extent.height = tex_height;
2611 image_create_info.extent.depth = 1;
2612 image_create_info.mipLevels = 1;
2613 image_create_info.arrayLayers = 1;
2614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2617 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002618
Cortf801b982017-01-17 18:10:21 -08002619 VkBufferCreateInfo buffer_create_info = {};
2620 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2621 buffer_create_info.pNext = NULL;
2622 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002623 buffer_create_info.size = 4 * 1024 * 1024;
2624 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002625 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002626
Cortf801b982017-01-17 18:10:21 -08002627 // Create an image/buffer, allocate memory, free it, and then try to bind it
2628 {
2629 VkImage image = VK_NULL_HANDLE;
2630 VkBuffer buffer = VK_NULL_HANDLE;
2631 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2632 ASSERT_VK_SUCCESS(err);
2633 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2634 ASSERT_VK_SUCCESS(err);
2635 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2636 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2637 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2640 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2641 image_mem_alloc.allocationSize = image_mem_reqs.size;
2642 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2643 ASSERT_TRUE(pass);
2644 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2645 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2646 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2647 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2650 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2651 ASSERT_VK_SUCCESS(err);
2652 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2653 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 vkFreeMemory(device(), image_mem, NULL);
2656 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2659 err = vkBindImageMemory(device(), image, image_mem, 0);
2660 (void)err; // This may very well return an error.
2661 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Cortf801b982017-01-17 18:10:21 -08002663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2664 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2665 (void)err; // This may very well return an error.
2666 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002667
Cortf801b982017-01-17 18:10:21 -08002668 vkDestroyImage(m_device->device(), image, NULL);
2669 vkDestroyBuffer(m_device->device(), buffer, NULL);
2670 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002671
2672 // Try to bind memory to an object that already has a memory binding
2673 {
2674 VkImage image = VK_NULL_HANDLE;
2675 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2676 ASSERT_VK_SUCCESS(err);
2677 VkBuffer buffer = VK_NULL_HANDLE;
2678 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2679 ASSERT_VK_SUCCESS(err);
2680 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2681 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2682 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2683 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2684 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2685 image_alloc_info.allocationSize = image_mem_reqs.size;
2686 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2689 ASSERT_TRUE(pass);
2690 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2691 ASSERT_TRUE(pass);
2692 VkDeviceMemory image_mem, buffer_mem;
2693 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2694 ASSERT_VK_SUCCESS(err);
2695 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2696 ASSERT_VK_SUCCESS(err);
2697
2698 err = vkBindImageMemory(device(), image, image_mem, 0);
2699 ASSERT_VK_SUCCESS(err);
2700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
2704
2705 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2706 ASSERT_VK_SUCCESS(err);
2707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2708 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2709 (void)err; // This may very well return an error.
2710 m_errorMonitor->VerifyFound();
2711
2712 vkFreeMemory(device(), image_mem, NULL);
2713 vkFreeMemory(device(), buffer_mem, NULL);
2714 vkDestroyImage(device(), image, NULL);
2715 vkDestroyBuffer(device(), buffer, NULL);
2716 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002717
Cort Strattonde748202017-02-17 12:50:01 -08002718 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002719 {
2720 VkImage image = VK_NULL_HANDLE;
2721 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2722 ASSERT_VK_SUCCESS(err);
2723 VkBuffer buffer = VK_NULL_HANDLE;
2724 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2725 ASSERT_VK_SUCCESS(err);
2726 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2727 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2728 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2729 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2730 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Leave some extra space for alignment wiggle room
2732 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002733 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002734 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002735 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2736 ASSERT_TRUE(pass);
2737 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2738 ASSERT_TRUE(pass);
2739 VkDeviceMemory image_mem, buffer_mem;
2740 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2741 ASSERT_VK_SUCCESS(err);
2742 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2743 ASSERT_VK_SUCCESS(err);
2744
Cort Strattonde748202017-02-17 12:50:01 -08002745 // Test unaligned memory offset
2746 {
2747 if (image_mem_reqs.alignment > 1) {
2748 VkDeviceSize image_offset = 1;
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2750 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753 }
Cort6c7dff72017-01-27 18:34:50 -08002754
Cort Strattonde748202017-02-17 12:50:01 -08002755 if (buffer_mem_reqs.alignment > 1) {
2756 VkDeviceSize buffer_offset = 1;
2757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2758 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2759 (void)err; // This may very well return an error.
2760 m_errorMonitor->VerifyFound();
2761 }
2762 }
2763
2764 // Test memory offsets outside the memory allocation
2765 {
2766 VkDeviceSize image_offset =
2767 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2769 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2770 (void)err; // This may very well return an error.
2771 m_errorMonitor->VerifyFound();
2772
2773 VkDeviceSize buffer_offset =
2774 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2776 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2777 (void)err; // This may very well return an error.
2778 m_errorMonitor->VerifyFound();
2779 }
2780
2781 // Test memory offsets within the memory allocation, but which leave too little memory for
2782 // the resource.
2783 {
2784 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2785 if (image_offset > 0) {
2786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2787 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2788 (void)err; // This may very well return an error.
2789 m_errorMonitor->VerifyFound();
2790 }
2791
2792 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2793 if (buffer_offset > 0) {
2794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2795 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2796 (void)err; // This may very well return an error.
2797 m_errorMonitor->VerifyFound();
2798 }
2799 }
Cort6c7dff72017-01-27 18:34:50 -08002800
2801 vkFreeMemory(device(), image_mem, NULL);
2802 vkFreeMemory(device(), buffer_mem, NULL);
2803 vkDestroyImage(device(), image, NULL);
2804 vkDestroyBuffer(device(), buffer, NULL);
2805 }
2806
Cort Stratton4c38bb52017-01-28 13:33:10 -08002807 // Try to bind memory to an object with an invalid memory type
2808 {
2809 VkImage image = VK_NULL_HANDLE;
2810 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2811 ASSERT_VK_SUCCESS(err);
2812 VkBuffer buffer = VK_NULL_HANDLE;
2813 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2814 ASSERT_VK_SUCCESS(err);
2815 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2816 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2817 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2818 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2819 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2820 image_alloc_info.allocationSize = image_mem_reqs.size;
2821 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002823 // Create a mask of available memory types *not* supported by these resources,
2824 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002825 VkPhysicalDeviceMemoryProperties memory_properties = {};
2826 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002827 VkDeviceMemory image_mem, buffer_mem;
2828
Cort Stratton4c38bb52017-01-28 13:33:10 -08002829 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2836 err = vkBindImageMemory(device(), image, image_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
2841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 uint32_t buffer_unsupported_mem_type_bits =
2843 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002845 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2846 ASSERT_TRUE(pass);
2847 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2848 ASSERT_VK_SUCCESS(err);
2849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2850 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2851 (void)err; // This may very well return an error.
2852 m_errorMonitor->VerifyFound();
2853 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002854 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002855
Cort Stratton4c38bb52017-01-28 13:33:10 -08002856 vkDestroyImage(device(), image, NULL);
2857 vkDestroyBuffer(device(), buffer, NULL);
2858 }
2859
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 // Try to bind memory to an image created with sparse memory flags
2861 {
2862 VkImageCreateInfo sparse_image_create_info = image_create_info;
2863 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2864 VkImageFormatProperties image_format_properties = {};
2865 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2866 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2867 sparse_image_create_info.usage, sparse_image_create_info.flags,
2868 &image_format_properties);
2869 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2870 // most likely means sparse formats aren't supported here; skip this test.
2871 } else {
2872 ASSERT_VK_SUCCESS(err);
2873 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002874 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002875 return;
2876 } else {
2877 VkImage sparse_image = VK_NULL_HANDLE;
2878 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2879 ASSERT_VK_SUCCESS(err);
2880 VkMemoryRequirements sparse_mem_reqs = {};
2881 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2882 if (sparse_mem_reqs.memoryTypeBits != 0) {
2883 VkMemoryAllocateInfo sparse_mem_alloc = {};
2884 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2885 sparse_mem_alloc.pNext = NULL;
2886 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2887 sparse_mem_alloc.memoryTypeIndex = 0;
2888 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2889 ASSERT_TRUE(pass);
2890 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2891 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2892 ASSERT_VK_SUCCESS(err);
2893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2894 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2895 // This may very well return an error.
2896 (void)err;
2897 m_errorMonitor->VerifyFound();
2898 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2899 }
2900 vkDestroyImage(m_device->device(), sparse_image, NULL);
2901 }
2902 }
2903 }
2904
2905 // Try to bind memory to a buffer created with sparse memory flags
2906 {
2907 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2908 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2909 if (!m_device->phy().features().sparseResidencyBuffer) {
2910 // most likely means sparse formats aren't supported here; skip this test.
2911 } else {
2912 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2913 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2914 ASSERT_VK_SUCCESS(err);
2915 VkMemoryRequirements sparse_mem_reqs = {};
2916 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2917 if (sparse_mem_reqs.memoryTypeBits != 0) {
2918 VkMemoryAllocateInfo sparse_mem_alloc = {};
2919 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2920 sparse_mem_alloc.pNext = NULL;
2921 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2922 sparse_mem_alloc.memoryTypeIndex = 0;
2923 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2924 ASSERT_TRUE(pass);
2925 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2926 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2927 ASSERT_VK_SUCCESS(err);
2928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2929 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2930 // This may very well return an error.
2931 (void)err;
2932 m_errorMonitor->VerifyFound();
2933 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2934 }
2935 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2936 }
2937 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002938}
2939
Karl Schultz6addd812016-02-02 17:17:23 -07002940TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2941 VkResult err;
2942 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002945
Tobin Ehlisec598302015-09-15 15:02:17 -06002946 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
Karl Schultz6addd812016-02-02 17:17:23 -07002948 // Create an image object, allocate memory, destroy the object and then try
2949 // to bind it
2950 VkImage image;
2951 VkDeviceMemory mem;
2952 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002953
Karl Schultz6addd812016-02-02 17:17:23 -07002954 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2955 const int32_t tex_width = 32;
2956 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
2958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2960 image_create_info.pNext = NULL;
2961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2962 image_create_info.format = tex_format;
2963 image_create_info.extent.width = tex_width;
2964 image_create_info.extent.height = tex_height;
2965 image_create_info.extent.depth = 1;
2966 image_create_info.mipLevels = 1;
2967 image_create_info.arrayLayers = 1;
2968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2969 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2971 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002973 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002974 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2975 mem_alloc.pNext = NULL;
2976 mem_alloc.allocationSize = 0;
2977 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002978
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002983
2984 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002985 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002986 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002987
2988 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002990 ASSERT_VK_SUCCESS(err);
2991
2992 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002994 ASSERT_VK_SUCCESS(err);
2995
2996 // Now Try to bind memory to this destroyed object
2997 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2998 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002999 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003001 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003002
Chia-I Wuf7458c52015-10-26 21:10:41 +08003003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003004}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003005
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003006TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3007 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3008
3009 ASSERT_NO_FATAL_FAILURE(InitState());
3010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3011
3012 VkVertexInputBindingDescription input_binding;
3013 memset(&input_binding, 0, sizeof(input_binding));
3014
3015 VkVertexInputAttributeDescription input_attribs;
3016 memset(&input_attribs, 0, sizeof(input_attribs));
3017
3018 // Pick a really bad format for this purpose and make sure it should fail
3019 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3020 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3021 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003022 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003023 return;
3024 }
3025
3026 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003027 char const *vsSource =
3028 "#version 450\n"
3029 "\n"
3030 "out gl_PerVertex {\n"
3031 " vec4 gl_Position;\n"
3032 "};\n"
3033 "void main(){\n"
3034 " gl_Position = vec4(1);\n"
3035 "}\n";
3036 char const *fsSource =
3037 "#version 450\n"
3038 "\n"
3039 "layout(location=0) out vec4 color;\n"
3040 "void main(){\n"
3041 " color = vec4(1);\n"
3042 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003043
3044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3047
3048 VkPipelineObj pipe(m_device);
3049 pipe.AddColorAttachment();
3050 pipe.AddShader(&vs);
3051 pipe.AddShader(&fs);
3052
3053 pipe.AddVertexInputBindings(&input_binding, 1);
3054 pipe.AddVertexInputAttribs(&input_attribs, 1);
3055
3056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3059
3060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3061
3062 m_errorMonitor->VerifyFound();
3063}
3064
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003065TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003066 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3067 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003068
3069 VkMemoryPropertyFlags reqs = 0;
3070 VkImageCreateInfo image_create_info = {};
3071 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3072 image_create_info.pNext = NULL;
3073 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3074 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3075 image_create_info.extent.width = 256;
3076 image_create_info.extent.height = 256;
3077 image_create_info.extent.depth = 1;
3078 image_create_info.mipLevels = 1;
3079 image_create_info.arrayLayers = 1;
3080 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3081 image_create_info.flags = 0;
3082
3083 VkImageBlit blit_region = {};
3084 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3085 blit_region.srcSubresource.baseArrayLayer = 0;
3086 blit_region.srcSubresource.layerCount = 1;
3087 blit_region.srcSubresource.mipLevel = 0;
3088 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3089 blit_region.dstSubresource.baseArrayLayer = 0;
3090 blit_region.dstSubresource.layerCount = 1;
3091 blit_region.dstSubresource.mipLevel = 0;
3092
3093 // Create two images, the source with sampleCount = 2, and attempt to blit
3094 // between them
3095 {
3096 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003098 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003099 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003102 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003105 m_errorMonitor->SetDesiredFailureMsg(
3106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_errorMonitor->VerifyFound();
3111 m_commandBuffer->EndCommandBuffer();
3112 }
3113
3114 // Create two images, the dest with sampleCount = 4, and attempt to blit
3115 // between them
3116 {
3117 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003118 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003119 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003123 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003125 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003126 m_errorMonitor->SetDesiredFailureMsg(
3127 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3128 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3130 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003131 m_errorMonitor->VerifyFound();
3132 m_commandBuffer->EndCommandBuffer();
3133 }
3134
3135 VkBufferImageCopy copy_region = {};
3136 copy_region.bufferRowLength = 128;
3137 copy_region.bufferImageHeight = 128;
3138 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3139 copy_region.imageSubresource.layerCount = 1;
3140 copy_region.imageExtent.height = 64;
3141 copy_region.imageExtent.width = 64;
3142 copy_region.imageExtent.depth = 1;
3143
3144 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3145 // buffer to image
3146 {
3147 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003148 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3149 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003151 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003152 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003153 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003154 m_errorMonitor->SetDesiredFailureMsg(
3155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3156 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3158 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003159 m_errorMonitor->VerifyFound();
3160 m_commandBuffer->EndCommandBuffer();
3161 }
3162
3163 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3164 // image to buffer
3165 {
3166 vk_testing::Buffer dst_buffer;
3167 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3168 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003170 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003172 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003173 m_errorMonitor->SetDesiredFailureMsg(
3174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003177 dst_buffer.handle(), 1, &copy_region);
3178 m_errorMonitor->VerifyFound();
3179 m_commandBuffer->EndCommandBuffer();
3180 }
3181}
3182
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003183TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003184 ASSERT_NO_FATAL_FAILURE(InitState());
3185
3186 VkImageObj src_image(m_device);
3187 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3188 VkImageObj dst_image(m_device);
3189 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3190 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003191 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003192
3193 VkImageBlit blitRegion = {};
3194 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3195 blitRegion.srcSubresource.baseArrayLayer = 0;
3196 blitRegion.srcSubresource.layerCount = 1;
3197 blitRegion.srcSubresource.mipLevel = 0;
3198 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3199 blitRegion.dstSubresource.baseArrayLayer = 0;
3200 blitRegion.dstSubresource.layerCount = 1;
3201 blitRegion.dstSubresource.mipLevel = 0;
3202
Dave Houlton34df4cb2016-12-01 16:43:06 -07003203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3204
3205 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3206 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
3208 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003209 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 m_errorMonitor->VerifyFound();
3214
Dave Houlton34df4cb2016-12-01 16:43:06 -07003215 // Test should generate 2 VU failures
3216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218
3219 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003220 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3221 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003222
Dave Houlton34df4cb2016-12-01 16:43:06 -07003223 // TODO: Note that this only verifies that at least one of the VU enums was found
3224 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003225 m_errorMonitor->VerifyFound();
3226
Tony Barbour552f6c02016-12-21 14:34:07 -07003227 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228}
3229
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003230TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3231 VkResult err;
3232 bool pass;
3233
3234 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3235 ASSERT_NO_FATAL_FAILURE(InitState());
3236
3237 // If w/d/h granularity is 1, test is not meaningful
3238 // TODO: When virtual device limits are available, create a set of limits for this test that
3239 // will always have a granularity of > 1 for w, h, and d
3240 auto index = m_device->graphics_queue_node_index_;
3241 auto queue_family_properties = m_device->phy().queue_properties();
3242
3243 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3244 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3245 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3246 return;
3247 }
3248
3249 // Create two images of different types and try to copy between them
3250 VkImage srcImage;
3251 VkImage dstImage;
3252 VkDeviceMemory srcMem;
3253 VkDeviceMemory destMem;
3254 VkMemoryRequirements memReqs;
3255
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003256 VkImageCreateInfo image_create_info = {};
3257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3258 image_create_info.pNext = NULL;
3259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3260 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3261 image_create_info.extent.width = 32;
3262 image_create_info.extent.height = 32;
3263 image_create_info.extent.depth = 1;
3264 image_create_info.mipLevels = 1;
3265 image_create_info.arrayLayers = 4;
3266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3268 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3269 image_create_info.flags = 0;
3270
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_VK_SUCCESS(err);
3273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 // Allocate memory
3278 VkMemoryAllocateInfo memAlloc = {};
3279 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3280 memAlloc.pNext = NULL;
3281 memAlloc.allocationSize = 0;
3282 memAlloc.memoryTypeIndex = 0;
3283
3284 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3285 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003287 ASSERT_TRUE(pass);
3288 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3289 ASSERT_VK_SUCCESS(err);
3290
3291 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3292 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 ASSERT_VK_SUCCESS(err);
3295 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3296 ASSERT_VK_SUCCESS(err);
3297
3298 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3299 ASSERT_VK_SUCCESS(err);
3300 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3301 ASSERT_VK_SUCCESS(err);
3302
Tony Barbour552f6c02016-12-21 14:34:07 -07003303 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 VkImageCopy copyRegion;
3305 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3306 copyRegion.srcSubresource.mipLevel = 0;
3307 copyRegion.srcSubresource.baseArrayLayer = 0;
3308 copyRegion.srcSubresource.layerCount = 1;
3309 copyRegion.srcOffset.x = 0;
3310 copyRegion.srcOffset.y = 0;
3311 copyRegion.srcOffset.z = 0;
3312 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3313 copyRegion.dstSubresource.mipLevel = 0;
3314 copyRegion.dstSubresource.baseArrayLayer = 0;
3315 copyRegion.dstSubresource.layerCount = 1;
3316 copyRegion.dstOffset.x = 0;
3317 copyRegion.dstOffset.y = 0;
3318 copyRegion.dstOffset.z = 0;
3319 copyRegion.extent.width = 1;
3320 copyRegion.extent.height = 1;
3321 copyRegion.extent.depth = 1;
3322
3323 // Introduce failure by setting srcOffset to a bad granularity value
3324 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3326 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003327 m_errorMonitor->VerifyFound();
3328
3329 // Introduce failure by setting extent to a bad granularity value
3330 copyRegion.srcOffset.y = 0;
3331 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3333 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334 m_errorMonitor->VerifyFound();
3335
3336 // Now do some buffer/image copies
3337 vk_testing::Buffer buffer;
3338 VkMemoryPropertyFlags reqs = 0;
3339 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3340 VkBufferImageCopy region = {};
3341 region.bufferOffset = 0;
3342 region.bufferRowLength = 3;
3343 region.bufferImageHeight = 128;
3344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3345 region.imageSubresource.layerCount = 1;
3346 region.imageExtent.height = 16;
3347 region.imageExtent.width = 16;
3348 region.imageExtent.depth = 1;
3349 region.imageOffset.x = 0;
3350 region.imageOffset.y = 0;
3351 region.imageOffset.z = 0;
3352
3353 // Introduce failure by setting bufferRowLength to a bad granularity value
3354 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3356 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3357 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003358 m_errorMonitor->VerifyFound();
3359 region.bufferRowLength = 128;
3360
3361 // Introduce failure by setting bufferOffset to a bad granularity value
3362 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3365 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003366 m_errorMonitor->VerifyFound();
3367 region.bufferOffset = 0;
3368
3369 // Introduce failure by setting bufferImageHeight to a bad granularity value
3370 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferImageHeight = 128;
3376
3377 // Introduce failure by setting imageExtent to a bad granularity value
3378 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.imageExtent.width = 16;
3384
3385 // Introduce failure by setting imageOffset to a bad granularity value
3386 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391
Tony Barbour552f6c02016-12-21 14:34:07 -07003392 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003393
3394 vkDestroyImage(m_device->device(), srcImage, NULL);
3395 vkDestroyImage(m_device->device(), dstImage, NULL);
3396 vkFreeMemory(m_device->device(), srcMem, NULL);
3397 vkFreeMemory(m_device->device(), destMem, NULL);
3398}
3399
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003401 TEST_DESCRIPTION(
3402 "Submit command buffer created using one queue family and "
3403 "attempt to submit them on a queue created in a different "
3404 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003405
Cody Northropc31a84f2016-08-22 10:41:47 -06003406 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003407
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003408 // This test is meaningless unless we have multiple queue families
3409 auto queue_family_properties = m_device->phy().queue_properties();
3410 if (queue_family_properties.size() < 2) {
3411 return;
3412 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003414 // Get safe index of another queue family
3415 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3416 ASSERT_NO_FATAL_FAILURE(InitState());
3417 // Create a second queue using a different queue family
3418 VkQueue other_queue;
3419 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3420
3421 // Record an empty cmd buffer
3422 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3423 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3424 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3425 vkEndCommandBuffer(m_commandBuffer->handle());
3426
3427 // And submit on the wrong queue
3428 VkSubmitInfo submit_info = {};
3429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3430 submit_info.commandBufferCount = 1;
3431 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003432 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003433
3434 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003435}
3436
Chris Forbes4c24a922016-11-16 08:59:10 +13003437TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3438 ASSERT_NO_FATAL_FAILURE(InitState());
3439
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003440 // There are no attachments, but refer to attachment 0.
3441 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003442 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003443 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003444 };
3445
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003446 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003447 VkRenderPass rp;
3448
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003449 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003451 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3452 m_errorMonitor->VerifyFound();
3453}
3454
Chris Forbesa58c4522016-09-28 15:19:39 +13003455TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3456 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3457 ASSERT_NO_FATAL_FAILURE(InitState());
3458
3459 // A renderpass with two subpasses, both writing the same attachment.
3460 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3462 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003465 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003466 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003467 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3468 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003469 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003470 VkSubpassDependency dep = {0,
3471 1,
3472 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3473 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3474 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3475 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3476 VK_DEPENDENCY_BY_REGION_BIT};
3477 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 VkRenderPass rp;
3479 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3480 ASSERT_VK_SUCCESS(err);
3481
3482 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003484 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003487 VkFramebuffer fb;
3488 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3489 ASSERT_VK_SUCCESS(err);
3490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003491 char const *vsSource =
3492 "#version 450\n"
3493 "void main() { gl_Position = vec4(1); }\n";
3494 char const *fsSource =
3495 "#version 450\n"
3496 "layout(location=0) out vec4 color;\n"
3497 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3501 VkPipelineObj pipe(m_device);
3502 pipe.AddColorAttachment();
3503 pipe.AddShader(&vs);
3504 pipe.AddShader(&fs);
3505 VkViewport view_port = {};
3506 m_viewports.push_back(view_port);
3507 pipe.SetViewport(m_viewports);
3508 VkRect2D rect = {};
3509 m_scissors.push_back(rect);
3510 pipe.SetScissor(m_scissors);
3511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003512 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513 VkPipelineLayout pl;
3514 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3515 ASSERT_VK_SUCCESS(err);
3516 pipe.CreateVKPipeline(pl, rp);
3517
Tony Barbour552f6c02016-12-21 14:34:07 -07003518 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003519
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3521 nullptr,
3522 rp,
3523 fb,
3524 {{
3525 0, 0,
3526 },
3527 {32, 32}},
3528 0,
3529 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003530
3531 // subtest 1: bind in the wrong subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003535 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
3541 // subtest 2: bind in correct subpass, then transition to next subpass
3542 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3543 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3544 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003546 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3547 m_errorMonitor->VerifyFound();
3548
3549 vkCmdEndRenderPass(m_commandBuffer->handle());
3550
Tony Barbour552f6c02016-12-21 14:34:07 -07003551 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003552
3553 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3556}
3557
Tony Barbour4e919972016-08-09 13:27:40 -06003558TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003559 TEST_DESCRIPTION(
3560 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3561 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003562 ASSERT_NO_FATAL_FAILURE(InitState());
3563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3566 "Cannot execute a render pass with renderArea "
3567 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003568
3569 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3570 m_renderPassBeginInfo.renderArea.extent.width = 257;
3571 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003572 m_commandBuffer->BeginCommandBuffer();
3573 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003574 m_errorMonitor->VerifyFound();
3575}
3576
3577TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003578 TEST_DESCRIPTION(
3579 "Generate INDEPENDENT_BLEND by disabling independent "
3580 "blend and then specifying different blend states for two "
3581 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003582 VkPhysicalDeviceFeatures features = {};
3583 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Invalid Pipeline CreateInfo: If independent blend feature not "
3588 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003589
Cody Northropc31a84f2016-08-22 10:41:47 -06003590 VkDescriptorSetObj descriptorSet(m_device);
3591 descriptorSet.AppendDummy();
3592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003593
Cody Northropc31a84f2016-08-22 10:41:47 -06003594 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003595 // Create a renderPass with two color attachments
3596 VkAttachmentReference attachments[2] = {};
3597 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 VkSubpassDescription subpass = {};
3602 subpass.pColorAttachments = attachments;
3603 subpass.colorAttachmentCount = 2;
3604
3605 VkRenderPassCreateInfo rpci = {};
3606 rpci.subpassCount = 1;
3607 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003608 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 VkAttachmentDescription attach_desc[2] = {};
3611 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3612 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3613 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3614 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3615 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3616 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3617 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3618 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003619
Tony Barbourffd60bd2017-03-09 12:04:55 -07003620 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003621 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3622
3623 VkRenderPass renderpass;
3624 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003627
Cody Northropc31a84f2016-08-22 10:41:47 -06003628 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3629 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3630 att_state1.blendEnable = VK_TRUE;
3631 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3632 att_state2.blendEnable = VK_FALSE;
3633 pipeline.AddColorAttachment(0, &att_state1);
3634 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003636 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003637 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003638}
3639
Mike Weiblen40b160e2017-02-06 19:21:52 -07003640// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3641TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3642 TEST_DESCRIPTION(
3643 "Create a graphics pipeline that is incompatible with the requirements "
3644 "of its contained Renderpass/subpasses.");
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646
3647 VkDescriptorSetObj ds_obj(m_device);
3648 ds_obj.AppendDummy();
3649 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3650
3651 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3652
3653 VkPipelineColorBlendAttachmentState att_state1 = {};
3654 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3655 att_state1.blendEnable = VK_TRUE;
3656
3657 VkRenderpassObj rp_obj(m_device);
3658
3659 {
3660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3661 VkPipelineObj pipeline(m_device);
3662 pipeline.AddShader(&vs_obj);
3663 pipeline.AddColorAttachment(0, &att_state1);
3664
3665 VkGraphicsPipelineCreateInfo info = {};
3666 pipeline.InitGraphicsPipelineCreateInfo(&info);
3667 info.pColorBlendState = nullptr;
3668
3669 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3670 m_errorMonitor->VerifyFound();
3671 }
3672}
3673
Chris Forbes26ec2122016-11-29 08:58:33 +13003674#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003675TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3676 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3677 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003678 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3681 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003682
3683 // Create a renderPass with a single color attachment
3684 VkAttachmentReference attach = {};
3685 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3686 VkSubpassDescription subpass = {};
3687 VkRenderPassCreateInfo rpci = {};
3688 rpci.subpassCount = 1;
3689 rpci.pSubpasses = &subpass;
3690 rpci.attachmentCount = 1;
3691 VkAttachmentDescription attach_desc = {};
3692 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3693 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3694 rpci.pAttachments = &attach_desc;
3695 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3696 VkRenderPass rp;
3697 subpass.pDepthStencilAttachment = &attach;
3698 subpass.pColorAttachments = NULL;
3699 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3700 m_errorMonitor->VerifyFound();
3701}
Chris Forbes26ec2122016-11-29 08:58:33 +13003702#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003703
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003704TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003705 TEST_DESCRIPTION(
3706 "Create a framebuffer where a subpass has a preserve "
3707 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003708
3709 ASSERT_NO_FATAL_FAILURE(InitState());
3710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003713
3714 VkAttachmentReference color_attach = {};
3715 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3716 color_attach.attachment = 0;
3717 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3718 VkSubpassDescription subpass = {};
3719 subpass.colorAttachmentCount = 1;
3720 subpass.pColorAttachments = &color_attach;
3721 subpass.preserveAttachmentCount = 1;
3722 subpass.pPreserveAttachments = &preserve_attachment;
3723
3724 VkRenderPassCreateInfo rpci = {};
3725 rpci.subpassCount = 1;
3726 rpci.pSubpasses = &subpass;
3727 rpci.attachmentCount = 1;
3728 VkAttachmentDescription attach_desc = {};
3729 attach_desc.format = VK_FORMAT_UNDEFINED;
3730 rpci.pAttachments = &attach_desc;
3731 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3732 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003733 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003734
3735 m_errorMonitor->VerifyFound();
3736
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003737 if (result == VK_SUCCESS) {
3738 vkDestroyRenderPass(m_device->device(), rp, NULL);
3739 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003740}
3741
Chris Forbesc5389742016-06-29 11:49:23 +12003742TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003743 TEST_DESCRIPTION(
3744 "Ensure that CreateRenderPass produces a validation error "
3745 "when the source of a subpass multisample resolve "
3746 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003747
Chris Forbesc5389742016-06-29 11:49:23 +12003748 ASSERT_NO_FATAL_FAILURE(InitState());
3749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3751 "Subpass 0 requests multisample resolve from attachment 0 which has "
3752 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003753
3754 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3756 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3758 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3759 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003761 };
3762
3763 VkAttachmentReference color = {
3764 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3765 };
3766
3767 VkAttachmentReference resolve = {
3768 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3769 };
3770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003774
3775 VkRenderPass rp;
3776 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3777
3778 m_errorMonitor->VerifyFound();
3779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003780 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003781}
3782
3783TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003784 TEST_DESCRIPTION(
3785 "Ensure CreateRenderPass produces a validation error "
3786 "when a subpass multisample resolve operation is "
3787 "requested, and the destination of that resolve has "
3788 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003789
Chris Forbesc5389742016-06-29 11:49:23 +12003790 ASSERT_NO_FATAL_FAILURE(InitState());
3791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3793 "Subpass 0 requests multisample resolve into attachment 1, which "
3794 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003795
3796 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003797 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3798 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3800 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3801 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3802 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003803 };
3804
3805 VkAttachmentReference color = {
3806 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3807 };
3808
3809 VkAttachmentReference resolve = {
3810 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3811 };
3812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003813 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003816
3817 VkRenderPass rp;
3818 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3819
3820 m_errorMonitor->VerifyFound();
3821
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003822 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003823}
3824
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003826 TEST_DESCRIPTION(
3827 "Ensure CreateRenderPass produces a validation error "
3828 "when the color and depth attachments used by a subpass "
3829 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003830
Chris Forbes3f128ef2016-06-29 14:58:53 +12003831 ASSERT_NO_FATAL_FAILURE(InitState());
3832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3834 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003835
3836 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3838 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3839 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3840 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3841 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3842 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003843 };
3844
3845 VkAttachmentReference color[] = {
3846 {
3847 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3848 },
3849 {
3850 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3851 },
3852 };
3853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003857
3858 VkRenderPass rp;
3859 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3860
3861 m_errorMonitor->VerifyFound();
3862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003863 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003864}
3865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003867 TEST_DESCRIPTION(
3868 "Hit errors when attempting to create a framebuffer :\n"
3869 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3870 " 2. Use a color image as depthStencil attachment\n"
3871 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3872 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3873 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3874 " 6. Framebuffer attachment where dimensions don't match\n"
3875 " 7. Framebuffer attachment w/o identity swizzle\n"
3876 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3880
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003881 m_errorMonitor->SetDesiredFailureMsg(
3882 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3883 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003885 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003886 VkAttachmentReference attach = {};
3887 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3888 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003889 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003890 VkRenderPassCreateInfo rpci = {};
3891 rpci.subpassCount = 1;
3892 rpci.pSubpasses = &subpass;
3893 rpci.attachmentCount = 1;
3894 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003896 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003897 rpci.pAttachments = &attach_desc;
3898 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3899 VkRenderPass rp;
3900 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3901 ASSERT_VK_SUCCESS(err);
3902
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003903 VkImageView ivs[2];
3904 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3905 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003906 VkFramebufferCreateInfo fb_info = {};
3907 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3908 fb_info.pNext = NULL;
3909 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 // Set mis-matching attachmentCount
3911 fb_info.attachmentCount = 2;
3912 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003913 fb_info.width = 100;
3914 fb_info.height = 100;
3915 fb_info.layers = 1;
3916
3917 VkFramebuffer fb;
3918 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3919
3920 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003921 if (err == VK_SUCCESS) {
3922 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3923 }
3924 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003925
3926 // Create a renderPass with a depth-stencil attachment created with
3927 // IMAGE_USAGE_COLOR_ATTACHMENT
3928 // Add our color attachment to pDepthStencilAttachment
3929 subpass.pDepthStencilAttachment = &attach;
3930 subpass.pColorAttachments = NULL;
3931 VkRenderPass rp_ds;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3933 ASSERT_VK_SUCCESS(err);
3934 // Set correct attachment count, but attachment has COLOR usage bit set
3935 fb_info.attachmentCount = 1;
3936 fb_info.renderPass = rp_ds;
3937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003939 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3940
3941 m_errorMonitor->VerifyFound();
3942 if (err == VK_SUCCESS) {
3943 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3944 }
3945 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003946
3947 // Create new renderpass with alternate attachment format from fb
3948 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3949 subpass.pDepthStencilAttachment = NULL;
3950 subpass.pColorAttachments = &attach;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched formats between rp & fb
3955 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3956 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3958 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003959 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3960
3961 m_errorMonitor->VerifyFound();
3962 if (err == VK_SUCCESS) {
3963 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3964 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003965 vkDestroyRenderPass(m_device->device(), rp, NULL);
3966
3967 // Create new renderpass with alternate sample count from fb
3968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3969 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3970 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 // Cause error due to mis-matched sample count between rp & fb
3974 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003976 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003977 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3978
3979 m_errorMonitor->VerifyFound();
3980 if (err == VK_SUCCESS) {
3981 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3982 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003983
3984 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003985
3986 // Create a custom imageView with non-1 mip levels
3987 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003988 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003989 ASSERT_TRUE(image.initialized());
3990
3991 VkImageView view;
3992 VkImageViewCreateInfo ivci = {};
3993 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3994 ivci.image = image.handle();
3995 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3996 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3997 ivci.subresourceRange.layerCount = 1;
3998 ivci.subresourceRange.baseMipLevel = 0;
3999 // Set level count 2 (only 1 is allowed for FB attachment)
4000 ivci.subresourceRange.levelCount = 2;
4001 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4002 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4003 ASSERT_VK_SUCCESS(err);
4004 // Re-create renderpass to have matching sample count
4005 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4006 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4007 ASSERT_VK_SUCCESS(err);
4008
4009 fb_info.renderPass = rp;
4010 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004012 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4013
4014 m_errorMonitor->VerifyFound();
4015 if (err == VK_SUCCESS) {
4016 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4017 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004018 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004019 // Update view to original color buffer and grow FB dimensions too big
4020 fb_info.pAttachments = ivs;
4021 fb_info.height = 1024;
4022 fb_info.width = 1024;
4023 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004025 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4026
4027 m_errorMonitor->VerifyFound();
4028 if (err == VK_SUCCESS) {
4029 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4030 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004031 // Create view attachment with non-identity swizzle
4032 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4033 ivci.image = image.handle();
4034 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4035 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4036 ivci.subresourceRange.layerCount = 1;
4037 ivci.subresourceRange.baseMipLevel = 0;
4038 ivci.subresourceRange.levelCount = 1;
4039 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4040 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4041 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4042 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4043 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4044 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 fb_info.pAttachments = &view;
4048 fb_info.height = 100;
4049 fb_info.width = 100;
4050 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004051 m_errorMonitor->SetDesiredFailureMsg(
4052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4053 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4055
4056 m_errorMonitor->VerifyFound();
4057 if (err == VK_SUCCESS) {
4058 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4059 }
4060 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004061 // reset attachment to color attachment
4062 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063
4064 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004065 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004066 fb_info.height = 100;
4067 fb_info.layers = 1;
4068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004069 m_errorMonitor->SetDesiredFailureMsg(
4070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004071 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4072 "Here are the respective dimensions for attachment");
4073
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4075
4076 m_errorMonitor->VerifyFound();
4077 if (err == VK_SUCCESS) {
4078 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4079 }
4080
4081 // Request fb that exceeds max height
4082 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004083 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004084 fb_info.layers = 1;
4085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004086 m_errorMonitor->SetDesiredFailureMsg(
4087 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004088 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4089 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004090 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4091
4092 m_errorMonitor->VerifyFound();
4093 if (err == VK_SUCCESS) {
4094 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4095 }
4096
4097 // Request fb that exceeds max layers
4098 fb_info.width = 100;
4099 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004100 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004102 m_errorMonitor->SetDesiredFailureMsg(
4103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004104 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4105 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4107
4108 m_errorMonitor->VerifyFound();
4109 if (err == VK_SUCCESS) {
4110 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4111 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004112
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004113 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004114}
4115
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004116TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004117 TEST_DESCRIPTION(
4118 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4119 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120
Cody Northropc31a84f2016-08-22 10:41:47 -06004121 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004122 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4124 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125 m_errorMonitor->VerifyFound();
4126}
4127
4128TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004129 TEST_DESCRIPTION(
4130 "Run a simple draw calls to validate failure when Line Width dynamic "
4131 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004132
Cody Northropc31a84f2016-08-22 10:41:47 -06004133 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004134 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004137 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138}
4139
4140TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004141 TEST_DESCRIPTION(
4142 "Run a simple draw calls to validate failure when Viewport dynamic "
4143 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004144
Cody Northropc31a84f2016-08-22 10:41:47 -06004145 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004146 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4148 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004149 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004150 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004151}
4152
4153TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004154 TEST_DESCRIPTION(
4155 "Run a simple draw calls to validate failure when Scissor dynamic "
4156 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004157
Cody Northropc31a84f2016-08-22 10:41:47 -06004158 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004159 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4161 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004164}
4165
Cortd713fe82016-07-27 09:51:27 -07004166TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004167 TEST_DESCRIPTION(
4168 "Run a simple draw calls to validate failure when Blend Constants "
4169 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004170
4171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004172 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4174 "Dynamic blend constants state not set for this command buffer");
4175 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004176 m_errorMonitor->VerifyFound();
4177}
4178
4179TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004180 TEST_DESCRIPTION(
4181 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4182 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004183
4184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004185 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004186 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004187 return;
4188 }
4189 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4191 "Dynamic depth bounds state not set for this command buffer");
4192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004193 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004194}
4195
4196TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004197 TEST_DESCRIPTION(
4198 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4199 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004202 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4204 "Dynamic stencil read mask state not set for this command buffer");
4205 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004206 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004207}
4208
4209TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004210 TEST_DESCRIPTION(
4211 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4212 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004213
4214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004215 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Dynamic stencil write mask state not set for this command buffer");
4218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004220}
4221
4222TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004223 TEST_DESCRIPTION(
4224 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004226
4227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004228 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Dynamic stencil reference state not set for this command buffer");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004232 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004233}
4234
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004235TEST_F(VkLayerTest, IndexBufferNotBound) {
4236 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004237
4238 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4240 "Index buffer object not bound to this command buffer when Indexed ");
4241 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004242 m_errorMonitor->VerifyFound();
4243}
4244
Karl Schultz6addd812016-02-02 17:17:23 -07004245TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4247 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4248 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 ASSERT_NO_FATAL_FAILURE(InitState());
4251 ASSERT_NO_FATAL_FAILURE(InitViewport());
4252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4253
Karl Schultz6addd812016-02-02 17:17:23 -07004254 // We luck out b/c by default the framework creates CB w/ the
4255 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004256 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004258 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004259
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004260 // Bypass framework since it does the waits automatically
4261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004271 submit_info.pSignalSemaphores = NULL;
4272
Chris Forbes40028e22016-06-13 09:59:34 +12004273 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Karl Schultz6addd812016-02-02 17:17:23 -07004277 // Cause validation error by re-submitting cmd buffer that should only be
4278 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004279 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004280 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004282 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004283}
4284
Karl Schultz6addd812016-02-02 17:17:23 -07004285TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004287 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004288
4289 ASSERT_NO_FATAL_FAILURE(InitState());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004291
Karl Schultz6addd812016-02-02 17:17:23 -07004292 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4293 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004295 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004296 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004297
4298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4300 ds_pool_ci.pNext = NULL;
4301 ds_pool_ci.flags = 0;
4302 ds_pool_ci.maxSets = 1;
4303 ds_pool_ci.poolSizeCount = 1;
4304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004305
4306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004308 ASSERT_VK_SUCCESS(err);
4309
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004310 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4311 dsl_binding_samp.binding = 0;
4312 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4313 dsl_binding_samp.descriptorCount = 1;
4314 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4315 dsl_binding_samp.pImmutableSamplers = NULL;
4316
4317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4319 ds_layout_ci.pNext = NULL;
4320 ds_layout_ci.bindingCount = 1;
4321 ds_layout_ci.pBindings = &dsl_binding_samp;
4322
4323 VkDescriptorSetLayout ds_layout_samp;
4324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4325 ASSERT_VK_SUCCESS(err);
4326
4327 // Try to allocate 2 sets when pool only has 1 set
4328 VkDescriptorSet descriptor_sets[2];
4329 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4330 VkDescriptorSetAllocateInfo alloc_info = {};
4331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4332 alloc_info.descriptorSetCount = 2;
4333 alloc_info.descriptorPool = ds_pool;
4334 alloc_info.pSetLayouts = set_layouts;
4335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4337 m_errorMonitor->VerifyFound();
4338
4339 alloc_info.descriptorSetCount = 1;
4340 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004342 dsl_binding.binding = 0;
4343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4344 dsl_binding.descriptorCount = 1;
4345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4346 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347
Karl Schultz6addd812016-02-02 17:17:23 -07004348 ds_layout_ci.bindingCount = 1;
4349 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004351 VkDescriptorSetLayout ds_layout_ub;
4352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004353 ASSERT_VK_SUCCESS(err);
4354
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004355 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004356 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004357 alloc_info.pSetLayouts = &ds_layout_ub;
4358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004362
Karl Schultz2825ab92016-12-02 08:23:14 -07004363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004366}
4367
Karl Schultz6addd812016-02-02 17:17:23 -07004368TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4369 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004372
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_NO_FATAL_FAILURE(InitState());
4374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004375
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4382 ds_pool_ci.pNext = NULL;
4383 ds_pool_ci.maxSets = 1;
4384 ds_pool_ci.poolSizeCount = 1;
4385 ds_pool_ci.flags = 0;
4386 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4387 // app can only call vkResetDescriptorPool on this pool.;
4388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004389
4390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004392 ASSERT_VK_SUCCESS(err);
4393
4394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004395 dsl_binding.binding = 0;
4396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4397 dsl_binding.descriptorCount = 1;
4398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004400
4401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4403 ds_layout_ci.pNext = NULL;
4404 ds_layout_ci.bindingCount = 1;
4405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004406
4407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004409 ASSERT_VK_SUCCESS(err);
4410
4411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004415 alloc_info.descriptorPool = ds_pool;
4416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004418 ASSERT_VK_SUCCESS(err);
4419
4420 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004421 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Chia-I Wuf7458c52015-10-26 21:10:41 +08004423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004425}
4426
Karl Schultz6addd812016-02-02 17:17:23 -07004427TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 // Attempt to clear Descriptor Pool with bad object.
4429 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004433 uint64_t fake_pool_handle = 0xbaad6001;
4434 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4435 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004436 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437}
4438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004439TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004440 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4441 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004442 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004443 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004444
4445 uint64_t fake_set_handle = 0xbaad6001;
4446 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004447 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004449
4450 ASSERT_NO_FATAL_FAILURE(InitState());
4451
4452 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4453 layout_bindings[0].binding = 0;
4454 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4455 layout_bindings[0].descriptorCount = 1;
4456 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4457 layout_bindings[0].pImmutableSamplers = NULL;
4458
4459 VkDescriptorSetLayout descriptor_set_layout;
4460 VkDescriptorSetLayoutCreateInfo dslci = {};
4461 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4462 dslci.pNext = NULL;
4463 dslci.bindingCount = 1;
4464 dslci.pBindings = layout_bindings;
4465 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004466 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004467
4468 VkPipelineLayout pipeline_layout;
4469 VkPipelineLayoutCreateInfo plci = {};
4470 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4471 plci.pNext = NULL;
4472 plci.setLayoutCount = 1;
4473 plci.pSetLayouts = &descriptor_set_layout;
4474 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004475 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004476
Tony Barbour552f6c02016-12-21 14:34:07 -07004477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4479 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004481 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4483 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004484}
4485
Karl Schultz6addd812016-02-02 17:17:23 -07004486TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004487 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4488 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004489 uint64_t fake_layout_handle = 0xbaad6001;
4490 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004492 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004493 VkPipelineLayout pipeline_layout;
4494 VkPipelineLayoutCreateInfo plci = {};
4495 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4496 plci.pNext = NULL;
4497 plci.setLayoutCount = 1;
4498 plci.pSetLayouts = &bad_layout;
4499 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4500
4501 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004502}
4503
Mark Muellerd4914412016-06-13 17:52:06 -06004504TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004505 TEST_DESCRIPTION(
4506 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4507 "1) A uniform buffer update must have a valid buffer index."
4508 "2) When using an array of descriptors in a single WriteDescriptor,"
4509 " the descriptor types and stageflags must all be the same."
4510 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004511
Mike Weiblena6666382017-01-05 15:16:11 -07004512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004513
4514 ASSERT_NO_FATAL_FAILURE(InitState());
4515 VkDescriptorPoolSize ds_type_count[4] = {};
4516 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4517 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004518 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004519 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004520 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004521 ds_type_count[2].descriptorCount = 1;
4522 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4523 ds_type_count[3].descriptorCount = 1;
4524
4525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4527 ds_pool_ci.maxSets = 1;
4528 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4529 ds_pool_ci.pPoolSizes = ds_type_count;
4530
4531 VkDescriptorPool ds_pool;
4532 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4533 ASSERT_VK_SUCCESS(err);
4534
Mark Muellerb9896722016-06-16 09:54:29 -06004535 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004536 layout_binding[0].binding = 0;
4537 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4538 layout_binding[0].descriptorCount = 1;
4539 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4540 layout_binding[0].pImmutableSamplers = NULL;
4541
4542 layout_binding[1].binding = 1;
4543 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4544 layout_binding[1].descriptorCount = 1;
4545 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4546 layout_binding[1].pImmutableSamplers = NULL;
4547
4548 VkSamplerCreateInfo sampler_ci = {};
4549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4550 sampler_ci.pNext = NULL;
4551 sampler_ci.magFilter = VK_FILTER_NEAREST;
4552 sampler_ci.minFilter = VK_FILTER_NEAREST;
4553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4557 sampler_ci.mipLodBias = 1.0;
4558 sampler_ci.anisotropyEnable = VK_FALSE;
4559 sampler_ci.maxAnisotropy = 1;
4560 sampler_ci.compareEnable = VK_FALSE;
4561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4562 sampler_ci.minLod = 1.0;
4563 sampler_ci.maxLod = 1.0;
4564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4566 VkSampler sampler;
4567
4568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4569 ASSERT_VK_SUCCESS(err);
4570
4571 layout_binding[2].binding = 2;
4572 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4573 layout_binding[2].descriptorCount = 1;
4574 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4575 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4576
Mark Muellerd4914412016-06-13 17:52:06 -06004577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4579 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4580 ds_layout_ci.pBindings = layout_binding;
4581 VkDescriptorSetLayout ds_layout;
4582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
4585 VkDescriptorSetAllocateInfo alloc_info = {};
4586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4587 alloc_info.descriptorSetCount = 1;
4588 alloc_info.descriptorPool = ds_pool;
4589 alloc_info.pSetLayouts = &ds_layout;
4590 VkDescriptorSet descriptorSet;
4591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4592 ASSERT_VK_SUCCESS(err);
4593
4594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4596 pipeline_layout_ci.pNext = NULL;
4597 pipeline_layout_ci.setLayoutCount = 1;
4598 pipeline_layout_ci.pSetLayouts = &ds_layout;
4599
4600 VkPipelineLayout pipeline_layout;
4601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4602 ASSERT_VK_SUCCESS(err);
4603
Mark Mueller5c838ce2016-06-16 09:54:29 -06004604 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4606 descriptor_write.dstSet = descriptorSet;
4607 descriptor_write.dstBinding = 0;
4608 descriptor_write.descriptorCount = 1;
4609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4610
Mark Mueller5c838ce2016-06-16 09:54:29 -06004611 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4613 m_errorMonitor->VerifyFound();
4614
4615 // Create a buffer to update the descriptor with
4616 uint32_t qfi = 0;
4617 VkBufferCreateInfo buffCI = {};
4618 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4619 buffCI.size = 1024;
4620 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4621 buffCI.queueFamilyIndexCount = 1;
4622 buffCI.pQueueFamilyIndices = &qfi;
4623
4624 VkBuffer dyub;
4625 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4626 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004627
Tony Barboure132c5f2016-12-12 11:50:20 -07004628 VkDeviceMemory mem;
4629 VkMemoryRequirements mem_reqs;
4630 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4631
4632 VkMemoryAllocateInfo mem_alloc_info = {};
4633 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4634 mem_alloc_info.allocationSize = mem_reqs.size;
4635 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4636 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4637 ASSERT_VK_SUCCESS(err);
4638
4639 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4640 ASSERT_VK_SUCCESS(err);
4641
4642 VkDescriptorBufferInfo buffInfo[2] = {};
4643 buffInfo[0].buffer = dyub;
4644 buffInfo[0].offset = 0;
4645 buffInfo[0].range = 1024;
4646 buffInfo[1].buffer = dyub;
4647 buffInfo[1].offset = 0;
4648 buffInfo[1].range = 1024;
4649 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004650 descriptor_write.descriptorCount = 2;
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4655 m_errorMonitor->VerifyFound();
4656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4658 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004659 descriptor_write.dstBinding = 1;
4660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004661
Mark Mueller5c838ce2016-06-16 09:54:29 -06004662 // Make pImageInfo index non-null to avoid complaints of it missing
4663 VkDescriptorImageInfo imageInfo = {};
4664 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4665 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4668 m_errorMonitor->VerifyFound();
4669
Mark Muellerd4914412016-06-13 17:52:06 -06004670 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004671 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004672 vkDestroySampler(m_device->device(), sampler, NULL);
4673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4676}
4677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004679 TEST_DESCRIPTION(
4680 "Attempt to draw with a command buffer that is invalid "
4681 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004682 ASSERT_NO_FATAL_FAILURE(InitState());
4683
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004684 VkBuffer buffer;
4685 VkDeviceMemory mem;
4686 VkMemoryRequirements mem_reqs;
4687
4688 VkBufferCreateInfo buf_info = {};
4689 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004690 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004691 buf_info.size = 256;
4692 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4693 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4694 ASSERT_VK_SUCCESS(err);
4695
4696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4697
4698 VkMemoryAllocateInfo alloc_info = {};
4699 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4700 alloc_info.allocationSize = 256;
4701 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004702 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004703 if (!pass) {
4704 vkDestroyBuffer(m_device->device(), buffer, NULL);
4705 return;
4706 }
4707 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4708 ASSERT_VK_SUCCESS(err);
4709
4710 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4711 ASSERT_VK_SUCCESS(err);
4712
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004714 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004715 m_commandBuffer->EndCommandBuffer();
4716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004718 // Destroy buffer dependency prior to submit to cause ERROR
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720
4721 VkSubmitInfo submit_info = {};
4722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4723 submit_info.commandBufferCount = 1;
4724 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4726
4727 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004728 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004729 vkFreeMemory(m_device->handle(), mem, NULL);
4730}
4731
Tobin Ehlisea413442016-09-28 10:23:59 -06004732TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4733 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4734
4735 ASSERT_NO_FATAL_FAILURE(InitState());
4736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4737
4738 VkDescriptorPoolSize ds_type_count;
4739 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4740 ds_type_count.descriptorCount = 1;
4741
4742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4744 ds_pool_ci.maxSets = 1;
4745 ds_pool_ci.poolSizeCount = 1;
4746 ds_pool_ci.pPoolSizes = &ds_type_count;
4747
4748 VkDescriptorPool ds_pool;
4749 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4750 ASSERT_VK_SUCCESS(err);
4751
4752 VkDescriptorSetLayoutBinding layout_binding;
4753 layout_binding.binding = 0;
4754 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4755 layout_binding.descriptorCount = 1;
4756 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4757 layout_binding.pImmutableSamplers = NULL;
4758
4759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4761 ds_layout_ci.bindingCount = 1;
4762 ds_layout_ci.pBindings = &layout_binding;
4763 VkDescriptorSetLayout ds_layout;
4764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkDescriptorSetAllocateInfo alloc_info = {};
4768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4769 alloc_info.descriptorSetCount = 1;
4770 alloc_info.descriptorPool = ds_pool;
4771 alloc_info.pSetLayouts = &ds_layout;
4772 VkDescriptorSet descriptor_set;
4773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4778 pipeline_layout_ci.pNext = NULL;
4779 pipeline_layout_ci.setLayoutCount = 1;
4780 pipeline_layout_ci.pSetLayouts = &ds_layout;
4781
4782 VkPipelineLayout pipeline_layout;
4783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 VkBuffer buffer;
4787 uint32_t queue_family_index = 0;
4788 VkBufferCreateInfo buffer_create_info = {};
4789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4790 buffer_create_info.size = 1024;
4791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4792 buffer_create_info.queueFamilyIndexCount = 1;
4793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4794
4795 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4796 ASSERT_VK_SUCCESS(err);
4797
4798 VkMemoryRequirements memory_reqs;
4799 VkDeviceMemory buffer_memory;
4800
4801 VkMemoryAllocateInfo memory_info = {};
4802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4803 memory_info.allocationSize = 0;
4804 memory_info.memoryTypeIndex = 0;
4805
4806 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4807 memory_info.allocationSize = memory_reqs.size;
4808 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4809 ASSERT_TRUE(pass);
4810
4811 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4812 ASSERT_VK_SUCCESS(err);
4813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkBufferView view;
4817 VkBufferViewCreateInfo bvci = {};
4818 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4819 bvci.buffer = buffer;
4820 bvci.format = VK_FORMAT_R8_UNORM;
4821 bvci.range = VK_WHOLE_SIZE;
4822
4823 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4824 ASSERT_VK_SUCCESS(err);
4825
4826 VkWriteDescriptorSet descriptor_write = {};
4827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4828 descriptor_write.dstSet = descriptor_set;
4829 descriptor_write.dstBinding = 0;
4830 descriptor_write.descriptorCount = 1;
4831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4832 descriptor_write.pTexelBufferView = &view;
4833
4834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004836 char const *vsSource =
4837 "#version 450\n"
4838 "\n"
4839 "out gl_PerVertex { \n"
4840 " vec4 gl_Position;\n"
4841 "};\n"
4842 "void main(){\n"
4843 " gl_Position = vec4(1);\n"
4844 "}\n";
4845 char const *fsSource =
4846 "#version 450\n"
4847 "\n"
4848 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4849 "layout(location=0) out vec4 x;\n"
4850 "void main(){\n"
4851 " x = imageLoad(s, 0);\n"
4852 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4855 VkPipelineObj pipe(m_device);
4856 pipe.AddShader(&vs);
4857 pipe.AddShader(&fs);
4858 pipe.AddColorAttachment();
4859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4862
Tony Barbour552f6c02016-12-21 14:34:07 -07004863 m_commandBuffer->BeginCommandBuffer();
4864 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4865
Tobin Ehlisea413442016-09-28 10:23:59 -06004866 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4867 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4868 VkRect2D scissor = {{0, 0}, {16, 16}};
4869 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4870 // Bind pipeline to cmd buffer
4871 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4872 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4873 &descriptor_set, 0, nullptr);
4874 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004875 m_commandBuffer->EndRenderPass();
4876 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004877
4878 // Delete BufferView in order to invalidate cmd buffer
4879 vkDestroyBufferView(m_device->device(), view, NULL);
4880 // Now attempt submit of cmd buffer
4881 VkSubmitInfo submit_info = {};
4882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4883 submit_info.commandBufferCount = 1;
4884 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4885 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4886 m_errorMonitor->VerifyFound();
4887
4888 // Clean-up
4889 vkDestroyBuffer(m_device->device(), buffer, NULL);
4890 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4894}
4895
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004897 TEST_DESCRIPTION(
4898 "Attempt to draw with a command buffer that is invalid "
4899 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_NO_FATAL_FAILURE(InitState());
4901
4902 VkImage image;
4903 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4904 VkImageCreateInfo image_create_info = {};
4905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4906 image_create_info.pNext = NULL;
4907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4908 image_create_info.format = tex_format;
4909 image_create_info.extent.width = 32;
4910 image_create_info.extent.height = 32;
4911 image_create_info.extent.depth = 1;
4912 image_create_info.mipLevels = 1;
4913 image_create_info.arrayLayers = 1;
4914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004919 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004920 // Have to bind memory to image before recording cmd in cmd buffer using it
4921 VkMemoryRequirements mem_reqs;
4922 VkDeviceMemory image_mem;
4923 bool pass;
4924 VkMemoryAllocateInfo mem_alloc = {};
4925 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4926 mem_alloc.pNext = NULL;
4927 mem_alloc.memoryTypeIndex = 0;
4928 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4929 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004931 ASSERT_TRUE(pass);
4932 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4935 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004936
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004937 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004938 VkClearColorValue ccv;
4939 ccv.float32[0] = 1.0f;
4940 ccv.float32[1] = 1.0f;
4941 ccv.float32[2] = 1.0f;
4942 ccv.float32[3] = 1.0f;
4943 VkImageSubresourceRange isr = {};
4944 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004945 isr.baseArrayLayer = 0;
4946 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004947 isr.layerCount = 1;
4948 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004950 m_commandBuffer->EndCommandBuffer();
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953 // Destroy image dependency prior to submit to cause ERROR
4954 vkDestroyImage(m_device->device(), image, NULL);
4955
4956 VkSubmitInfo submit_info = {};
4957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4958 submit_info.commandBufferCount = 1;
4959 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4961
4962 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004963 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004964}
4965
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004967 TEST_DESCRIPTION(
4968 "Attempt to draw with a command buffer that is invalid "
4969 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 VkFormatProperties format_properties;
4971 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004972 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4973 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 return;
4975 }
4976
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkImageCreateInfo image_ci = {};
4981 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4982 image_ci.pNext = NULL;
4983 image_ci.imageType = VK_IMAGE_TYPE_2D;
4984 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4985 image_ci.extent.width = 32;
4986 image_ci.extent.height = 32;
4987 image_ci.extent.depth = 1;
4988 image_ci.mipLevels = 1;
4989 image_ci.arrayLayers = 1;
4990 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4991 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004993 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4994 image_ci.flags = 0;
4995 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004997
4998 VkMemoryRequirements memory_reqs;
4999 VkDeviceMemory image_memory;
5000 bool pass;
5001 VkMemoryAllocateInfo memory_info = {};
5002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 memory_info.pNext = NULL;
5004 memory_info.allocationSize = 0;
5005 memory_info.memoryTypeIndex = 0;
5006 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5007 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005009 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 ASSERT_VK_SUCCESS(err);
5012 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 VkImageViewCreateInfo ivci = {
5016 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5017 nullptr,
5018 0,
5019 image,
5020 VK_IMAGE_VIEW_TYPE_2D,
5021 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5024 };
5025 VkImageView view;
5026 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5027 ASSERT_VK_SUCCESS(err);
5028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 VkFramebuffer fb;
5031 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5032 ASSERT_VK_SUCCESS(err);
5033
5034 // Just use default renderpass with our framebuffer
5035 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005036 m_renderPassBeginInfo.renderArea.extent.width = 32;
5037 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005039 m_commandBuffer->BeginCommandBuffer();
5040 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5041 m_commandBuffer->EndRenderPass();
5042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005043 // Destroy image attached to framebuffer to invalidate cmd buffer
5044 vkDestroyImage(m_device->device(), image, NULL);
5045 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005047 QueueCommandBuffer(false);
5048 m_errorMonitor->VerifyFound();
5049
5050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5051 vkDestroyImageView(m_device->device(), view, nullptr);
5052 vkFreeMemory(m_device->device(), image_memory, nullptr);
5053}
5054
Tobin Ehlisb329f992016-10-12 13:20:29 -06005055TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5056 TEST_DESCRIPTION("Delete in-use framebuffer.");
5057 VkFormatProperties format_properties;
5058 VkResult err = VK_SUCCESS;
5059 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5060
5061 ASSERT_NO_FATAL_FAILURE(InitState());
5062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5063
5064 VkImageObj image(m_device);
5065 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5066 ASSERT_TRUE(image.initialized());
5067 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5068
5069 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5070 VkFramebuffer fb;
5071 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5072 ASSERT_VK_SUCCESS(err);
5073
5074 // Just use default renderpass with our framebuffer
5075 m_renderPassBeginInfo.framebuffer = fb;
5076 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005077 m_commandBuffer->BeginCommandBuffer();
5078 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5079 m_commandBuffer->EndRenderPass();
5080 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005081 // Submit cmd buffer to put it in-flight
5082 VkSubmitInfo submit_info = {};
5083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5084 submit_info.commandBufferCount = 1;
5085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5086 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5087 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005089 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5090 m_errorMonitor->VerifyFound();
5091 // Wait for queue to complete so we can safely destroy everything
5092 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005093 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5094 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005095 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5096}
5097
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5099 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5100 VkFormatProperties format_properties;
5101 VkResult err = VK_SUCCESS;
5102 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103
5104 ASSERT_NO_FATAL_FAILURE(InitState());
5105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5106
5107 VkImageCreateInfo image_ci = {};
5108 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5109 image_ci.pNext = NULL;
5110 image_ci.imageType = VK_IMAGE_TYPE_2D;
5111 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5112 image_ci.extent.width = 256;
5113 image_ci.extent.height = 256;
5114 image_ci.extent.depth = 1;
5115 image_ci.mipLevels = 1;
5116 image_ci.arrayLayers = 1;
5117 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5118 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005119 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005120 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5121 image_ci.flags = 0;
5122 VkImage image;
5123 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5124
5125 VkMemoryRequirements memory_reqs;
5126 VkDeviceMemory image_memory;
5127 bool pass;
5128 VkMemoryAllocateInfo memory_info = {};
5129 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5130 memory_info.pNext = NULL;
5131 memory_info.allocationSize = 0;
5132 memory_info.memoryTypeIndex = 0;
5133 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5134 memory_info.allocationSize = memory_reqs.size;
5135 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5136 ASSERT_TRUE(pass);
5137 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5138 ASSERT_VK_SUCCESS(err);
5139 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5140 ASSERT_VK_SUCCESS(err);
5141
5142 VkImageViewCreateInfo ivci = {
5143 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5144 nullptr,
5145 0,
5146 image,
5147 VK_IMAGE_VIEW_TYPE_2D,
5148 VK_FORMAT_B8G8R8A8_UNORM,
5149 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5150 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5151 };
5152 VkImageView view;
5153 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5157 VkFramebuffer fb;
5158 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5159 ASSERT_VK_SUCCESS(err);
5160
5161 // Just use default renderpass with our framebuffer
5162 m_renderPassBeginInfo.framebuffer = fb;
5163 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005164 m_commandBuffer->BeginCommandBuffer();
5165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5166 m_commandBuffer->EndRenderPass();
5167 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005168 // Submit cmd buffer to put it (and attached imageView) in-flight
5169 VkSubmitInfo submit_info = {};
5170 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5171 submit_info.commandBufferCount = 1;
5172 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5173 // Submit cmd buffer to put framebuffer and children in-flight
5174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5175 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005177 vkDestroyImage(m_device->device(), image, NULL);
5178 m_errorMonitor->VerifyFound();
5179 // Wait for queue to complete so we can safely destroy image and other objects
5180 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005181 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5182 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005183 vkDestroyImage(m_device->device(), image, NULL);
5184 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5185 vkDestroyImageView(m_device->device(), view, nullptr);
5186 vkFreeMemory(m_device->device(), image_memory, nullptr);
5187}
5188
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005189TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5190 TEST_DESCRIPTION("Delete in-use renderPass.");
5191
5192 ASSERT_NO_FATAL_FAILURE(InitState());
5193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5194
5195 // Create simple renderpass
5196 VkAttachmentReference attach = {};
5197 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5198 VkSubpassDescription subpass = {};
5199 subpass.pColorAttachments = &attach;
5200 VkRenderPassCreateInfo rpci = {};
5201 rpci.subpassCount = 1;
5202 rpci.pSubpasses = &subpass;
5203 rpci.attachmentCount = 1;
5204 VkAttachmentDescription attach_desc = {};
5205 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5206 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5207 rpci.pAttachments = &attach_desc;
5208 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5209 VkRenderPass rp;
5210 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Create a pipeline that uses the given renderpass
5214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5216
5217 VkPipelineLayout pipeline_layout;
5218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5219 ASSERT_VK_SUCCESS(err);
5220
5221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005224 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005225 vp_state_ci.pViewports = &vp;
5226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005227 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005228 vp_state_ci.pScissors = &scissors;
5229
5230 VkPipelineShaderStageCreateInfo shaderStages[2];
5231 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5232
5233 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005234 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005235 // but add it to be able to run on more devices
5236 shaderStages[0] = vs.GetStageCreateInfo();
5237 shaderStages[1] = fs.GetStageCreateInfo();
5238
5239 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5240 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5241
5242 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5243 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5244 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5245
5246 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5247 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5248 rs_ci.rasterizerDiscardEnable = true;
5249 rs_ci.lineWidth = 1.0f;
5250
5251 VkPipelineColorBlendAttachmentState att = {};
5252 att.blendEnable = VK_FALSE;
5253 att.colorWriteMask = 0xf;
5254
5255 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5256 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5257 cb_ci.attachmentCount = 1;
5258 cb_ci.pAttachments = &att;
5259
5260 VkGraphicsPipelineCreateInfo gp_ci = {};
5261 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5262 gp_ci.stageCount = 2;
5263 gp_ci.pStages = shaderStages;
5264 gp_ci.pVertexInputState = &vi_ci;
5265 gp_ci.pInputAssemblyState = &ia_ci;
5266 gp_ci.pViewportState = &vp_state_ci;
5267 gp_ci.pRasterizationState = &rs_ci;
5268 gp_ci.pColorBlendState = &cb_ci;
5269 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5270 gp_ci.layout = pipeline_layout;
5271 gp_ci.renderPass = rp;
5272
5273 VkPipelineCacheCreateInfo pc_ci = {};
5274 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5275
5276 VkPipeline pipeline;
5277 VkPipelineCache pipe_cache;
5278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5279 ASSERT_VK_SUCCESS(err);
5280
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005281 m_errorMonitor->SetUnexpectedError(
5282 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5283 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005284 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5285 ASSERT_VK_SUCCESS(err);
5286 // Bind pipeline to cmd buffer, will also bind renderpass
5287 m_commandBuffer->BeginCommandBuffer();
5288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5289 m_commandBuffer->EndCommandBuffer();
5290
5291 VkSubmitInfo submit_info = {};
5292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5293 submit_info.commandBufferCount = 1;
5294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5295 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5296
5297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5298 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5299 m_errorMonitor->VerifyFound();
5300
5301 // Wait for queue to complete so we can safely destroy everything
5302 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005303 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5304 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005305 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5306 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5307 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5309}
5310
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005311TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 ASSERT_NO_FATAL_FAILURE(InitState());
5314
5315 VkImage image;
5316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5317 VkImageCreateInfo image_create_info = {};
5318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5319 image_create_info.pNext = NULL;
5320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5321 image_create_info.format = tex_format;
5322 image_create_info.extent.width = 32;
5323 image_create_info.extent.height = 32;
5324 image_create_info.extent.depth = 1;
5325 image_create_info.mipLevels = 1;
5326 image_create_info.arrayLayers = 1;
5327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005329 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005330 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005332 ASSERT_VK_SUCCESS(err);
5333 // Have to bind memory to image before recording cmd in cmd buffer using it
5334 VkMemoryRequirements mem_reqs;
5335 VkDeviceMemory image_mem;
5336 bool pass;
5337 VkMemoryAllocateInfo mem_alloc = {};
5338 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5339 mem_alloc.pNext = NULL;
5340 mem_alloc.memoryTypeIndex = 0;
5341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005344 ASSERT_TRUE(pass);
5345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5346 ASSERT_VK_SUCCESS(err);
5347
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005348 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005350 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005351
5352 m_commandBuffer->BeginCommandBuffer();
5353 VkClearColorValue ccv;
5354 ccv.float32[0] = 1.0f;
5355 ccv.float32[1] = 1.0f;
5356 ccv.float32[2] = 1.0f;
5357 ccv.float32[3] = 1.0f;
5358 VkImageSubresourceRange isr = {};
5359 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5360 isr.baseArrayLayer = 0;
5361 isr.baseMipLevel = 0;
5362 isr.layerCount = 1;
5363 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005364 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005365 m_commandBuffer->EndCommandBuffer();
5366
5367 m_errorMonitor->VerifyFound();
5368 vkDestroyImage(m_device->device(), image, NULL);
5369 vkFreeMemory(m_device->device(), image_mem, nullptr);
5370}
5371
5372TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005374 ASSERT_NO_FATAL_FAILURE(InitState());
5375
5376 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 VK_IMAGE_TILING_OPTIMAL, 0);
5379 ASSERT_TRUE(image.initialized());
5380
5381 VkBuffer buffer;
5382 VkDeviceMemory mem;
5383 VkMemoryRequirements mem_reqs;
5384
5385 VkBufferCreateInfo buf_info = {};
5386 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005387 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005388 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005389 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5390 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5391 ASSERT_VK_SUCCESS(err);
5392
5393 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5394
5395 VkMemoryAllocateInfo alloc_info = {};
5396 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005397 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005398 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005400 if (!pass) {
5401 vkDestroyBuffer(m_device->device(), buffer, NULL);
5402 return;
5403 }
5404 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5405 ASSERT_VK_SUCCESS(err);
5406
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005407 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005409 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005410 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005411 region.bufferRowLength = 16;
5412 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005413 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5414
5415 region.imageSubresource.layerCount = 1;
5416 region.imageExtent.height = 4;
5417 region.imageExtent.width = 4;
5418 region.imageExtent.depth = 1;
5419 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5421 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005422 m_commandBuffer->EndCommandBuffer();
5423
5424 m_errorMonitor->VerifyFound();
5425
5426 vkDestroyBuffer(m_device->device(), buffer, NULL);
5427 vkFreeMemory(m_device->handle(), mem, NULL);
5428}
5429
Tobin Ehlis85940f52016-07-07 16:57:21 -06005430TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005431 TEST_DESCRIPTION(
5432 "Attempt to draw with a command buffer that is invalid "
5433 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005434 ASSERT_NO_FATAL_FAILURE(InitState());
5435
5436 VkEvent event;
5437 VkEventCreateInfo evci = {};
5438 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5439 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5440 ASSERT_VK_SUCCESS(result);
5441
5442 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005443 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005444 m_commandBuffer->EndCommandBuffer();
5445
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005447 // Destroy event dependency prior to submit to cause ERROR
5448 vkDestroyEvent(m_device->device(), event, NULL);
5449
5450 VkSubmitInfo submit_info = {};
5451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5452 submit_info.commandBufferCount = 1;
5453 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5454 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5455
5456 m_errorMonitor->VerifyFound();
5457}
5458
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005459TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005460 TEST_DESCRIPTION(
5461 "Attempt to draw with a command buffer that is invalid "
5462 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005463 ASSERT_NO_FATAL_FAILURE(InitState());
5464
5465 VkQueryPool query_pool;
5466 VkQueryPoolCreateInfo qpci{};
5467 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5468 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5469 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005470 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005471 ASSERT_VK_SUCCESS(result);
5472
5473 m_commandBuffer->BeginCommandBuffer();
5474 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5475 m_commandBuffer->EndCommandBuffer();
5476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005478 // Destroy query pool dependency prior to submit to cause ERROR
5479 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5480
5481 VkSubmitInfo submit_info = {};
5482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5483 submit_info.commandBufferCount = 1;
5484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5486
5487 m_errorMonitor->VerifyFound();
5488}
5489
Tobin Ehlis24130d92016-07-08 15:50:53 -06005490TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005491 TEST_DESCRIPTION(
5492 "Attempt to draw with a command buffer that is invalid "
5493 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
5495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5496
5497 VkResult err;
5498
5499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5501
5502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005504 ASSERT_VK_SUCCESS(err);
5505
5506 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5507 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5508 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005509 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005510 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005512 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005513 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005514
5515 VkPipelineShaderStageCreateInfo shaderStages[2];
5516 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005519 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005520 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005521 shaderStages[0] = vs.GetStageCreateInfo();
5522 shaderStages[1] = fs.GetStageCreateInfo();
5523
5524 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5525 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5526
5527 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5528 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5529 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5530
5531 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5532 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005533 rs_ci.rasterizerDiscardEnable = true;
5534 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005535
5536 VkPipelineColorBlendAttachmentState att = {};
5537 att.blendEnable = VK_FALSE;
5538 att.colorWriteMask = 0xf;
5539
5540 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5541 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5542 cb_ci.attachmentCount = 1;
5543 cb_ci.pAttachments = &att;
5544
5545 VkGraphicsPipelineCreateInfo gp_ci = {};
5546 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5547 gp_ci.stageCount = 2;
5548 gp_ci.pStages = shaderStages;
5549 gp_ci.pVertexInputState = &vi_ci;
5550 gp_ci.pInputAssemblyState = &ia_ci;
5551 gp_ci.pViewportState = &vp_state_ci;
5552 gp_ci.pRasterizationState = &rs_ci;
5553 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005554 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5555 gp_ci.layout = pipeline_layout;
5556 gp_ci.renderPass = renderPass();
5557
5558 VkPipelineCacheCreateInfo pc_ci = {};
5559 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5560
5561 VkPipeline pipeline;
5562 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 ASSERT_VK_SUCCESS(err);
5565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 ASSERT_VK_SUCCESS(err);
5568
5569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005571 m_commandBuffer->EndCommandBuffer();
5572 // Now destroy pipeline in order to cause error when submitting
5573 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005576
5577 VkSubmitInfo submit_info = {};
5578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5579 submit_info.commandBufferCount = 1;
5580 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5582
5583 m_errorMonitor->VerifyFound();
5584 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5586}
5587
Tobin Ehlis31289162016-08-17 14:57:58 -06005588TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005589 TEST_DESCRIPTION(
5590 "Attempt to draw with a command buffer that is invalid "
5591 "due to a bound descriptor set with a buffer dependency "
5592 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005593 ASSERT_NO_FATAL_FAILURE(InitState());
5594 ASSERT_NO_FATAL_FAILURE(InitViewport());
5595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5596
5597 VkDescriptorPoolSize ds_type_count = {};
5598 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5599 ds_type_count.descriptorCount = 1;
5600
5601 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5602 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5603 ds_pool_ci.pNext = NULL;
5604 ds_pool_ci.maxSets = 1;
5605 ds_pool_ci.poolSizeCount = 1;
5606 ds_pool_ci.pPoolSizes = &ds_type_count;
5607
5608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005609 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005610 ASSERT_VK_SUCCESS(err);
5611
5612 VkDescriptorSetLayoutBinding dsl_binding = {};
5613 dsl_binding.binding = 0;
5614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5615 dsl_binding.descriptorCount = 1;
5616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5617 dsl_binding.pImmutableSamplers = NULL;
5618
5619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5621 ds_layout_ci.pNext = NULL;
5622 ds_layout_ci.bindingCount = 1;
5623 ds_layout_ci.pBindings = &dsl_binding;
5624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005626 ASSERT_VK_SUCCESS(err);
5627
5628 VkDescriptorSet descriptorSet;
5629 VkDescriptorSetAllocateInfo alloc_info = {};
5630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5631 alloc_info.descriptorSetCount = 1;
5632 alloc_info.descriptorPool = ds_pool;
5633 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005635 ASSERT_VK_SUCCESS(err);
5636
5637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5639 pipeline_layout_ci.pNext = NULL;
5640 pipeline_layout_ci.setLayoutCount = 1;
5641 pipeline_layout_ci.pSetLayouts = &ds_layout;
5642
5643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005645 ASSERT_VK_SUCCESS(err);
5646
5647 // Create a buffer to update the descriptor with
5648 uint32_t qfi = 0;
5649 VkBufferCreateInfo buffCI = {};
5650 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5651 buffCI.size = 1024;
5652 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5653 buffCI.queueFamilyIndexCount = 1;
5654 buffCI.pQueueFamilyIndices = &qfi;
5655
5656 VkBuffer buffer;
5657 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5658 ASSERT_VK_SUCCESS(err);
5659 // Allocate memory and bind to buffer so we can make it to the appropriate
5660 // error
5661 VkMemoryAllocateInfo mem_alloc = {};
5662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5663 mem_alloc.pNext = NULL;
5664 mem_alloc.allocationSize = 1024;
5665 mem_alloc.memoryTypeIndex = 0;
5666
5667 VkMemoryRequirements memReqs;
5668 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005670 if (!pass) {
5671 vkDestroyBuffer(m_device->device(), buffer, NULL);
5672 return;
5673 }
5674
5675 VkDeviceMemory mem;
5676 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5677 ASSERT_VK_SUCCESS(err);
5678 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5679 ASSERT_VK_SUCCESS(err);
5680 // Correctly update descriptor to avoid "NOT_UPDATED" error
5681 VkDescriptorBufferInfo buffInfo = {};
5682 buffInfo.buffer = buffer;
5683 buffInfo.offset = 0;
5684 buffInfo.range = 1024;
5685
5686 VkWriteDescriptorSet descriptor_write;
5687 memset(&descriptor_write, 0, sizeof(descriptor_write));
5688 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5689 descriptor_write.dstSet = descriptorSet;
5690 descriptor_write.dstBinding = 0;
5691 descriptor_write.descriptorCount = 1;
5692 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5693 descriptor_write.pBufferInfo = &buffInfo;
5694
5695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5696
5697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005698 char const *vsSource =
5699 "#version 450\n"
5700 "\n"
5701 "out gl_PerVertex { \n"
5702 " vec4 gl_Position;\n"
5703 "};\n"
5704 "void main(){\n"
5705 " gl_Position = vec4(1);\n"
5706 "}\n";
5707 char const *fsSource =
5708 "#version 450\n"
5709 "\n"
5710 "layout(location=0) out vec4 x;\n"
5711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5712 "void main(){\n"
5713 " x = vec4(bar.y);\n"
5714 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5717 VkPipelineObj pipe(m_device);
5718 pipe.AddShader(&vs);
5719 pipe.AddShader(&fs);
5720 pipe.AddColorAttachment();
5721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5722
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->BeginCommandBuffer();
5724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5727 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005728
5729 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5730 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5731
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005733 m_commandBuffer->EndRenderPass();
5734 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005736 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5737 vkDestroyBuffer(m_device->device(), buffer, NULL);
5738 // Attempt to submit cmd buffer
5739 VkSubmitInfo submit_info = {};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5743 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5744 m_errorMonitor->VerifyFound();
5745 // Cleanup
5746 vkFreeMemory(m_device->device(), mem, NULL);
5747
5748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5751}
5752
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005754 TEST_DESCRIPTION(
5755 "Attempt to draw with a command buffer that is invalid "
5756 "due to a bound descriptor sets with a combined image "
5757 "sampler having their image, sampler, and descriptor set "
5758 "each respectively destroyed and then attempting to "
5759 "submit associated cmd buffers. Attempt to destroy a "
5760 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005761 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
5765 VkDescriptorPoolSize ds_type_count = {};
5766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5767 ds_type_count.descriptorCount = 1;
5768
5769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5771 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005772 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005773 ds_pool_ci.maxSets = 1;
5774 ds_pool_ci.poolSizeCount = 1;
5775 ds_pool_ci.pPoolSizes = &ds_type_count;
5776
5777 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSetLayoutBinding dsl_binding = {};
5782 dsl_binding.binding = 0;
5783 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5784 dsl_binding.descriptorCount = 1;
5785 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5786 dsl_binding.pImmutableSamplers = NULL;
5787
5788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5790 ds_layout_ci.pNext = NULL;
5791 ds_layout_ci.bindingCount = 1;
5792 ds_layout_ci.pBindings = &dsl_binding;
5793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkDescriptorSet descriptorSet;
5798 VkDescriptorSetAllocateInfo alloc_info = {};
5799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5800 alloc_info.descriptorSetCount = 1;
5801 alloc_info.descriptorPool = ds_pool;
5802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005804 ASSERT_VK_SUCCESS(err);
5805
5806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5808 pipeline_layout_ci.pNext = NULL;
5809 pipeline_layout_ci.setLayoutCount = 1;
5810 pipeline_layout_ci.pSetLayouts = &ds_layout;
5811
5812 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005814 ASSERT_VK_SUCCESS(err);
5815
5816 // Create images to update the descriptor with
5817 VkImage image;
5818 VkImage image2;
5819 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5820 const int32_t tex_width = 32;
5821 const int32_t tex_height = 32;
5822 VkImageCreateInfo image_create_info = {};
5823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5824 image_create_info.pNext = NULL;
5825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5826 image_create_info.format = tex_format;
5827 image_create_info.extent.width = tex_width;
5828 image_create_info.extent.height = tex_height;
5829 image_create_info.extent.depth = 1;
5830 image_create_info.mipLevels = 1;
5831 image_create_info.arrayLayers = 1;
5832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5833 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5835 image_create_info.flags = 0;
5836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5837 ASSERT_VK_SUCCESS(err);
5838 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5839 ASSERT_VK_SUCCESS(err);
5840
5841 VkMemoryRequirements memory_reqs;
5842 VkDeviceMemory image_memory;
5843 bool pass;
5844 VkMemoryAllocateInfo memory_info = {};
5845 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5846 memory_info.pNext = NULL;
5847 memory_info.allocationSize = 0;
5848 memory_info.memoryTypeIndex = 0;
5849 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5850 // Allocate enough memory for both images
5851 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005853 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5857 ASSERT_VK_SUCCESS(err);
5858 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860 ASSERT_VK_SUCCESS(err);
5861
5862 VkImageViewCreateInfo image_view_create_info = {};
5863 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5864 image_view_create_info.image = image;
5865 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5866 image_view_create_info.format = tex_format;
5867 image_view_create_info.subresourceRange.layerCount = 1;
5868 image_view_create_info.subresourceRange.baseMipLevel = 0;
5869 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871
5872 VkImageView view;
5873 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005875 ASSERT_VK_SUCCESS(err);
5876 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005878 ASSERT_VK_SUCCESS(err);
5879 // Create Samplers
5880 VkSamplerCreateInfo sampler_ci = {};
5881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5882 sampler_ci.pNext = NULL;
5883 sampler_ci.magFilter = VK_FILTER_NEAREST;
5884 sampler_ci.minFilter = VK_FILTER_NEAREST;
5885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5889 sampler_ci.mipLodBias = 1.0;
5890 sampler_ci.anisotropyEnable = VK_FALSE;
5891 sampler_ci.maxAnisotropy = 1;
5892 sampler_ci.compareEnable = VK_FALSE;
5893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5894 sampler_ci.minLod = 1.0;
5895 sampler_ci.maxLod = 1.0;
5896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5898 VkSampler sampler;
5899 VkSampler sampler2;
5900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5901 ASSERT_VK_SUCCESS(err);
5902 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5903 ASSERT_VK_SUCCESS(err);
5904 // Update descriptor with image and sampler
5905 VkDescriptorImageInfo img_info = {};
5906 img_info.sampler = sampler;
5907 img_info.imageView = view;
5908 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5909
5910 VkWriteDescriptorSet descriptor_write;
5911 memset(&descriptor_write, 0, sizeof(descriptor_write));
5912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5913 descriptor_write.dstSet = descriptorSet;
5914 descriptor_write.dstBinding = 0;
5915 descriptor_write.descriptorCount = 1;
5916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5917 descriptor_write.pImageInfo = &img_info;
5918
5919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5920
5921 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005922 char const *vsSource =
5923 "#version 450\n"
5924 "\n"
5925 "out gl_PerVertex { \n"
5926 " vec4 gl_Position;\n"
5927 "};\n"
5928 "void main(){\n"
5929 " gl_Position = vec4(1);\n"
5930 "}\n";
5931 char const *fsSource =
5932 "#version 450\n"
5933 "\n"
5934 "layout(set=0, binding=0) uniform sampler2D s;\n"
5935 "layout(location=0) out vec4 x;\n"
5936 "void main(){\n"
5937 " x = texture(s, vec2(1));\n"
5938 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005939 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5940 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5941 VkPipelineObj pipe(m_device);
5942 pipe.AddShader(&vs);
5943 pipe.AddShader(&fs);
5944 pipe.AddColorAttachment();
5945 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5946
5947 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->BeginCommandBuffer();
5950 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5952 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5953 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005954 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5955 VkRect2D scissor = {{0, 0}, {16, 16}};
5956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5957 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005958 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005959 m_commandBuffer->EndRenderPass();
5960 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 // Destroy sampler invalidates the cmd buffer, causing error on submit
5962 vkDestroySampler(m_device->device(), sampler, NULL);
5963 // Attempt to submit cmd buffer
5964 VkSubmitInfo submit_info = {};
5965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5966 submit_info.commandBufferCount = 1;
5967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5969 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005970
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005971 // Now re-update descriptor with valid sampler and delete image
5972 img_info.sampler = sampler2;
5973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005974
5975 VkCommandBufferBeginInfo info = {};
5976 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5977 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005980 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005981 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5983 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5984 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005987 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005988 m_commandBuffer->EndRenderPass();
5989 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005990 // Destroy image invalidates the cmd buffer, causing error on submit
5991 vkDestroyImage(m_device->device(), image, NULL);
5992 // Attempt to submit cmd buffer
5993 submit_info = {};
5994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5995 submit_info.commandBufferCount = 1;
5996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5998 m_errorMonitor->VerifyFound();
5999 // Now update descriptor to be valid, but then free descriptor
6000 img_info.imageView = view2;
6001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006002 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6008 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006010 m_commandBuffer->EndRenderPass();
6011 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006013
6014 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006016 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006017 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006018
6019 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006020 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006021 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006022 m_errorMonitor->SetUnexpectedError(
6023 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6024 "either be a valid handle or VK_NULL_HANDLE");
6025 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006026 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6027
6028 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006029 submit_info = {};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6035 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006037 // Cleanup
6038 vkFreeMemory(m_device->device(), image_memory, NULL);
6039 vkDestroySampler(m_device->device(), sampler2, NULL);
6040 vkDestroyImage(m_device->device(), image2, NULL);
6041 vkDestroyImageView(m_device->device(), view, NULL);
6042 vkDestroyImageView(m_device->device(), view2, NULL);
6043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6046}
6047
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006048TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6049 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6050 ASSERT_NO_FATAL_FAILURE(InitState());
6051 ASSERT_NO_FATAL_FAILURE(InitViewport());
6052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6053
6054 VkDescriptorPoolSize ds_type_count = {};
6055 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6056 ds_type_count.descriptorCount = 1;
6057
6058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6060 ds_pool_ci.pNext = NULL;
6061 ds_pool_ci.maxSets = 1;
6062 ds_pool_ci.poolSizeCount = 1;
6063 ds_pool_ci.pPoolSizes = &ds_type_count;
6064
6065 VkDescriptorPool ds_pool;
6066 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6067 ASSERT_VK_SUCCESS(err);
6068
6069 VkDescriptorSetLayoutBinding dsl_binding = {};
6070 dsl_binding.binding = 0;
6071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6072 dsl_binding.descriptorCount = 1;
6073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6074 dsl_binding.pImmutableSamplers = NULL;
6075
6076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6078 ds_layout_ci.pNext = NULL;
6079 ds_layout_ci.bindingCount = 1;
6080 ds_layout_ci.pBindings = &dsl_binding;
6081 VkDescriptorSetLayout ds_layout;
6082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6083 ASSERT_VK_SUCCESS(err);
6084
6085 VkDescriptorSet descriptor_set;
6086 VkDescriptorSetAllocateInfo alloc_info = {};
6087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6088 alloc_info.descriptorSetCount = 1;
6089 alloc_info.descriptorPool = ds_pool;
6090 alloc_info.pSetLayouts = &ds_layout;
6091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6092 ASSERT_VK_SUCCESS(err);
6093
6094 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6095 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6096 pipeline_layout_ci.pNext = NULL;
6097 pipeline_layout_ci.setLayoutCount = 1;
6098 pipeline_layout_ci.pSetLayouts = &ds_layout;
6099
6100 VkPipelineLayout pipeline_layout;
6101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6102 ASSERT_VK_SUCCESS(err);
6103
6104 // Create image to update the descriptor with
6105 VkImageObj image(m_device);
6106 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6107 ASSERT_TRUE(image.initialized());
6108
6109 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6110 // Create Sampler
6111 VkSamplerCreateInfo sampler_ci = {};
6112 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6113 sampler_ci.pNext = NULL;
6114 sampler_ci.magFilter = VK_FILTER_NEAREST;
6115 sampler_ci.minFilter = VK_FILTER_NEAREST;
6116 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6117 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6118 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6119 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6120 sampler_ci.mipLodBias = 1.0;
6121 sampler_ci.anisotropyEnable = VK_FALSE;
6122 sampler_ci.maxAnisotropy = 1;
6123 sampler_ci.compareEnable = VK_FALSE;
6124 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6125 sampler_ci.minLod = 1.0;
6126 sampler_ci.maxLod = 1.0;
6127 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6128 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6129 VkSampler sampler;
6130 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6131 ASSERT_VK_SUCCESS(err);
6132 // Update descriptor with image and sampler
6133 VkDescriptorImageInfo img_info = {};
6134 img_info.sampler = sampler;
6135 img_info.imageView = view;
6136 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6137
6138 VkWriteDescriptorSet descriptor_write;
6139 memset(&descriptor_write, 0, sizeof(descriptor_write));
6140 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6141 descriptor_write.dstSet = descriptor_set;
6142 descriptor_write.dstBinding = 0;
6143 descriptor_write.descriptorCount = 1;
6144 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6145 descriptor_write.pImageInfo = &img_info;
6146
6147 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6148
6149 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006150 char const *vsSource =
6151 "#version 450\n"
6152 "\n"
6153 "out gl_PerVertex { \n"
6154 " vec4 gl_Position;\n"
6155 "};\n"
6156 "void main(){\n"
6157 " gl_Position = vec4(1);\n"
6158 "}\n";
6159 char const *fsSource =
6160 "#version 450\n"
6161 "\n"
6162 "layout(set=0, binding=0) uniform sampler2D s;\n"
6163 "layout(location=0) out vec4 x;\n"
6164 "void main(){\n"
6165 " x = texture(s, vec2(1));\n"
6166 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6169 VkPipelineObj pipe(m_device);
6170 pipe.AddShader(&vs);
6171 pipe.AddShader(&fs);
6172 pipe.AddColorAttachment();
6173 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6174
Tony Barbour552f6c02016-12-21 14:34:07 -07006175 m_commandBuffer->BeginCommandBuffer();
6176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006177 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6178 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6179 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006180
6181 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6182 VkRect2D scissor = {{0, 0}, {16, 16}};
6183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6184 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6185
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006186 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006187 m_commandBuffer->EndRenderPass();
6188 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189 // Submit cmd buffer to put pool in-flight
6190 VkSubmitInfo submit_info = {};
6191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6192 submit_info.commandBufferCount = 1;
6193 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6194 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6195 // Destroy pool while in-flight, causing error
6196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6198 m_errorMonitor->VerifyFound();
6199 vkQueueWaitIdle(m_device->m_queue);
6200 // Cleanup
6201 vkDestroySampler(m_device->device(), sampler, NULL);
6202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006204 m_errorMonitor->SetUnexpectedError(
6205 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6206 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006208 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006209}
6210
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006211TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6212 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6213 ASSERT_NO_FATAL_FAILURE(InitState());
6214 ASSERT_NO_FATAL_FAILURE(InitViewport());
6215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6216
6217 VkDescriptorPoolSize ds_type_count = {};
6218 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6219 ds_type_count.descriptorCount = 1;
6220
6221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6223 ds_pool_ci.pNext = NULL;
6224 ds_pool_ci.maxSets = 1;
6225 ds_pool_ci.poolSizeCount = 1;
6226 ds_pool_ci.pPoolSizes = &ds_type_count;
6227
6228 VkDescriptorPool ds_pool;
6229 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6230 ASSERT_VK_SUCCESS(err);
6231
6232 VkDescriptorSetLayoutBinding dsl_binding = {};
6233 dsl_binding.binding = 0;
6234 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6235 dsl_binding.descriptorCount = 1;
6236 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6237 dsl_binding.pImmutableSamplers = NULL;
6238
6239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6241 ds_layout_ci.pNext = NULL;
6242 ds_layout_ci.bindingCount = 1;
6243 ds_layout_ci.pBindings = &dsl_binding;
6244 VkDescriptorSetLayout ds_layout;
6245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6246 ASSERT_VK_SUCCESS(err);
6247
6248 VkDescriptorSet descriptorSet;
6249 VkDescriptorSetAllocateInfo alloc_info = {};
6250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6251 alloc_info.descriptorSetCount = 1;
6252 alloc_info.descriptorPool = ds_pool;
6253 alloc_info.pSetLayouts = &ds_layout;
6254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6255 ASSERT_VK_SUCCESS(err);
6256
6257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6259 pipeline_layout_ci.pNext = NULL;
6260 pipeline_layout_ci.setLayoutCount = 1;
6261 pipeline_layout_ci.pSetLayouts = &ds_layout;
6262
6263 VkPipelineLayout pipeline_layout;
6264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6265 ASSERT_VK_SUCCESS(err);
6266
6267 // Create images to update the descriptor with
6268 VkImage image;
6269 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6270 const int32_t tex_width = 32;
6271 const int32_t tex_height = 32;
6272 VkImageCreateInfo image_create_info = {};
6273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6274 image_create_info.pNext = NULL;
6275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6276 image_create_info.format = tex_format;
6277 image_create_info.extent.width = tex_width;
6278 image_create_info.extent.height = tex_height;
6279 image_create_info.extent.depth = 1;
6280 image_create_info.mipLevels = 1;
6281 image_create_info.arrayLayers = 1;
6282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6284 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6285 image_create_info.flags = 0;
6286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6287 ASSERT_VK_SUCCESS(err);
6288 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6289 VkMemoryRequirements memory_reqs;
6290 VkDeviceMemory image_memory;
6291 bool pass;
6292 VkMemoryAllocateInfo memory_info = {};
6293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6294 memory_info.pNext = NULL;
6295 memory_info.allocationSize = 0;
6296 memory_info.memoryTypeIndex = 0;
6297 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6298 // Allocate enough memory for image
6299 memory_info.allocationSize = memory_reqs.size;
6300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6301 ASSERT_TRUE(pass);
6302 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6303 ASSERT_VK_SUCCESS(err);
6304 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6305 ASSERT_VK_SUCCESS(err);
6306
6307 VkImageViewCreateInfo image_view_create_info = {};
6308 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6309 image_view_create_info.image = image;
6310 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6311 image_view_create_info.format = tex_format;
6312 image_view_create_info.subresourceRange.layerCount = 1;
6313 image_view_create_info.subresourceRange.baseMipLevel = 0;
6314 image_view_create_info.subresourceRange.levelCount = 1;
6315 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6316
6317 VkImageView view;
6318 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6319 ASSERT_VK_SUCCESS(err);
6320 // Create Samplers
6321 VkSamplerCreateInfo sampler_ci = {};
6322 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6323 sampler_ci.pNext = NULL;
6324 sampler_ci.magFilter = VK_FILTER_NEAREST;
6325 sampler_ci.minFilter = VK_FILTER_NEAREST;
6326 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6327 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6328 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6329 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6330 sampler_ci.mipLodBias = 1.0;
6331 sampler_ci.anisotropyEnable = VK_FALSE;
6332 sampler_ci.maxAnisotropy = 1;
6333 sampler_ci.compareEnable = VK_FALSE;
6334 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6335 sampler_ci.minLod = 1.0;
6336 sampler_ci.maxLod = 1.0;
6337 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6338 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6339 VkSampler sampler;
6340 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6341 ASSERT_VK_SUCCESS(err);
6342 // Update descriptor with image and sampler
6343 VkDescriptorImageInfo img_info = {};
6344 img_info.sampler = sampler;
6345 img_info.imageView = view;
6346 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6347
6348 VkWriteDescriptorSet descriptor_write;
6349 memset(&descriptor_write, 0, sizeof(descriptor_write));
6350 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6351 descriptor_write.dstSet = descriptorSet;
6352 descriptor_write.dstBinding = 0;
6353 descriptor_write.descriptorCount = 1;
6354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6355 descriptor_write.pImageInfo = &img_info;
6356 // Break memory binding and attempt update
6357 vkFreeMemory(m_device->device(), image_memory, nullptr);
6358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006359 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6361 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6363 m_errorMonitor->VerifyFound();
6364 // Cleanup
6365 vkDestroyImage(m_device->device(), image, NULL);
6366 vkDestroySampler(m_device->device(), sampler, NULL);
6367 vkDestroyImageView(m_device->device(), view, NULL);
6368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6371}
6372
Karl Schultz6addd812016-02-02 17:17:23 -07006373TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006374 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6375 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006376 // Create a valid cmd buffer
6377 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006378 uint64_t fake_pipeline_handle = 0xbaad6001;
6379 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006380 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6382
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006384 m_commandBuffer->BeginCommandBuffer();
6385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006387 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006388
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006389 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006391 Draw(1, 0, 0, 0);
6392 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006393
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006394 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006396 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006397 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6398 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006399}
6400
Karl Schultz6addd812016-02-02 17:17:23 -07006401TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006402 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006403 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006406
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006407 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006408 ASSERT_NO_FATAL_FAILURE(InitViewport());
6409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006410 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6412 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006413
6414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6416 ds_pool_ci.pNext = NULL;
6417 ds_pool_ci.maxSets = 1;
6418 ds_pool_ci.poolSizeCount = 1;
6419 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006420
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006423 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006424
Tony Barboureb254902015-07-15 12:50:33 -06006425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 dsl_binding.binding = 0;
6427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6428 dsl_binding.descriptorCount = 1;
6429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006431
Tony Barboureb254902015-07-15 12:50:33 -06006432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6434 ds_layout_ci.pNext = NULL;
6435 ds_layout_ci.bindingCount = 1;
6436 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006437 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006439 ASSERT_VK_SUCCESS(err);
6440
6441 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006442 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006444 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006445 alloc_info.descriptorPool = ds_pool;
6446 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006448 ASSERT_VK_SUCCESS(err);
6449
Tony Barboureb254902015-07-15 12:50:33 -06006450 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6452 pipeline_layout_ci.pNext = NULL;
6453 pipeline_layout_ci.setLayoutCount = 1;
6454 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
6456 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006458 ASSERT_VK_SUCCESS(err);
6459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006461 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006462 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006464
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006465 VkPipelineObj pipe(m_device);
6466 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006467 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006468 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006469 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006470
Tony Barbour552f6c02016-12-21 14:34:07 -07006471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6474 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006475
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006476 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477
Chia-I Wuf7458c52015-10-26 21:10:41 +08006478 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006481}
6482
Karl Schultz6addd812016-02-02 17:17:23 -07006483TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006484 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006486
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006488
6489 ASSERT_NO_FATAL_FAILURE(InitState());
6490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6492 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493
6494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6496 ds_pool_ci.pNext = NULL;
6497 ds_pool_ci.maxSets = 1;
6498 ds_pool_ci.poolSizeCount = 1;
6499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006500
6501 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006503 ASSERT_VK_SUCCESS(err);
6504
6505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 dsl_binding.binding = 0;
6507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6508 dsl_binding.descriptorCount = 1;
6509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6510 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511
6512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6514 ds_layout_ci.pNext = NULL;
6515 ds_layout_ci.bindingCount = 1;
6516 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006517 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006519 ASSERT_VK_SUCCESS(err);
6520
6521 VkDescriptorSet descriptorSet;
6522 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006525 alloc_info.descriptorPool = ds_pool;
6526 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006528 ASSERT_VK_SUCCESS(err);
6529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006530 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006531 VkWriteDescriptorSet descriptor_write;
6532 memset(&descriptor_write, 0, sizeof(descriptor_write));
6533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6534 descriptor_write.dstSet = descriptorSet;
6535 descriptor_write.dstBinding = 0;
6536 descriptor_write.descriptorCount = 1;
6537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6538 descriptor_write.pTexelBufferView = &view;
6539
6540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006543
6544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6546}
6547
Mark Youngd339ba32016-05-30 13:28:35 -06006548TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006549 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06006550
6551 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006553 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006554
6555 ASSERT_NO_FATAL_FAILURE(InitState());
6556
6557 // Create a buffer with no bound memory and then attempt to create
6558 // a buffer view.
6559 VkBufferCreateInfo buff_ci = {};
6560 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006561 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006562 buff_ci.size = 256;
6563 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6564 VkBuffer buffer;
6565 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6566 ASSERT_VK_SUCCESS(err);
6567
6568 VkBufferViewCreateInfo buff_view_ci = {};
6569 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6570 buff_view_ci.buffer = buffer;
6571 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6572 buff_view_ci.range = VK_WHOLE_SIZE;
6573 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006575
6576 m_errorMonitor->VerifyFound();
6577 vkDestroyBuffer(m_device->device(), buffer, NULL);
6578 // If last error is success, it still created the view, so delete it.
6579 if (err == VK_SUCCESS) {
6580 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6581 }
6582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6585 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6586 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006587 // 1. No dynamicOffset supplied
6588 // 2. Too many dynamicOffsets supplied
6589 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006590 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6592 " requires 1 dynamicOffsets, but only "
6593 "0 dynamicOffsets are left in "
6594 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006595
6596 ASSERT_NO_FATAL_FAILURE(InitState());
6597 ASSERT_NO_FATAL_FAILURE(InitViewport());
6598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6599
6600 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6602 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006603
6604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6606 ds_pool_ci.pNext = NULL;
6607 ds_pool_ci.maxSets = 1;
6608 ds_pool_ci.poolSizeCount = 1;
6609 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006613 ASSERT_VK_SUCCESS(err);
6614
6615 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006616 dsl_binding.binding = 0;
6617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 dsl_binding.descriptorCount = 1;
6619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6620 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006621
6622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6624 ds_layout_ci.pNext = NULL;
6625 ds_layout_ci.bindingCount = 1;
6626 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006627 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006629 ASSERT_VK_SUCCESS(err);
6630
6631 VkDescriptorSet descriptorSet;
6632 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006633 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006634 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006635 alloc_info.descriptorPool = ds_pool;
6636 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638 ASSERT_VK_SUCCESS(err);
6639
6640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6642 pipeline_layout_ci.pNext = NULL;
6643 pipeline_layout_ci.setLayoutCount = 1;
6644 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006645
6646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006648 ASSERT_VK_SUCCESS(err);
6649
6650 // Create a buffer to update the descriptor with
6651 uint32_t qfi = 0;
6652 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006653 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6654 buffCI.size = 1024;
6655 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6656 buffCI.queueFamilyIndexCount = 1;
6657 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006658
6659 VkBuffer dyub;
6660 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6661 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006662 // Allocate memory and bind to buffer so we can make it to the appropriate
6663 // error
6664 VkMemoryAllocateInfo mem_alloc = {};
6665 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6666 mem_alloc.pNext = NULL;
6667 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006668 mem_alloc.memoryTypeIndex = 0;
6669
6670 VkMemoryRequirements memReqs;
6671 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006673 if (!pass) {
6674 vkDestroyBuffer(m_device->device(), dyub, NULL);
6675 return;
6676 }
6677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 VkDeviceMemory mem;
6679 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6680 ASSERT_VK_SUCCESS(err);
6681 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6682 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 // Correctly update descriptor to avoid "NOT_UPDATED" error
6684 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 buffInfo.buffer = dyub;
6686 buffInfo.offset = 0;
6687 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006688
6689 VkWriteDescriptorSet descriptor_write;
6690 memset(&descriptor_write, 0, sizeof(descriptor_write));
6691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6692 descriptor_write.dstSet = descriptorSet;
6693 descriptor_write.dstBinding = 0;
6694 descriptor_write.descriptorCount = 1;
6695 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6696 descriptor_write.pBufferInfo = &buffInfo;
6697
6698 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6699
Tony Barbour552f6c02016-12-21 14:34:07 -07006700 m_commandBuffer->BeginCommandBuffer();
6701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6703 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006704 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006705 uint32_t pDynOff[2] = {512, 756};
6706 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6708 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6710 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006711 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006712 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6714 " dynamic offset 512 combined with "
6715 "offset 0 and range 1024 that "
6716 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006717 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006718 char const *vsSource =
6719 "#version 450\n"
6720 "\n"
6721 "out gl_PerVertex { \n"
6722 " vec4 gl_Position;\n"
6723 "};\n"
6724 "void main(){\n"
6725 " gl_Position = vec4(1);\n"
6726 "}\n";
6727 char const *fsSource =
6728 "#version 450\n"
6729 "\n"
6730 "layout(location=0) out vec4 x;\n"
6731 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6732 "void main(){\n"
6733 " x = vec4(bar.y);\n"
6734 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006735 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6736 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6737 VkPipelineObj pipe(m_device);
6738 pipe.AddShader(&vs);
6739 pipe.AddShader(&fs);
6740 pipe.AddColorAttachment();
6741 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6742
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006743 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6744 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6745 VkRect2D scissor = {{0, 0}, {16, 16}};
6746 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // This update should succeed, but offset size of 512 will overstep buffer
6750 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6752 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006753 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006755
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006756 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006757 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006758
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6762}
6763
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006764TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006765 TEST_DESCRIPTION(
6766 "Attempt to update a descriptor with a non-sparse buffer "
6767 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006768 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006770 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6772 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
6775 ASSERT_NO_FATAL_FAILURE(InitViewport());
6776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6777
6778 VkDescriptorPoolSize ds_type_count = {};
6779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6780 ds_type_count.descriptorCount = 1;
6781
6782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6784 ds_pool_ci.pNext = NULL;
6785 ds_pool_ci.maxSets = 1;
6786 ds_pool_ci.poolSizeCount = 1;
6787 ds_pool_ci.pPoolSizes = &ds_type_count;
6788
6789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006791 ASSERT_VK_SUCCESS(err);
6792
6793 VkDescriptorSetLayoutBinding dsl_binding = {};
6794 dsl_binding.binding = 0;
6795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6796 dsl_binding.descriptorCount = 1;
6797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6798 dsl_binding.pImmutableSamplers = NULL;
6799
6800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6802 ds_layout_ci.pNext = NULL;
6803 ds_layout_ci.bindingCount = 1;
6804 ds_layout_ci.pBindings = &dsl_binding;
6805 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006807 ASSERT_VK_SUCCESS(err);
6808
6809 VkDescriptorSet descriptorSet;
6810 VkDescriptorSetAllocateInfo alloc_info = {};
6811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6812 alloc_info.descriptorSetCount = 1;
6813 alloc_info.descriptorPool = ds_pool;
6814 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006816 ASSERT_VK_SUCCESS(err);
6817
6818 // Create a buffer to update the descriptor with
6819 uint32_t qfi = 0;
6820 VkBufferCreateInfo buffCI = {};
6821 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6822 buffCI.size = 1024;
6823 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6824 buffCI.queueFamilyIndexCount = 1;
6825 buffCI.pQueueFamilyIndices = &qfi;
6826
6827 VkBuffer dyub;
6828 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6829 ASSERT_VK_SUCCESS(err);
6830
6831 // Attempt to update descriptor without binding memory to it
6832 VkDescriptorBufferInfo buffInfo = {};
6833 buffInfo.buffer = dyub;
6834 buffInfo.offset = 0;
6835 buffInfo.range = 1024;
6836
6837 VkWriteDescriptorSet descriptor_write;
6838 memset(&descriptor_write, 0, sizeof(descriptor_write));
6839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6840 descriptor_write.dstSet = descriptorSet;
6841 descriptor_write.dstBinding = 0;
6842 descriptor_write.descriptorCount = 1;
6843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6844 descriptor_write.pBufferInfo = &buffInfo;
6845
6846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6847 m_errorMonitor->VerifyFound();
6848
6849 vkDestroyBuffer(m_device->device(), dyub, NULL);
6850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6852}
6853
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006855 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006856 ASSERT_NO_FATAL_FAILURE(InitState());
6857 ASSERT_NO_FATAL_FAILURE(InitViewport());
6858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6859
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006861 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.pushConstantRangeCount = 1;
6865 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6866
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006867 //
6868 // Check for invalid push constant ranges in pipeline layouts.
6869 //
6870 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006872 char const *msg;
6873 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006874
Karl Schultzc81037d2016-05-12 08:11:23 -06006875 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6876 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6877 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6878 "vkCreatePipelineLayout() call has push constants index 0 with "
6879 "size 0."},
6880 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6881 "vkCreatePipelineLayout() call has push constants index 0 with "
6882 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006883 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006884 "vkCreatePipelineLayout() call has push constants index 0 with "
6885 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006886 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006887 "vkCreatePipelineLayout() call has push constants index 0 with "
6888 "size 0."},
6889 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6890 "vkCreatePipelineLayout() call has push constants index 0 with "
6891 "offset 1. Offset must"},
6892 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6893 "vkCreatePipelineLayout() call has push constants index 0 "
6894 "with offset "},
6895 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6896 "vkCreatePipelineLayout() call has push constants "
6897 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006898 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006899 "vkCreatePipelineLayout() call has push constants index 0 "
6900 "with offset "},
6901 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6902 "vkCreatePipelineLayout() call has push "
6903 "constants index 0 with offset "},
6904 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6905 "vkCreatePipelineLayout() call has push "
6906 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006907 }};
6908
6909 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006910 for (const auto &iter : range_tests) {
6911 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914 m_errorMonitor->VerifyFound();
6915 if (VK_SUCCESS == err) {
6916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6917 }
6918 }
6919
6920 // Check for invalid stage flag
6921 pc_range.offset = 0;
6922 pc_range.size = 16;
6923 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006924 m_errorMonitor->SetDesiredFailureMsg(
6925 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6926 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006928 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929 if (VK_SUCCESS == err) {
6930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6931 }
6932
Karl Schultzc59b72d2017-02-24 15:45:05 -07006933 // Check for duplicate stage flags in a list of push constant ranges.
6934 // A shader can only have one push constant block and that block is mapped
6935 // to the push constant range that has that shader's stage flag set.
6936 // The shader's stage flag can only appear once in all the ranges, so the
6937 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006938 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006939 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006941 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006943 // Overlapping ranges are OK, but a stage flag can appear only once.
6944 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6945 {
6946 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6948 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6949 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006950 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006951 {
6952 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6953 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6954 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6955 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6956 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6957 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6961 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6962 }},
6963 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6964 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6965 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6966 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6967 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6968 {
6969 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6970 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6971 }},
6972 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6973 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6974 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6975 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6976 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6977 {
6978 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6979 }},
6980 },
6981 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006982
Karl Schultzc59b72d2017-02-24 15:45:05 -07006983 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006985 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988 m_errorMonitor->VerifyFound();
6989 if (VK_SUCCESS == err) {
6990 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6991 }
6992 }
6993
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006994 //
6995 // CmdPushConstants tests
6996 //
6997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006999 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007000 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007003 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007005 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007006
7007 const uint8_t dummy_values[100] = {};
7008
7009 m_commandBuffer->BeginCommandBuffer();
7010 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007011
7012 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007013 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007016 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007017
Karl Schultzc59b72d2017-02-24 15:45:05 -07007018 m_errorMonitor->ExpectSuccess();
7019 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7020 m_errorMonitor->VerifyNotFound();
7021 m_errorMonitor->ExpectSuccess();
7022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7023 m_errorMonitor->VerifyNotFound();
7024 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7025 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7026 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7027 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7028 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7029 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7030 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007031 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007032 for (const auto &iter : cmd_range_tests) {
7033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7034 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7035 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 m_errorMonitor->VerifyFound();
7037 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007038
Tony Barbour552f6c02016-12-21 14:34:07 -07007039 m_commandBuffer->EndRenderPass();
7040 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007041 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007042}
7043
Karl Schultz6addd812016-02-02 17:17:23 -07007044TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007046 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 ASSERT_NO_FATAL_FAILURE(InitState());
7049 ASSERT_NO_FATAL_FAILURE(InitViewport());
7050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7051
7052 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7053 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007054 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7055 ds_type_count[0].descriptorCount = 10;
7056 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7057 ds_type_count[1].descriptorCount = 2;
7058 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7059 ds_type_count[2].descriptorCount = 2;
7060 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7061 ds_type_count[3].descriptorCount = 5;
7062 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7063 // type
7064 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7065 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7066 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007067
7068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7070 ds_pool_ci.pNext = NULL;
7071 ds_pool_ci.maxSets = 5;
7072 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7073 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007074
7075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007077 ASSERT_VK_SUCCESS(err);
7078
7079 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7080 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 dsl_binding[0].binding = 0;
7082 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7083 dsl_binding[0].descriptorCount = 5;
7084 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7085 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 // Create layout identical to set0 layout but w/ different stageFlags
7088 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007089 dsl_fs_stage_only.binding = 0;
7090 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007092 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7093 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7097 ds_layout_ci.pNext = NULL;
7098 ds_layout_ci.bindingCount = 1;
7099 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 static const uint32_t NUM_LAYOUTS = 4;
7101 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007103 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7104 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007106 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007107 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 dsl_binding[0].binding = 0;
7111 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007112 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007113 dsl_binding[1].binding = 1;
7114 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7115 dsl_binding[1].descriptorCount = 2;
7116 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7117 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007118 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
7122 dsl_binding[0].binding = 0;
7123 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 ASSERT_VK_SUCCESS(err);
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 ASSERT_VK_SUCCESS(err);
7132
7133 static const uint32_t NUM_SETS = 4;
7134 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7135 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007137 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138 alloc_info.descriptorPool = ds_pool;
7139 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007141 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007142 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007143 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007147
7148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7150 pipeline_layout_ci.pNext = NULL;
7151 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7152 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007153
7154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007156 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007157 // Create pipelineLayout with only one setLayout
7158 pipeline_layout_ci.setLayoutCount = 1;
7159 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 ASSERT_VK_SUCCESS(err);
7162 // Create pipelineLayout with 2 descriptor setLayout at index 0
7163 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7164 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7169 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with UB type, but stageFlags for FS only
7173 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7174 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7178 VkDescriptorSetLayout pl_bad_s0[2] = {};
7179 pl_bad_s0[0] = ds_layout_fs_only;
7180 pl_bad_s0[1] = ds_layout[1];
7181 pipeline_layout_ci.setLayoutCount = 2;
7182 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7183 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007186
Tobin Ehlis88452832015-12-03 09:40:56 -07007187 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007188 char const *vsSource =
7189 "#version 450\n"
7190 "\n"
7191 "out gl_PerVertex {\n"
7192 " vec4 gl_Position;\n"
7193 "};\n"
7194 "void main(){\n"
7195 " gl_Position = vec4(1);\n"
7196 "}\n";
7197 char const *fsSource =
7198 "#version 450\n"
7199 "\n"
7200 "layout(location=0) out vec4 x;\n"
7201 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7202 "void main(){\n"
7203 " x = vec4(bar.y);\n"
7204 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007207 VkPipelineObj pipe(m_device);
7208 pipe.AddShader(&vs);
7209 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 pipe.AddColorAttachment();
7211 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212
Tony Barbour552f6c02016-12-21 14:34:07 -07007213 m_commandBuffer->BeginCommandBuffer();
7214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007216 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007217 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7218 // of PSO
7219 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7220 // cmd_pipeline.c
7221 // due to the fact that cmd_alloc_dset_data() has not been called in
7222 // cmd_bind_graphics_pipeline()
7223 // TODO : Want to cause various binding incompatibility issues here to test
7224 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 // First cause various verify_layout_compatibility() fails
7226 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007227 // verify_set_layout_compatibility fail cases:
7228 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7231 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007232 m_errorMonitor->VerifyFound();
7233
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007234 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7237 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007238 m_errorMonitor->VerifyFound();
7239
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007240 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007241 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7242 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7245 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
7247
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007248 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7249 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7252 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007253 m_errorMonitor->VerifyFound();
7254
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7256 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7258 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Cause INFO messages due to disturbing previously bound Sets
7264 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7266 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007267 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7270 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
7272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7274 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007275 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7277 " newly bound as set #0 so set #1 and "
7278 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7280 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis10fad692016-07-07 12:00:36 -06007283 // Now that we're done actively using the pipelineLayout that gfx pipeline
7284 // was created with, we should be able to delete it. Do that now to verify
7285 // that validation obeys pipelineLayout lifetime
7286 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7287
Tobin Ehlis88452832015-12-03 09:40:56 -07007288 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007289 // 1. Error due to not binding required set (we actually use same code as
7290 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7292 &descriptorSet[0], 0, NULL);
7293 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7294 &descriptorSet[1], 0, NULL);
7295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007296
7297 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7298 VkRect2D scissor = {{0, 0}, {16, 16}};
7299 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7300 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7301
Tobin Ehlis88452832015-12-03 09:40:56 -07007302 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007303 m_errorMonitor->VerifyFound();
7304
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007305 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007306 // 2. Error due to bound set not being compatible with PSO's
7307 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007308 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7309 &descriptorSet[0], 0, NULL);
7310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007311 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
7313
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007314 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007315 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7317 }
7318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7321}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007322
Karl Schultz6addd812016-02-02 17:17:23 -07007323TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7325 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007326
7327 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007329 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007332 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007333}
7334
Karl Schultz6addd812016-02-02 17:17:23 -07007335TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7336 VkResult err;
7337 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007338
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007344 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007345 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 cmd.commandPool = m_commandPool;
7347 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007348 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007351 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007352
7353 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007354 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007355 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7356
7357 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007358 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007359 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007361 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007362
7363 // The error should be caught by validation of the BeginCommandBuffer call
7364 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007366 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007367 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007368}
7369
Karl Schultz6addd812016-02-02 17:17:23 -07007370TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007371 // Cause error due to Begin while recording CB
7372 // Then cause 2 errors for attempting to reset CB w/o having
7373 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7374 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376
7377 ASSERT_NO_FATAL_FAILURE(InitState());
7378
7379 // Calls AllocateCommandBuffers
7380 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007382 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007383 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007384 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7385 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007386 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7387 cmd_buf_info.pNext = NULL;
7388 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007389 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007390
7391 // Begin CB to transition to recording state
7392 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7393 // Can't re-begin. This should trigger error
7394 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007395 m_errorMonitor->VerifyFound();
7396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007398 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007399 // Reset attempt will trigger error due to incorrect CommandPool state
7400 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007401 m_errorMonitor->VerifyFound();
7402
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Transition CB to RECORDED state
7405 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7406 // Now attempting to Begin will implicitly reset, which triggers error
7407 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409}
7410
Karl Schultz6addd812016-02-02 17:17:23 -07007411TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007413 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7416 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007417
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007420
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007421 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7423 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007424
7425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7427 ds_pool_ci.pNext = NULL;
7428 ds_pool_ci.maxSets = 1;
7429 ds_pool_ci.poolSizeCount = 1;
7430 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007431
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007432 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007434 ASSERT_VK_SUCCESS(err);
7435
Tony Barboureb254902015-07-15 12:50:33 -06007436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007437 dsl_binding.binding = 0;
7438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7439 dsl_binding.descriptorCount = 1;
7440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007442
Tony Barboureb254902015-07-15 12:50:33 -06007443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7445 ds_layout_ci.pNext = NULL;
7446 ds_layout_ci.bindingCount = 1;
7447 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
7453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007457 alloc_info.descriptorPool = ds_pool;
7458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007460 ASSERT_VK_SUCCESS(err);
7461
Tony Barboureb254902015-07-15 12:50:33 -06007462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7464 pipeline_layout_ci.setLayoutCount = 1;
7465 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007466
7467 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007469 ASSERT_VK_SUCCESS(err);
7470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007471 VkViewport vp = {}; // Just need dummy vp to point to
7472 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007475 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7476 vp_state_ci.scissorCount = 1;
7477 vp_state_ci.pScissors = &sc;
7478 vp_state_ci.viewportCount = 1;
7479 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007481 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7482 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7483 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7484 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7485 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7486 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007487 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 rs_state_ci.lineWidth = 1.0f;
7490
7491 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7492 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7493 vi_ci.pNext = nullptr;
7494 vi_ci.vertexBindingDescriptionCount = 0;
7495 vi_ci.pVertexBindingDescriptions = nullptr;
7496 vi_ci.vertexAttributeDescriptionCount = 0;
7497 vi_ci.pVertexAttributeDescriptions = nullptr;
7498
7499 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7500 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7501 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7502
7503 VkPipelineShaderStageCreateInfo shaderStages[2];
7504 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7505
7506 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7507 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007508 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007509 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007510
Tony Barboureb254902015-07-15 12:50:33 -06007511 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7513 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007514 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7516 gp_ci.layout = pipeline_layout;
7517 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007518 gp_ci.pVertexInputState = &vi_ci;
7519 gp_ci.pInputAssemblyState = &ia_ci;
7520
7521 gp_ci.stageCount = 1;
7522 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007523
7524 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7526 pc_ci.initialDataSize = 0;
7527 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007530 VkPipelineCache pipelineCache;
7531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007533 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007536
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007541}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007542
Tobin Ehlis912df022015-09-17 08:46:18 -06007543/*// TODO : This test should be good, but needs Tess support in compiler to run
7544TEST_F(VkLayerTest, InvalidPatchControlPoints)
7545{
7546 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007548
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007550 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7551primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007552
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 ASSERT_NO_FATAL_FAILURE(InitState());
7554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007555
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007556 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007558 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559
7560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7562 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007563 ds_pool_ci.poolSizeCount = 1;
7564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007565
7566 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007567 err = vkCreateDescriptorPool(m_device->device(),
7568VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007569 ASSERT_VK_SUCCESS(err);
7570
7571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007572 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007574 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7576 dsl_binding.pImmutableSamplers = NULL;
7577
7578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007579 ds_layout_ci.sType =
7580VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007581 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007582 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007583 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007584
7585 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7587&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007588 ASSERT_VK_SUCCESS(err);
7589
7590 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7592VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007596 pipeline_layout_ci.sType =
7597VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007599 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007600 pipeline_layout_ci.pSetLayouts = &ds_layout;
7601
7602 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7604&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkPipelineShaderStageCreateInfo shaderStages[3];
7608 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7609
Karl Schultz6addd812016-02-02 17:17:23 -07007610 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7611this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007612 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007613 VkShaderObj
7614tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7615this);
7616 VkShaderObj
7617te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7618this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007619
Karl Schultz6addd812016-02-02 17:17:23 -07007620 shaderStages[0].sType =
7621VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007622 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007623 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007624 shaderStages[1].sType =
7625VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007626 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007627 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007628 shaderStages[2].sType =
7629VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007630 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007631 shaderStages[2].shader = te.handle();
7632
7633 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007634 iaCI.sType =
7635VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007636 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007637
7638 VkPipelineTessellationStateCreateInfo tsCI = {};
7639 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7640 tsCI.patchControlPoints = 0; // This will cause an error
7641
7642 VkGraphicsPipelineCreateInfo gp_ci = {};
7643 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7644 gp_ci.pNext = NULL;
7645 gp_ci.stageCount = 3;
7646 gp_ci.pStages = shaderStages;
7647 gp_ci.pVertexInputState = NULL;
7648 gp_ci.pInputAssemblyState = &iaCI;
7649 gp_ci.pTessellationState = &tsCI;
7650 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007651 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007652 gp_ci.pMultisampleState = NULL;
7653 gp_ci.pDepthStencilState = NULL;
7654 gp_ci.pColorBlendState = NULL;
7655 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7656 gp_ci.layout = pipeline_layout;
7657 gp_ci.renderPass = renderPass();
7658
7659 VkPipelineCacheCreateInfo pc_ci = {};
7660 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7661 pc_ci.pNext = NULL;
7662 pc_ci.initialSize = 0;
7663 pc_ci.initialData = 0;
7664 pc_ci.maxSize = 0;
7665
7666 VkPipeline pipeline;
7667 VkPipelineCache pipelineCache;
7668
Karl Schultz6addd812016-02-02 17:17:23 -07007669 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7670&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007671 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7673&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007674
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007675 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007676
Chia-I Wuf7458c52015-10-26 21:10:41 +08007677 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007681}
7682*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007683
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007684TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007685 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007687 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689 ASSERT_NO_FATAL_FAILURE(InitState());
7690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7694 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695
7696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7698 ds_pool_ci.maxSets = 1;
7699 ds_pool_ci.poolSizeCount = 1;
7700 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007701
7702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 dsl_binding.binding = 0;
7708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7709 dsl_binding.descriptorCount = 1;
7710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007711
7712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7714 ds_layout_ci.bindingCount = 1;
7715 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007724 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007725 alloc_info.descriptorPool = ds_pool;
7726 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728 ASSERT_VK_SUCCESS(err);
7729
7730 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7732 pipeline_layout_ci.setLayoutCount = 1;
7733 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734
7735 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007737 ASSERT_VK_SUCCESS(err);
7738
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007739 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007740 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007741 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007742 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007743 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007744 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007746 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7747 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7748 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7749 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7750 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7751 rs_state_ci.depthClampEnable = VK_FALSE;
7752 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7753 rs_state_ci.depthBiasEnable = VK_FALSE;
7754
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007755 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7756 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7757 vi_ci.pNext = nullptr;
7758 vi_ci.vertexBindingDescriptionCount = 0;
7759 vi_ci.pVertexBindingDescriptions = nullptr;
7760 vi_ci.vertexAttributeDescriptionCount = 0;
7761 vi_ci.pVertexAttributeDescriptions = nullptr;
7762
7763 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7764 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7765 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7766
7767 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7768 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7769 pipe_ms_state_ci.pNext = NULL;
7770 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7771 pipe_ms_state_ci.sampleShadingEnable = 0;
7772 pipe_ms_state_ci.minSampleShading = 1.0;
7773 pipe_ms_state_ci.pSampleMask = NULL;
7774
Cody Northropeb3a6c12015-10-05 14:44:45 -06007775 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007776 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007779 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007780 shaderStages[0] = vs.GetStageCreateInfo();
7781 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
7783 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007784 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7785 gp_ci.stageCount = 2;
7786 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007787 gp_ci.pVertexInputState = &vi_ci;
7788 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007790 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007791 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007792 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7793 gp_ci.layout = pipeline_layout;
7794 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007795
7796 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007797 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007798
7799 VkPipeline pipeline;
7800 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007802 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007804 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007805 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806
7807 // Check case where multiViewport is disabled and viewport count is not 1
7808 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7811 vp_state_ci.scissorCount = 0;
7812 vp_state_ci.viewportCount = 0;
7813 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7814 m_errorMonitor->VerifyFound();
7815 } else {
7816 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007817 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007818 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007819 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007820
7821 // Check is that viewportcount and scissorcount match
7822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7823 vp_state_ci.scissorCount = 1;
7824 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7825 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7826 m_errorMonitor->VerifyFound();
7827
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007828 // Check case where multiViewport is enabled and viewport count is greater than max
7829 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7832 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7833 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7834 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7835 m_errorMonitor->VerifyFound();
7836 }
7837 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
Chia-I Wuf7458c52015-10-26 21:10:41 +08007839 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007844
7845// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7846// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007848 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007850 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7851
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007853
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007857 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7859 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860
7861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
7867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007869 ASSERT_VK_SUCCESS(err);
7870
7871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007876
7877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7879 ds_layout_ci.bindingCount = 1;
7880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007884 ASSERT_VK_SUCCESS(err);
7885
7886 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007887 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007889 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007890 alloc_info.descriptorPool = ds_pool;
7891 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 ASSERT_VK_SUCCESS(err);
7894
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007895 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7896 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7897 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7898
7899 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7900 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7901 vi_ci.pNext = nullptr;
7902 vi_ci.vertexBindingDescriptionCount = 0;
7903 vi_ci.pVertexBindingDescriptions = nullptr;
7904 vi_ci.vertexAttributeDescriptionCount = 0;
7905 vi_ci.pVertexAttributeDescriptions = nullptr;
7906
7907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7909 pipe_ms_state_ci.pNext = NULL;
7910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7911 pipe_ms_state_ci.sampleShadingEnable = 0;
7912 pipe_ms_state_ci.minSampleShading = 1.0;
7913 pipe_ms_state_ci.pSampleMask = NULL;
7914
Tobin Ehlise68360f2015-10-01 11:15:13 -06007915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7917 pipeline_layout_ci.setLayoutCount = 1;
7918 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
7920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922 ASSERT_VK_SUCCESS(err);
7923
7924 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7925 // Set scissor as dynamic to avoid second error
7926 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7928 dyn_state_ci.dynamicStateCount = 1;
7929 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007930
Cody Northropeb3a6c12015-10-05 14:44:45 -06007931 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007932 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7936 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007937 shaderStages[0] = vs.GetStageCreateInfo();
7938 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007940 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7941 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7942 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7943 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7944 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7945 rs_state_ci.depthClampEnable = VK_FALSE;
7946 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7947 rs_state_ci.depthBiasEnable = VK_FALSE;
7948
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007950 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7951 gp_ci.stageCount = 2;
7952 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007953 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007954 // Not setting VP state w/o dynamic vp state should cause validation error
7955 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007956 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007957 gp_ci.pVertexInputState = &vi_ci;
7958 gp_ci.pInputAssemblyState = &ia_ci;
7959 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007960 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7961 gp_ci.layout = pipeline_layout;
7962 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
7964 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007965 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
7967 VkPipeline pipeline;
7968 VkPipelineCache pipelineCache;
7969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007974 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wuf7458c52015-10-26 21:10:41 +08007976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007981
7982// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7983// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007984TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7985 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007988
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007990
7991 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007992 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007993 return;
7994 }
7995
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007998 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8000 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8004 ds_pool_ci.maxSets = 1;
8005 ds_pool_ci.poolSizeCount = 1;
8006 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007
8008 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008010 ASSERT_VK_SUCCESS(err);
8011
8012 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008013 dsl_binding.binding = 0;
8014 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8015 dsl_binding.descriptorCount = 1;
8016 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008017
8018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8020 ds_layout_ci.bindingCount = 1;
8021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_VK_SUCCESS(err);
8026
8027 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008028 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008030 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008031 alloc_info.descriptorPool = ds_pool;
8032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034 ASSERT_VK_SUCCESS(err);
8035
8036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8038 pipeline_layout_ci.setLayoutCount = 1;
8039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008040
8041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008043 ASSERT_VK_SUCCESS(err);
8044
8045 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008046 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8047 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008048 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008051
8052 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8053 // Set scissor as dynamic to avoid that error
8054 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008055 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8056 dyn_state_ci.dynamicStateCount = 1;
8057 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008059 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8060 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8061 pipe_ms_state_ci.pNext = NULL;
8062 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8063 pipe_ms_state_ci.sampleShadingEnable = 0;
8064 pipe_ms_state_ci.minSampleShading = 1.0;
8065 pipe_ms_state_ci.pSampleMask = NULL;
8066
Cody Northropeb3a6c12015-10-05 14:44:45 -06008067 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8072 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008073 shaderStages[0] = vs.GetStageCreateInfo();
8074 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
Cody Northropf6622dc2015-10-06 10:33:21 -06008076 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8077 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8078 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008079 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008081 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 vi_ci.pVertexAttributeDescriptions = nullptr;
8083
8084 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8085 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8086 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008088 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008089 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008090 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008091 rs_ci.pNext = nullptr;
8092
Mark Youngc89c6312016-03-31 16:03:20 -06008093 VkPipelineColorBlendAttachmentState att = {};
8094 att.blendEnable = VK_FALSE;
8095 att.colorWriteMask = 0xf;
8096
Cody Northropf6622dc2015-10-06 10:33:21 -06008097 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8098 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8099 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008100 cb_ci.attachmentCount = 1;
8101 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008102
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8105 gp_ci.stageCount = 2;
8106 gp_ci.pStages = shaderStages;
8107 gp_ci.pVertexInputState = &vi_ci;
8108 gp_ci.pInputAssemblyState = &ia_ci;
8109 gp_ci.pViewportState = &vp_state_ci;
8110 gp_ci.pRasterizationState = &rs_ci;
8111 gp_ci.pColorBlendState = &cb_ci;
8112 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008113 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008114 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8115 gp_ci.layout = pipeline_layout;
8116 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008117
8118 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120
8121 VkPipeline pipeline;
8122 VkPipelineCache pipelineCache;
8123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008128 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008129
Tobin Ehlisd332f282015-10-02 11:00:56 -06008130 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008131 // First need to successfully create the PSO from above by setting
8132 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07008134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008135 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008136 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008138 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008139 m_commandBuffer->BeginCommandBuffer();
8140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008142 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008143 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008145 Draw(1, 0, 0, 0);
8146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008147 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008148
8149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008153 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008154}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008155
8156// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008157// viewportCount
8158TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8159 VkResult err;
8160
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008162
8163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008164
8165 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008166 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008167 return;
8168 }
8169
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8171
8172 VkDescriptorPoolSize ds_type_count = {};
8173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8174 ds_type_count.descriptorCount = 1;
8175
8176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8178 ds_pool_ci.maxSets = 1;
8179 ds_pool_ci.poolSizeCount = 1;
8180 ds_pool_ci.pPoolSizes = &ds_type_count;
8181
8182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008184 ASSERT_VK_SUCCESS(err);
8185
8186 VkDescriptorSetLayoutBinding dsl_binding = {};
8187 dsl_binding.binding = 0;
8188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8189 dsl_binding.descriptorCount = 1;
8190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8191
8192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8194 ds_layout_ci.bindingCount = 1;
8195 ds_layout_ci.pBindings = &dsl_binding;
8196
8197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ASSERT_VK_SUCCESS(err);
8200
8201 VkDescriptorSet descriptorSet;
8202 VkDescriptorSetAllocateInfo alloc_info = {};
8203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8204 alloc_info.descriptorSetCount = 1;
8205 alloc_info.descriptorPool = ds_pool;
8206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008208 ASSERT_VK_SUCCESS(err);
8209
8210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8212 pipeline_layout_ci.setLayoutCount = 1;
8213 pipeline_layout_ci.pSetLayouts = &ds_layout;
8214
8215 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008217 ASSERT_VK_SUCCESS(err);
8218
8219 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8220 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8221 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008222 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225
8226 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8227 // Set scissor as dynamic to avoid that error
8228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8230 dyn_state_ci.dynamicStateCount = 1;
8231 dyn_state_ci.pDynamicStates = &vp_state;
8232
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008233 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8234 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8235 pipe_ms_state_ci.pNext = NULL;
8236 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8237 pipe_ms_state_ci.sampleShadingEnable = 0;
8238 pipe_ms_state_ci.minSampleShading = 1.0;
8239 pipe_ms_state_ci.pSampleMask = NULL;
8240
Karl Schultz6addd812016-02-02 17:17:23 -07008241 VkPipelineShaderStageCreateInfo shaderStages[2];
8242 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8246 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07008247 shaderStages[0] = vs.GetStageCreateInfo();
8248 shaderStages[1] = fs.GetStageCreateInfo();
8249
8250 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8251 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8252 vi_ci.pNext = nullptr;
8253 vi_ci.vertexBindingDescriptionCount = 0;
8254 vi_ci.pVertexBindingDescriptions = nullptr;
8255 vi_ci.vertexAttributeDescriptionCount = 0;
8256 vi_ci.pVertexAttributeDescriptions = nullptr;
8257
8258 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8259 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8260 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8261
8262 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8263 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008264 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008265 rs_ci.pNext = nullptr;
8266
Mark Youngc89c6312016-03-31 16:03:20 -06008267 VkPipelineColorBlendAttachmentState att = {};
8268 att.blendEnable = VK_FALSE;
8269 att.colorWriteMask = 0xf;
8270
Karl Schultz6addd812016-02-02 17:17:23 -07008271 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8272 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8273 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008274 cb_ci.attachmentCount = 1;
8275 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008276
8277 VkGraphicsPipelineCreateInfo gp_ci = {};
8278 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8279 gp_ci.stageCount = 2;
8280 gp_ci.pStages = shaderStages;
8281 gp_ci.pVertexInputState = &vi_ci;
8282 gp_ci.pInputAssemblyState = &ia_ci;
8283 gp_ci.pViewportState = &vp_state_ci;
8284 gp_ci.pRasterizationState = &rs_ci;
8285 gp_ci.pColorBlendState = &cb_ci;
8286 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008287 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008288 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8289 gp_ci.layout = pipeline_layout;
8290 gp_ci.renderPass = renderPass();
8291
8292 VkPipelineCacheCreateInfo pc_ci = {};
8293 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8294
8295 VkPipeline pipeline;
8296 VkPipelineCache pipelineCache;
8297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008299 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008303
8304 // Now hit second fail case where we set scissor w/ different count than PSO
8305 // First need to successfully create the PSO from above by setting
8306 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8308 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008310 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008314 m_commandBuffer->BeginCommandBuffer();
8315 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008317 VkViewport viewports[1] = {};
8318 viewports[0].width = 8;
8319 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008320 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008321 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008322 Draw(1, 0, 0, 0);
8323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008324 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
Chia-I Wuf7458c52015-10-26 21:10:41 +08008326 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008330 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008331}
8332
Mark Young7394fdd2016-03-31 14:56:43 -06008333TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8334 VkResult err;
8335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008337
8338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8340
8341 VkDescriptorPoolSize ds_type_count = {};
8342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8343 ds_type_count.descriptorCount = 1;
8344
8345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8347 ds_pool_ci.maxSets = 1;
8348 ds_pool_ci.poolSizeCount = 1;
8349 ds_pool_ci.pPoolSizes = &ds_type_count;
8350
8351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008353 ASSERT_VK_SUCCESS(err);
8354
8355 VkDescriptorSetLayoutBinding dsl_binding = {};
8356 dsl_binding.binding = 0;
8357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8358 dsl_binding.descriptorCount = 1;
8359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8360
8361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8363 ds_layout_ci.bindingCount = 1;
8364 ds_layout_ci.pBindings = &dsl_binding;
8365
8366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkDescriptorSet descriptorSet;
8371 VkDescriptorSetAllocateInfo alloc_info = {};
8372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8373 alloc_info.descriptorSetCount = 1;
8374 alloc_info.descriptorPool = ds_pool;
8375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008377 ASSERT_VK_SUCCESS(err);
8378
8379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8381 pipeline_layout_ci.setLayoutCount = 1;
8382 pipeline_layout_ci.pSetLayouts = &ds_layout;
8383
8384 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008386 ASSERT_VK_SUCCESS(err);
8387
8388 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8389 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8390 vp_state_ci.scissorCount = 1;
8391 vp_state_ci.pScissors = NULL;
8392 vp_state_ci.viewportCount = 1;
8393 vp_state_ci.pViewports = NULL;
8394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008396 // Set scissor as dynamic to avoid that error
8397 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8398 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8399 dyn_state_ci.dynamicStateCount = 2;
8400 dyn_state_ci.pDynamicStates = dynamic_states;
8401
8402 VkPipelineShaderStageCreateInfo shaderStages[2];
8403 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8406 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008407 this); // TODO - We shouldn't need a fragment shader
8408 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008409 shaderStages[0] = vs.GetStageCreateInfo();
8410 shaderStages[1] = fs.GetStageCreateInfo();
8411
8412 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8413 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8414 vi_ci.pNext = nullptr;
8415 vi_ci.vertexBindingDescriptionCount = 0;
8416 vi_ci.pVertexBindingDescriptions = nullptr;
8417 vi_ci.vertexAttributeDescriptionCount = 0;
8418 vi_ci.pVertexAttributeDescriptions = nullptr;
8419
8420 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8421 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8422 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8423
8424 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8425 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8426 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008427 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008428
Mark Young47107952016-05-02 15:59:55 -06008429 // Check too low (line width of -1.0f).
8430 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008431
8432 VkPipelineColorBlendAttachmentState att = {};
8433 att.blendEnable = VK_FALSE;
8434 att.colorWriteMask = 0xf;
8435
8436 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8437 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8438 cb_ci.pNext = nullptr;
8439 cb_ci.attachmentCount = 1;
8440 cb_ci.pAttachments = &att;
8441
8442 VkGraphicsPipelineCreateInfo gp_ci = {};
8443 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8444 gp_ci.stageCount = 2;
8445 gp_ci.pStages = shaderStages;
8446 gp_ci.pVertexInputState = &vi_ci;
8447 gp_ci.pInputAssemblyState = &ia_ci;
8448 gp_ci.pViewportState = &vp_state_ci;
8449 gp_ci.pRasterizationState = &rs_ci;
8450 gp_ci.pColorBlendState = &cb_ci;
8451 gp_ci.pDynamicState = &dyn_state_ci;
8452 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8453 gp_ci.layout = pipeline_layout;
8454 gp_ci.renderPass = renderPass();
8455
8456 VkPipelineCacheCreateInfo pc_ci = {};
8457 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8458
8459 VkPipeline pipeline;
8460 VkPipelineCache pipelineCache;
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008463 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008465
8466 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008467 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too high (line width of 65536.0f).
8472 rs_ci.lineWidth = 65536.0f;
8473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008477
8478 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008479 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 dyn_state_ci.dynamicStateCount = 3;
8484
8485 rs_ci.lineWidth = 1.0f;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008490 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008492
8493 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008494 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008495 m_errorMonitor->VerifyFound();
8496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008498
8499 // Check too high with dynamic setting.
8500 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8501 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008502 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8505 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8506 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8507 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008508 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008509}
8510
Karl Schultz6addd812016-02-02 17:17:23 -07008511TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008512 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008514 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008515
8516 ASSERT_NO_FATAL_FAILURE(InitState());
8517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008518
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008520 // Don't care about RenderPass handle b/c error should be flagged before
8521 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008524 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008525}
8526
Karl Schultz6addd812016-02-02 17:17:23 -07008527TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008528 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8530 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008531
8532 ASSERT_NO_FATAL_FAILURE(InitState());
8533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008534
Tony Barbour552f6c02016-12-21 14:34:07 -07008535 m_commandBuffer->BeginCommandBuffer();
8536 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008537 // Just create a dummy Renderpass that's non-NULL so we can get to the
8538 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008541 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008542}
8543
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008544TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008545 TEST_DESCRIPTION(
8546 "Begin a renderPass where clearValueCount is less than"
8547 "the number of renderPass attachments that use loadOp"
8548 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8552
8553 // Create a renderPass with a single attachment that uses loadOp CLEAR
8554 VkAttachmentReference attach = {};
8555 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8556 VkSubpassDescription subpass = {};
8557 subpass.inputAttachmentCount = 1;
8558 subpass.pInputAttachments = &attach;
8559 VkRenderPassCreateInfo rpci = {};
8560 rpci.subpassCount = 1;
8561 rpci.pSubpasses = &subpass;
8562 rpci.attachmentCount = 1;
8563 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008564 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008565 // Set loadOp to CLEAR
8566 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8567 rpci.pAttachments = &attach_desc;
8568 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8569 VkRenderPass rp;
8570 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8571
8572 VkCommandBufferInheritanceInfo hinfo = {};
8573 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8574 hinfo.renderPass = VK_NULL_HANDLE;
8575 hinfo.subpass = 0;
8576 hinfo.framebuffer = VK_NULL_HANDLE;
8577 hinfo.occlusionQueryEnable = VK_FALSE;
8578 hinfo.queryFlags = 0;
8579 hinfo.pipelineStatistics = 0;
8580 VkCommandBufferBeginInfo info = {};
8581 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8582 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8583 info.pInheritanceInfo = &hinfo;
8584
8585 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8586 VkRenderPassBeginInfo rp_begin = {};
8587 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8588 rp_begin.pNext = NULL;
8589 rp_begin.renderPass = renderPass();
8590 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008591 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008592
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008596
8597 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008598
8599 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008600}
8601
Slawomir Cygan0808f392016-11-28 17:53:23 +01008602TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 TEST_DESCRIPTION(
8604 "Begin a renderPass where clearValueCount is greater than"
8605 "the number of renderPass attachments that use loadOp"
8606 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607
8608 ASSERT_NO_FATAL_FAILURE(InitState());
8609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8610
8611 // Create a renderPass with a single attachment that uses loadOp CLEAR
8612 VkAttachmentReference attach = {};
8613 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8614 VkSubpassDescription subpass = {};
8615 subpass.inputAttachmentCount = 1;
8616 subpass.pInputAttachments = &attach;
8617 VkRenderPassCreateInfo rpci = {};
8618 rpci.subpassCount = 1;
8619 rpci.pSubpasses = &subpass;
8620 rpci.attachmentCount = 1;
8621 VkAttachmentDescription attach_desc = {};
8622 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8623 // Set loadOp to CLEAR
8624 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8625 rpci.pAttachments = &attach_desc;
8626 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8627 VkRenderPass rp;
8628 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8629
8630 VkCommandBufferBeginInfo info = {};
8631 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8632 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8633
8634 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8635 VkRenderPassBeginInfo rp_begin = {};
8636 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8637 rp_begin.pNext = NULL;
8638 rp_begin.renderPass = renderPass();
8639 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008640 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8643 " has a clearValueCount of"
8644 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008645
8646 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8647
8648 m_errorMonitor->VerifyFound();
8649
8650 vkDestroyRenderPass(m_device->device(), rp, NULL);
8651}
8652
Cody Northrop3bb4d962016-05-09 16:15:57 -06008653TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008654 TEST_DESCRIPTION("End a command buffer with an active render pass");
8655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8657 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658
8659 ASSERT_NO_FATAL_FAILURE(InitState());
8660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8661
Tony Barbour552f6c02016-12-21 14:34:07 -07008662 m_commandBuffer->BeginCommandBuffer();
8663 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8664 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008665
8666 m_errorMonitor->VerifyFound();
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8669 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008687 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008689 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690}
8691
Karl Schultz6addd812016-02-02 17:17:23 -07008692TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8695 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
8697 ASSERT_NO_FATAL_FAILURE(InitState());
8698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
Tony Barbour552f6c02016-12-21 14:34:07 -07008700 m_commandBuffer->BeginCommandBuffer();
8701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
8703 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vk_testing::Buffer dstBuffer;
8705 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008706
Karl Schultz6addd812016-02-02 17:17:23 -07008707 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008708 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8709 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8710 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713}
8714
Karl Schultz6addd812016-02-02 17:17:23 -07008715TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8718 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008719
8720 ASSERT_NO_FATAL_FAILURE(InitState());
8721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008722
Tony Barbour552f6c02016-12-21 14:34:07 -07008723 m_commandBuffer->BeginCommandBuffer();
8724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Michael Lentine0a369f62016-02-03 16:51:46 -06008726 VkClearColorValue clear_color;
8727 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008728 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8730 const int32_t tex_width = 32;
8731 const int32_t tex_height = 32;
8732 VkImageCreateInfo image_create_info = {};
8733 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8734 image_create_info.pNext = NULL;
8735 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8736 image_create_info.format = tex_format;
8737 image_create_info.extent.width = tex_width;
8738 image_create_info.extent.height = tex_height;
8739 image_create_info.extent.depth = 1;
8740 image_create_info.mipLevels = 1;
8741 image_create_info.arrayLayers = 1;
8742 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8743 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008744 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008753 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008754}
8755
Karl Schultz6addd812016-02-02 17:17:23 -07008756TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8759 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
8761 ASSERT_NO_FATAL_FAILURE(InitState());
8762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Tony Barbourf887b162017-03-09 10:06:46 -07008764 auto depth_format = find_depth_stencil_format(m_device);
8765 if (!depth_format) {
8766 printf(" No Depth + Stencil format found. Skipped.\n");
8767 return;
8768 }
8769
Tony Barbour552f6c02016-12-21 14:34:07 -07008770 m_commandBuffer->BeginCommandBuffer();
8771 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
8773 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008774 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008775 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008777 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008778 image_create_info.extent.width = 64;
8779 image_create_info.extent.height = 64;
8780 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8781 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008783 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008788 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8789 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008791 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792}
8793
Karl Schultz6addd812016-02-02 17:17:23 -07008794TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008795 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008796 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "vkCmdClearAttachments(): This call "
8800 "must be issued inside an active "
8801 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803 ASSERT_NO_FATAL_FAILURE(InitState());
8804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
8806 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008807 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_VK_SUCCESS(err);
8809
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008810 VkClearAttachment color_attachment;
8811 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 color_attachment.clearValue.color.float32[0] = 0;
8813 color_attachment.clearValue.color.float32[1] = 0;
8814 color_attachment.clearValue.color.float32[2] = 0;
8815 color_attachment.clearValue.color.float32[3] = 0;
8816 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008817 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821}
8822
Chris Forbes3b97e932016-09-07 11:29:24 +12008823TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 TEST_DESCRIPTION(
8825 "Test that an error is produced when CmdNextSubpass is "
8826 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8829 "vkCmdNextSubpass(): Attempted to advance "
8830 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008831
8832 ASSERT_NO_FATAL_FAILURE(InitState());
8833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8834
Tony Barbour552f6c02016-12-21 14:34:07 -07008835 m_commandBuffer->BeginCommandBuffer();
8836 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008837
8838 // error here.
8839 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8840 m_errorMonitor->VerifyFound();
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->EndRenderPass();
8843 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008844}
8845
Chris Forbes6d624702016-09-07 13:57:05 +12008846TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008847 TEST_DESCRIPTION(
8848 "Test that an error is produced when CmdEndRenderPass is "
8849 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8852 "vkCmdEndRenderPass(): Called before reaching "
8853 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008854
8855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8857 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008860
8861 VkRenderPass rp;
8862 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8863 ASSERT_VK_SUCCESS(err);
8864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 VkFramebuffer fb;
8868 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8869 ASSERT_VK_SUCCESS(err);
8870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008874
8875 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8876
8877 // Error here.
8878 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8879 m_errorMonitor->VerifyFound();
8880
8881 // Clean up.
8882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8884}
8885
Karl Schultz9e66a292016-04-21 15:57:51 -06008886TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8887 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008892 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008893
8894 VkBufferMemoryBarrier buf_barrier = {};
8895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8896 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8897 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8898 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8899 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8900 buf_barrier.buffer = VK_NULL_HANDLE;
8901 buf_barrier.offset = 0;
8902 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8904 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 m_errorMonitor->VerifyFound();
8907}
8908
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008909TEST_F(VkLayerTest, InvalidBarriers) {
8910 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008913
8914 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008915 auto depth_format = find_depth_stencil_format(m_device);
8916 if (!depth_format) {
8917 printf(" No Depth + Stencil format found. Skipped.\n");
8918 return;
8919 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8921
8922 VkMemoryBarrier mem_barrier = {};
8923 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8924 mem_barrier.pNext = NULL;
8925 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8926 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008927 m_commandBuffer->BeginCommandBuffer();
8928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008929 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008931 &mem_barrier, 0, nullptr, 0, nullptr);
8932 m_errorMonitor->VerifyFound();
8933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008935 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008937 ASSERT_TRUE(image.initialized());
8938 VkImageMemoryBarrier img_barrier = {};
8939 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8940 img_barrier.pNext = NULL;
8941 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8942 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8943 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8944 // New layout can't be UNDEFINED
8945 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8946 img_barrier.image = image.handle();
8947 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8948 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8949 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8950 img_barrier.subresourceRange.baseArrayLayer = 0;
8951 img_barrier.subresourceRange.baseMipLevel = 0;
8952 img_barrier.subresourceRange.layerCount = 1;
8953 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8955 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008956 m_errorMonitor->VerifyFound();
8957 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8960 "Subresource must have the sum of the "
8961 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008962 // baseArrayLayer + layerCount must be <= image's arrayLayers
8963 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8965 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008966 m_errorMonitor->VerifyFound();
8967 img_barrier.subresourceRange.baseArrayLayer = 0;
8968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008970 // baseMipLevel + levelCount must be <= image's mipLevels
8971 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8973 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008974 m_errorMonitor->VerifyFound();
8975 img_barrier.subresourceRange.baseMipLevel = 0;
8976
Mike Weiblen7053aa32017-01-25 15:21:10 -07008977 // levelCount must be non-zero.
8978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8979 img_barrier.subresourceRange.levelCount = 0;
8980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8981 nullptr, 0, nullptr, 1, &img_barrier);
8982 m_errorMonitor->VerifyFound();
8983 img_barrier.subresourceRange.levelCount = 1;
8984
8985 // layerCount must be non-zero.
8986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8987 img_barrier.subresourceRange.layerCount = 0;
8988 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8989 nullptr, 0, nullptr, 1, &img_barrier);
8990 m_errorMonitor->VerifyFound();
8991 img_barrier.subresourceRange.layerCount = 1;
8992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008994 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008995 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8996 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997 VkBufferMemoryBarrier buf_barrier = {};
8998 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8999 buf_barrier.pNext = NULL;
9000 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9001 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9002 buf_barrier.buffer = buffer.handle();
9003 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9004 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9005 buf_barrier.offset = 0;
9006 buf_barrier.size = VK_WHOLE_SIZE;
9007 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9009 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009010 m_errorMonitor->VerifyFound();
9011 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009014 buf_barrier.offset = 257;
9015 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9017 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009018 m_errorMonitor->VerifyFound();
9019 buf_barrier.offset = 0;
9020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022 buf_barrier.size = 257;
9023 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9025 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009026 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009029 m_errorMonitor->SetDesiredFailureMsg(
9030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009031 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009032 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009033 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009034 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009035 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9036 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009037 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009038
9039 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009040 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9042 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009043 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009044
9045 // Having anything other than DEPTH or STENCIL is an error
9046 m_errorMonitor->SetDesiredFailureMsg(
9047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9048 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9049 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9051 nullptr, 0, nullptr, 1, &img_barrier);
9052 m_errorMonitor->VerifyFound();
9053
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009054 // Now test depth-only
9055 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9057 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 VkDepthStencilObj d_image(m_device);
9059 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9060 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009063 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009064
9065 // DEPTH bit must be set
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9067 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009069 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9070 0, nullptr, 0, nullptr, 1, &img_barrier);
9071 m_errorMonitor->VerifyFound();
9072
9073 // No bits other than DEPTH may be set
9074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9075 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9076 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009077 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9078 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009079 m_errorMonitor->VerifyFound();
9080 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009081
9082 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9084 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009085 VkDepthStencilObj s_image(m_device);
9086 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9087 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009089 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009091 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9096 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009097 m_errorMonitor->VerifyFound();
9098 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009099
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009100 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009101 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009103 ASSERT_TRUE(c_image.initialized());
9104 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9105 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9106 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009107
9108 // COLOR bit must be set
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9110 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9113 nullptr, 0, nullptr, 1, &img_barrier);
9114 m_errorMonitor->VerifyFound();
9115
9116 // No bits other than COLOR may be set
9117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9118 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9119 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009120 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9121 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009122 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009123
Mike Weiblene6e01172017-03-07 22:18:40 -07009124 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9125 {
9126 VkImageObj img_color(m_device);
9127 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9128 ASSERT_TRUE(img_color.initialized());
9129
9130 VkImageObj img_ds(m_device);
9131 img_ds.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9132 ASSERT_TRUE(img_ds.initialized());
9133
9134 VkImageObj img_xfer_src(m_device);
9135 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
9136 ASSERT_TRUE(img_xfer_src.initialized());
9137
9138 VkImageObj img_xfer_dst(m_device);
9139 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9140 ASSERT_TRUE(img_xfer_dst.initialized());
9141
9142 VkImageObj img_sampled(m_device);
9143 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
9144 ASSERT_TRUE(img_sampled.initialized());
9145
9146 VkImageObj img_input(m_device);
9147 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9148 ASSERT_TRUE(img_input.initialized());
9149
9150 const struct {
9151 VkImageObj &image_obj;
9152 VkImageLayout bad_layout;
9153 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9154 } bad_buffer_layouts[] = {
9155 // clang-format off
9156 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9157 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9158 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9159 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9160 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9161 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9162 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9163 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9164 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9165 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9166 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9167 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9168 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9169 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9170 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9171 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9172 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9173 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9174 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9175 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9176 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9177 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9178 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9179 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9180 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9181 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9182 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9183 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9184 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9185 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9186 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9187 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9188 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9189 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9190 // clang-format on
9191 };
9192 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9193
9194 for (uint32_t i = 0; i < layout_count; ++i) {
9195 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9196 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9197 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9198 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9199 : VK_IMAGE_ASPECT_COLOR_BIT;
9200
9201 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9202 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9204 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9205 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9206 m_errorMonitor->VerifyFound();
9207
9208 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9209 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9212 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9213 m_errorMonitor->VerifyFound();
9214 }
9215
9216 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9217 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9218 }
9219
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009220 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9221
9222 // Create command pool with incompatible queueflags
9223 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9224 uint32_t queue_family_index = UINT32_MAX;
9225 for (uint32_t i = 0; i < queue_props.size(); i++) {
9226 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9227 queue_family_index = i;
9228 break;
9229 }
9230 }
9231 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009232 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009233 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009234 }
9235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9236
9237 VkCommandPool command_pool;
9238 VkCommandPoolCreateInfo pool_create_info{};
9239 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9240 pool_create_info.queueFamilyIndex = queue_family_index;
9241 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9242 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9243
9244 // Allocate a command buffer
9245 VkCommandBuffer bad_command_buffer;
9246 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9247 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9248 command_buffer_allocate_info.commandPool = command_pool;
9249 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9250 command_buffer_allocate_info.commandBufferCount = 1;
9251 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9252
9253 VkCommandBufferBeginInfo cbbi = {};
9254 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9255 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9256 buf_barrier.offset = 0;
9257 buf_barrier.size = VK_WHOLE_SIZE;
9258 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9259 &buf_barrier, 0, nullptr);
9260 m_errorMonitor->VerifyFound();
9261
9262 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9263 vkEndCommandBuffer(bad_command_buffer);
9264 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009265 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009266 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009267 }
9268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9269 VkEvent event;
9270 VkEventCreateInfo event_create_info{};
9271 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9272 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9273 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9274 nullptr, 0, nullptr);
9275 m_errorMonitor->VerifyFound();
9276
9277 vkEndCommandBuffer(bad_command_buffer);
9278 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009279}
9280
Tony Barbour18ba25c2016-09-29 13:42:40 -06009281TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9282 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9283
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009285 ASSERT_NO_FATAL_FAILURE(InitState());
9286 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -07009287 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
9288 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009289 ASSERT_TRUE(image.initialized());
9290
9291 VkImageMemoryBarrier barrier = {};
9292 VkImageSubresourceRange range;
9293 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9294 barrier.srcAccessMask = 0;
9295 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9296 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9297 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9298 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9299 barrier.image = image.handle();
9300 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9301 range.baseMipLevel = 0;
9302 range.levelCount = 1;
9303 range.baseArrayLayer = 0;
9304 range.layerCount = 1;
9305 barrier.subresourceRange = range;
9306 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9307 cmdbuf.BeginCommandBuffer();
9308 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9309 &barrier);
9310 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9311 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9312 barrier.srcAccessMask = 0;
9313 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9314 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9315 &barrier);
9316
9317 m_errorMonitor->VerifyFound();
9318}
9319
Karl Schultz6addd812016-02-02 17:17:23 -07009320TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009321 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009322 ASSERT_NO_FATAL_FAILURE(InitState());
9323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009324
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009325 uint32_t const indices[] = {0};
9326 VkBufferCreateInfo buf_info = {};
9327 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9328 buf_info.size = 1024;
9329 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9330 buf_info.queueFamilyIndexCount = 1;
9331 buf_info.pQueueFamilyIndices = indices;
9332
9333 VkBuffer buffer;
9334 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9335 ASSERT_VK_SUCCESS(err);
9336
9337 VkMemoryRequirements requirements;
9338 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9339
9340 VkMemoryAllocateInfo alloc_info{};
9341 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9342 alloc_info.pNext = NULL;
9343 alloc_info.memoryTypeIndex = 0;
9344 alloc_info.allocationSize = requirements.size;
9345 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9346 ASSERT_TRUE(pass);
9347
9348 VkDeviceMemory memory;
9349 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9350 ASSERT_VK_SUCCESS(err);
9351
9352 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009353 ASSERT_VK_SUCCESS(err);
9354
Tony Barbour552f6c02016-12-21 14:34:07 -07009355 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009356 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009357
Karl Schultz6addd812016-02-02 17:17:23 -07009358 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9359 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009360 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9362 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009363 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009364
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009365 vkFreeMemory(m_device->device(), memory, NULL);
9366 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009367}
9368
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009369TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9370 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009371 ASSERT_NO_FATAL_FAILURE(InitState());
9372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9373 VkBufferCreateInfo buffCI = {};
9374 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9375 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009376 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009377 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009378 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009379 uint32_t qfi[2];
9380 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009381 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009382
9383 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009384 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009385
9386 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9389 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009390 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009391 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009392
9393 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009394 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9396
9397 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9398 buffCI.queueFamilyIndexCount = 2;
9399 qfi[0] = 1;
9400 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009401 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009402 VkDeviceMemory mem;
9403 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009404 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009405
9406 VkMemoryAllocateInfo alloc_info = {};
9407 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9408 alloc_info.allocationSize = 1024;
9409 bool pass = false;
9410 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9411 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009412 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009413 return;
9414 }
9415 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009416 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009417
9418 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009419 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009420 m_commandBuffer->end();
9421 QueueCommandBuffer(false);
9422 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009423 vkDestroyBuffer(m_device->device(), ib2, NULL);
9424 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009425 }
9426
Tony Barbourdf4c0042016-06-01 15:55:43 -06009427 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009428}
9429
Karl Schultz6addd812016-02-02 17:17:23 -07009430TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009431 TEST_DESCRIPTION(
9432 "Attempt vkCmdExecuteCommands with a primary command buffer"
9433 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009434
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009435 ASSERT_NO_FATAL_FAILURE(InitState());
9436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009437
Chris Forbesf29a84f2016-10-06 18:39:28 +13009438 // An empty primary command buffer
9439 VkCommandBufferObj cb(m_device, m_commandPool);
9440 cb.BeginCommandBuffer();
9441 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009442
Chris Forbesf29a84f2016-10-06 18:39:28 +13009443 m_commandBuffer->BeginCommandBuffer();
9444 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9445 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009446
Chris Forbesf29a84f2016-10-06 18:39:28 +13009447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9448 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009449 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009450
9451 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009452}
9453
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009454TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009455 TEST_DESCRIPTION(
9456 "Attempt to update descriptor sets for images and buffers "
9457 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009458 VkResult err;
9459
9460 ASSERT_NO_FATAL_FAILURE(InitState());
9461 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9462 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9463 ds_type_count[i].type = VkDescriptorType(i);
9464 ds_type_count[i].descriptorCount = 1;
9465 }
9466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9468 ds_pool_ci.pNext = NULL;
9469 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9470 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9471 ds_pool_ci.pPoolSizes = ds_type_count;
9472
9473 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 ASSERT_VK_SUCCESS(err);
9476
9477 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009479 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9480 dsl_binding[i].binding = 0;
9481 dsl_binding[i].descriptorType = VkDescriptorType(i);
9482 dsl_binding[i].descriptorCount = 1;
9483 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9484 dsl_binding[i].pImmutableSamplers = NULL;
9485 }
9486
9487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9489 ds_layout_ci.pNext = NULL;
9490 ds_layout_ci.bindingCount = 1;
9491 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9492 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9493 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 ASSERT_VK_SUCCESS(err);
9496 }
9497 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9498 VkDescriptorSetAllocateInfo alloc_info = {};
9499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9500 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9501 alloc_info.descriptorPool = ds_pool;
9502 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009504 ASSERT_VK_SUCCESS(err);
9505
9506 // Create a buffer & bufferView to be used for invalid updates
9507 VkBufferCreateInfo buff_ci = {};
9508 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009509 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 buff_ci.size = 256;
9511 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009512 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9514 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009515
9516 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9517 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9518 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9519 ASSERT_VK_SUCCESS(err);
9520
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009521 VkMemoryRequirements mem_reqs;
9522 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9523 VkMemoryAllocateInfo mem_alloc_info = {};
9524 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9525 mem_alloc_info.pNext = NULL;
9526 mem_alloc_info.memoryTypeIndex = 0;
9527 mem_alloc_info.allocationSize = mem_reqs.size;
9528 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9529 if (!pass) {
9530 vkDestroyBuffer(m_device->device(), buffer, NULL);
9531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9532 return;
9533 }
9534 VkDeviceMemory mem;
9535 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9536 ASSERT_VK_SUCCESS(err);
9537 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9538 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009539
9540 VkBufferViewCreateInfo buff_view_ci = {};
9541 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9542 buff_view_ci.buffer = buffer;
9543 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9544 buff_view_ci.range = VK_WHOLE_SIZE;
9545 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009547 ASSERT_VK_SUCCESS(err);
9548
Tony Barbour415497c2017-01-24 10:06:09 -07009549 // Now get resources / view for storage_texel_buffer
9550 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9551 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9552 if (!pass) {
9553 vkDestroyBuffer(m_device->device(), buffer, NULL);
9554 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9555 vkFreeMemory(m_device->device(), mem, NULL);
9556 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9558 return;
9559 }
9560 VkDeviceMemory storage_texel_buffer_mem;
9561 VkBufferView storage_texel_buffer_view;
9562 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9563 ASSERT_VK_SUCCESS(err);
9564 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9565 ASSERT_VK_SUCCESS(err);
9566 buff_view_ci.buffer = storage_texel_buffer;
9567 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9568 ASSERT_VK_SUCCESS(err);
9569
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009570 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009571 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009572 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009573 image_ci.format = VK_FORMAT_UNDEFINED;
9574 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9575 VkFormat format = static_cast<VkFormat>(f);
9576 VkFormatProperties fProps = m_device->format_properties(format);
9577 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9578 image_ci.format = format;
9579 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9580 break;
9581 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9582 image_ci.format = format;
9583 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9584 break;
9585 }
9586 }
9587 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9588 return;
9589 }
9590
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009591 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9592 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009593 image_ci.extent.width = 64;
9594 image_ci.extent.height = 64;
9595 image_ci.extent.depth = 1;
9596 image_ci.mipLevels = 1;
9597 image_ci.arrayLayers = 1;
9598 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009599 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009600 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009601 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9602 VkImage image;
9603 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9604 ASSERT_VK_SUCCESS(err);
9605 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009606 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009607
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009608 VkMemoryAllocateInfo mem_alloc = {};
9609 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9610 mem_alloc.pNext = NULL;
9611 mem_alloc.allocationSize = 0;
9612 mem_alloc.memoryTypeIndex = 0;
9613 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9614 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009616 ASSERT_TRUE(pass);
9617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9618 ASSERT_VK_SUCCESS(err);
9619 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9620 ASSERT_VK_SUCCESS(err);
9621 // Now create view for image
9622 VkImageViewCreateInfo image_view_ci = {};
9623 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9624 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009625 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009626 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9627 image_view_ci.subresourceRange.layerCount = 1;
9628 image_view_ci.subresourceRange.baseArrayLayer = 0;
9629 image_view_ci.subresourceRange.levelCount = 1;
9630 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9631 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009633 ASSERT_VK_SUCCESS(err);
9634
9635 VkDescriptorBufferInfo buff_info = {};
9636 buff_info.buffer = buffer;
9637 VkDescriptorImageInfo img_info = {};
9638 img_info.imageView = image_view;
9639 VkWriteDescriptorSet descriptor_write = {};
9640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9641 descriptor_write.dstBinding = 0;
9642 descriptor_write.descriptorCount = 1;
9643 descriptor_write.pTexelBufferView = &buff_view;
9644 descriptor_write.pBufferInfo = &buff_info;
9645 descriptor_write.pImageInfo = &img_info;
9646
9647 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009648 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009649 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9650 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9651 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9652 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9653 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9654 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9655 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9656 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9657 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9658 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9659 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009660 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009661 // Start loop at 1 as SAMPLER desc type has no usage bit error
9662 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009663 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9664 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9665 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9666 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009667 descriptor_write.descriptorType = VkDescriptorType(i);
9668 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009672
9673 m_errorMonitor->VerifyFound();
9674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009675 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9676 descriptor_write.pTexelBufferView = &buff_view;
9677 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009678 }
Tony Barbour415497c2017-01-24 10:06:09 -07009679
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009680 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9681 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009682 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009683 vkDestroyImageView(m_device->device(), image_view, NULL);
9684 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009685 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009686 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009687 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009688 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009689 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9691}
9692
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009693TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009694 TEST_DESCRIPTION(
9695 "Attempt to update buffer descriptor set that has incorrect "
9696 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009697 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009698 "2. range value of 0\n"
9699 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009700 VkResult err;
9701
9702 ASSERT_NO_FATAL_FAILURE(InitState());
9703 VkDescriptorPoolSize ds_type_count = {};
9704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9705 ds_type_count.descriptorCount = 1;
9706
9707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9709 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009710 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009711 ds_pool_ci.maxSets = 1;
9712 ds_pool_ci.poolSizeCount = 1;
9713 ds_pool_ci.pPoolSizes = &ds_type_count;
9714
9715 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009717 ASSERT_VK_SUCCESS(err);
9718
9719 // Create layout with single uniform buffer descriptor
9720 VkDescriptorSetLayoutBinding dsl_binding = {};
9721 dsl_binding.binding = 0;
9722 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9723 dsl_binding.descriptorCount = 1;
9724 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9725 dsl_binding.pImmutableSamplers = NULL;
9726
9727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9729 ds_layout_ci.pNext = NULL;
9730 ds_layout_ci.bindingCount = 1;
9731 ds_layout_ci.pBindings = &dsl_binding;
9732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkDescriptorSet descriptor_set = {};
9737 VkDescriptorSetAllocateInfo alloc_info = {};
9738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9739 alloc_info.descriptorSetCount = 1;
9740 alloc_info.descriptorPool = ds_pool;
9741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 // Create a buffer to be used for invalid updates
9746 VkBufferCreateInfo buff_ci = {};
9747 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9748 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009749 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009750 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9751 VkBuffer buffer;
9752 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9753 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009754
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009755 // Have to bind memory to buffer before descriptor update
9756 VkMemoryAllocateInfo mem_alloc = {};
9757 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9758 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009759 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009760 mem_alloc.memoryTypeIndex = 0;
9761
9762 VkMemoryRequirements mem_reqs;
9763 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009765 if (!pass) {
9766 vkDestroyBuffer(m_device->device(), buffer, NULL);
9767 return;
9768 }
9769
9770 VkDeviceMemory mem;
9771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9772 ASSERT_VK_SUCCESS(err);
9773 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9774 ASSERT_VK_SUCCESS(err);
9775
9776 VkDescriptorBufferInfo buff_info = {};
9777 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009778 // Cause error due to offset out of range
9779 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009780 buff_info.range = VK_WHOLE_SIZE;
9781 VkWriteDescriptorSet descriptor_write = {};
9782 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9783 descriptor_write.dstBinding = 0;
9784 descriptor_write.descriptorCount = 1;
9785 descriptor_write.pTexelBufferView = nullptr;
9786 descriptor_write.pBufferInfo = &buff_info;
9787 descriptor_write.pImageInfo = nullptr;
9788
9789 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9790 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009792
9793 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9794
9795 m_errorMonitor->VerifyFound();
9796 // Now cause error due to range of 0
9797 buff_info.offset = 0;
9798 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009800
9801 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9802
9803 m_errorMonitor->VerifyFound();
9804 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009805 buff_info.offset = 0;
9806 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009808
9809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9810
9811 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009812 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9814 vkDestroyBuffer(m_device->device(), buffer, NULL);
9815 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9817}
9818
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819TEST_F(VkLayerTest, DSBufferLimitErrors) {
9820 TEST_DESCRIPTION(
9821 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9822 "Test cases include:\n"
9823 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9824 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9825 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9826 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9827 VkResult err;
9828
9829 ASSERT_NO_FATAL_FAILURE(InitState());
9830 VkDescriptorPoolSize ds_type_count[2] = {};
9831 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9832 ds_type_count[0].descriptorCount = 1;
9833 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9834 ds_type_count[1].descriptorCount = 1;
9835
9836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9838 ds_pool_ci.pNext = NULL;
9839 ds_pool_ci.maxSets = 1;
9840 ds_pool_ci.poolSizeCount = 2;
9841 ds_pool_ci.pPoolSizes = ds_type_count;
9842
9843 VkDescriptorPool ds_pool;
9844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9845 ASSERT_VK_SUCCESS(err);
9846
9847 // Create layout with single uniform buffer & single storage buffer descriptor
9848 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9849 dsl_binding[0].binding = 0;
9850 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9851 dsl_binding[0].descriptorCount = 1;
9852 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9853 dsl_binding[0].pImmutableSamplers = NULL;
9854 dsl_binding[1].binding = 1;
9855 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9856 dsl_binding[1].descriptorCount = 1;
9857 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding[1].pImmutableSamplers = NULL;
9859
9860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9862 ds_layout_ci.pNext = NULL;
9863 ds_layout_ci.bindingCount = 2;
9864 ds_layout_ci.pBindings = dsl_binding;
9865 VkDescriptorSetLayout ds_layout;
9866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9867 ASSERT_VK_SUCCESS(err);
9868
9869 VkDescriptorSet descriptor_set = {};
9870 VkDescriptorSetAllocateInfo alloc_info = {};
9871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9872 alloc_info.descriptorSetCount = 1;
9873 alloc_info.descriptorPool = ds_pool;
9874 alloc_info.pSetLayouts = &ds_layout;
9875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9876 ASSERT_VK_SUCCESS(err);
9877
9878 // Create a buffer to be used for invalid updates
9879 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9880 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9881 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9882 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9883 VkBufferCreateInfo ub_ci = {};
9884 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9885 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9886 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9887 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9888 VkBuffer uniform_buffer;
9889 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9890 ASSERT_VK_SUCCESS(err);
9891 VkBufferCreateInfo sb_ci = {};
9892 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9893 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9894 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9895 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9896 VkBuffer storage_buffer;
9897 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9898 ASSERT_VK_SUCCESS(err);
9899 // Have to bind memory to buffer before descriptor update
9900 VkMemoryAllocateInfo mem_alloc = {};
9901 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9902 mem_alloc.pNext = NULL;
9903 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9904 mem_alloc.memoryTypeIndex = 0;
9905
Cort Stratton77a0d592017-02-17 13:14:13 -08009906 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9907 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9908 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9909 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9910 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009911 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009913 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009914 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009916 return;
9917 }
9918
9919 VkDeviceMemory mem;
9920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009921 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009922 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9924 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9925 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9927 return;
9928 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009929 ASSERT_VK_SUCCESS(err);
9930 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9931 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009932 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009933 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9934 ASSERT_VK_SUCCESS(err);
9935
9936 VkDescriptorBufferInfo buff_info = {};
9937 buff_info.buffer = uniform_buffer;
9938 buff_info.range = ub_ci.size; // This will exceed limit
9939 VkWriteDescriptorSet descriptor_write = {};
9940 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9941 descriptor_write.dstBinding = 0;
9942 descriptor_write.descriptorCount = 1;
9943 descriptor_write.pTexelBufferView = nullptr;
9944 descriptor_write.pBufferInfo = &buff_info;
9945 descriptor_write.pImageInfo = nullptr;
9946
9947 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9948 descriptor_write.dstSet = descriptor_set;
9949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9950 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9951 m_errorMonitor->VerifyFound();
9952
9953 // Reduce size of range to acceptable limit & cause offset error
9954 buff_info.range = max_ub_range;
9955 buff_info.offset = min_ub_align - 1;
9956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9958 m_errorMonitor->VerifyFound();
9959
9960 // Now break storage updates
9961 buff_info.buffer = storage_buffer;
9962 buff_info.range = sb_ci.size; // This will exceed limit
9963 buff_info.offset = 0; // Reset offset for this update
9964
9965 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9966 descriptor_write.dstBinding = 1;
9967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9969 m_errorMonitor->VerifyFound();
9970
9971 // Reduce size of range to acceptable limit & cause offset error
9972 buff_info.range = max_sb_range;
9973 buff_info.offset = min_sb_align - 1;
9974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9975 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9976 m_errorMonitor->VerifyFound();
9977
9978 vkFreeMemory(m_device->device(), mem, NULL);
9979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9980 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9981 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9983}
9984
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009985TEST_F(VkLayerTest, DSAspectBitsErrors) {
9986 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9987 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009988 TEST_DESCRIPTION(
9989 "Attempt to update descriptor sets for images "
9990 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009991 VkResult err;
9992
9993 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009994 auto depth_format = find_depth_stencil_format(m_device);
9995 if (!depth_format) {
9996 printf(" No Depth + Stencil format found. Skipped.\n");
9997 return;
9998 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009999 VkDescriptorPoolSize ds_type_count = {};
10000 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10001 ds_type_count.descriptorCount = 1;
10002
10003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10005 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010006 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010007 ds_pool_ci.maxSets = 5;
10008 ds_pool_ci.poolSizeCount = 1;
10009 ds_pool_ci.pPoolSizes = &ds_type_count;
10010
10011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010013 ASSERT_VK_SUCCESS(err);
10014
10015 VkDescriptorSetLayoutBinding dsl_binding = {};
10016 dsl_binding.binding = 0;
10017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10018 dsl_binding.descriptorCount = 1;
10019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10020 dsl_binding.pImmutableSamplers = NULL;
10021
10022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10024 ds_layout_ci.pNext = NULL;
10025 ds_layout_ci.bindingCount = 1;
10026 ds_layout_ci.pBindings = &dsl_binding;
10027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010029 ASSERT_VK_SUCCESS(err);
10030
10031 VkDescriptorSet descriptor_set = {};
10032 VkDescriptorSetAllocateInfo alloc_info = {};
10033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10034 alloc_info.descriptorSetCount = 1;
10035 alloc_info.descriptorPool = ds_pool;
10036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010038 ASSERT_VK_SUCCESS(err);
10039
10040 // Create an image to be used for invalid updates
10041 VkImageCreateInfo image_ci = {};
10042 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10043 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010044 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010045 image_ci.extent.width = 64;
10046 image_ci.extent.height = 64;
10047 image_ci.extent.depth = 1;
10048 image_ci.mipLevels = 1;
10049 image_ci.arrayLayers = 1;
10050 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010051 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010052 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10053 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10054 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10055 VkImage image;
10056 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10057 ASSERT_VK_SUCCESS(err);
10058 // Bind memory to image
10059 VkMemoryRequirements mem_reqs;
10060 VkDeviceMemory image_mem;
10061 bool pass;
10062 VkMemoryAllocateInfo mem_alloc = {};
10063 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10064 mem_alloc.pNext = NULL;
10065 mem_alloc.allocationSize = 0;
10066 mem_alloc.memoryTypeIndex = 0;
10067 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10068 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010070 ASSERT_TRUE(pass);
10071 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10072 ASSERT_VK_SUCCESS(err);
10073 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10074 ASSERT_VK_SUCCESS(err);
10075 // Now create view for image
10076 VkImageViewCreateInfo image_view_ci = {};
10077 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10078 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010079 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010080 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10081 image_view_ci.subresourceRange.layerCount = 1;
10082 image_view_ci.subresourceRange.baseArrayLayer = 0;
10083 image_view_ci.subresourceRange.levelCount = 1;
10084 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010086
10087 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010089 ASSERT_VK_SUCCESS(err);
10090
10091 VkDescriptorImageInfo img_info = {};
10092 img_info.imageView = image_view;
10093 VkWriteDescriptorSet descriptor_write = {};
10094 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10095 descriptor_write.dstBinding = 0;
10096 descriptor_write.descriptorCount = 1;
10097 descriptor_write.pTexelBufferView = NULL;
10098 descriptor_write.pBufferInfo = NULL;
10099 descriptor_write.pImageInfo = &img_info;
10100 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10101 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010102 const char *error_msg =
10103 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10104 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010106
10107 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10108
10109 m_errorMonitor->VerifyFound();
10110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10111 vkDestroyImage(m_device->device(), image, NULL);
10112 vkFreeMemory(m_device->device(), image_mem, NULL);
10113 vkDestroyImageView(m_device->device(), image_view, NULL);
10114 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10116}
10117
Karl Schultz6addd812016-02-02 17:17:23 -070010118TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010119 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010120 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10123 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10124 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010125
Tobin Ehlis3b780662015-05-28 12:11:26 -060010126 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010127 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10130 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010131
10132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10134 ds_pool_ci.pNext = NULL;
10135 ds_pool_ci.maxSets = 1;
10136 ds_pool_ci.poolSizeCount = 1;
10137 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010138
Tobin Ehlis3b780662015-05-28 12:11:26 -060010139 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010141 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010142 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010143 dsl_binding.binding = 0;
10144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10145 dsl_binding.descriptorCount = 1;
10146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10147 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148
Tony Barboureb254902015-07-15 12:50:33 -060010149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10151 ds_layout_ci.pNext = NULL;
10152 ds_layout_ci.bindingCount = 1;
10153 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010154
Tobin Ehlis3b780662015-05-28 12:11:26 -060010155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010157 ASSERT_VK_SUCCESS(err);
10158
10159 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010160 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010162 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010163 alloc_info.descriptorPool = ds_pool;
10164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010168 VkSamplerCreateInfo sampler_ci = {};
10169 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10170 sampler_ci.pNext = NULL;
10171 sampler_ci.magFilter = VK_FILTER_NEAREST;
10172 sampler_ci.minFilter = VK_FILTER_NEAREST;
10173 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10174 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10175 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10176 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10177 sampler_ci.mipLodBias = 1.0;
10178 sampler_ci.anisotropyEnable = VK_FALSE;
10179 sampler_ci.maxAnisotropy = 1;
10180 sampler_ci.compareEnable = VK_FALSE;
10181 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10182 sampler_ci.minLod = 1.0;
10183 sampler_ci.maxLod = 1.0;
10184 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10185 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10186 VkSampler sampler;
10187 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10188 ASSERT_VK_SUCCESS(err);
10189
10190 VkDescriptorImageInfo info = {};
10191 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010192
10193 VkWriteDescriptorSet descriptor_write;
10194 memset(&descriptor_write, 0, sizeof(descriptor_write));
10195 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010196 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010197 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010198 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010199 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010200 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010201
10202 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010204 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010205
Chia-I Wuf7458c52015-10-26 21:10:41 +080010206 vkDestroySampler(m_device->device(), sampler, NULL);
10207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010209}
10210
Karl Schultz6addd812016-02-02 17:17:23 -070010211TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010212 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010213 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010214
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010216
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010218 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010219 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010220 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10221 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010222
10223 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010224 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10225 ds_pool_ci.pNext = NULL;
10226 ds_pool_ci.maxSets = 1;
10227 ds_pool_ci.poolSizeCount = 1;
10228 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010229
Tobin Ehlis3b780662015-05-28 12:11:26 -060010230 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010232 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010233
Tony Barboureb254902015-07-15 12:50:33 -060010234 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010235 dsl_binding.binding = 0;
10236 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10237 dsl_binding.descriptorCount = 1;
10238 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10239 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010240
10241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10243 ds_layout_ci.pNext = NULL;
10244 ds_layout_ci.bindingCount = 1;
10245 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010246
Tobin Ehlis3b780662015-05-28 12:11:26 -060010247 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010249 ASSERT_VK_SUCCESS(err);
10250
10251 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010252 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010253 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010254 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010255 alloc_info.descriptorPool = ds_pool;
10256 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010258 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010259
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010260 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10261
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010262 // Correctly update descriptor to avoid "NOT_UPDATED" error
10263 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010264 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010265 buff_info.offset = 0;
10266 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010267
10268 VkWriteDescriptorSet descriptor_write;
10269 memset(&descriptor_write, 0, sizeof(descriptor_write));
10270 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010271 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010273 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010274 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10275 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010276
10277 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010280
Chia-I Wuf7458c52015-10-26 21:10:41 +080010281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010283}
10284
Karl Schultz6addd812016-02-02 17:17:23 -070010285TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010286 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010287 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010288
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010290
Tobin Ehlis3b780662015-05-28 12:11:26 -060010291 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010292 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010293 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10295 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010296
10297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10299 ds_pool_ci.pNext = NULL;
10300 ds_pool_ci.maxSets = 1;
10301 ds_pool_ci.poolSizeCount = 1;
10302 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010303
Tobin Ehlis3b780662015-05-28 12:11:26 -060010304 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010305 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010306 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010307
Tony Barboureb254902015-07-15 12:50:33 -060010308 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010309 dsl_binding.binding = 0;
10310 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10311 dsl_binding.descriptorCount = 1;
10312 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10313 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010314
10315 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010316 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10317 ds_layout_ci.pNext = NULL;
10318 ds_layout_ci.bindingCount = 1;
10319 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010320 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010322 ASSERT_VK_SUCCESS(err);
10323
10324 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010325 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010327 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010328 alloc_info.descriptorPool = ds_pool;
10329 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010332
Tony Barboureb254902015-07-15 12:50:33 -060010333 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010334 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10335 sampler_ci.pNext = NULL;
10336 sampler_ci.magFilter = VK_FILTER_NEAREST;
10337 sampler_ci.minFilter = VK_FILTER_NEAREST;
10338 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10339 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10340 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10341 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10342 sampler_ci.mipLodBias = 1.0;
10343 sampler_ci.anisotropyEnable = VK_FALSE;
10344 sampler_ci.maxAnisotropy = 1;
10345 sampler_ci.compareEnable = VK_FALSE;
10346 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10347 sampler_ci.minLod = 1.0;
10348 sampler_ci.maxLod = 1.0;
10349 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10350 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010351
Tobin Ehlis3b780662015-05-28 12:11:26 -060010352 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010353 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010355
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010356 VkDescriptorImageInfo info = {};
10357 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010358
10359 VkWriteDescriptorSet descriptor_write;
10360 memset(&descriptor_write, 0, sizeof(descriptor_write));
10361 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010362 descriptor_write.dstSet = descriptorSet;
10363 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010364 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010365 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010366 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010367 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010368
10369 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10370
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010371 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010372
Chia-I Wuf7458c52015-10-26 21:10:41 +080010373 vkDestroySampler(m_device->device(), sampler, NULL);
10374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010376}
10377
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010378TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10379 // Create layout w/ empty binding and attempt to update it
10380 VkResult err;
10381
10382 ASSERT_NO_FATAL_FAILURE(InitState());
10383
10384 VkDescriptorPoolSize ds_type_count = {};
10385 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10386 ds_type_count.descriptorCount = 1;
10387
10388 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10389 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10390 ds_pool_ci.pNext = NULL;
10391 ds_pool_ci.maxSets = 1;
10392 ds_pool_ci.poolSizeCount = 1;
10393 ds_pool_ci.pPoolSizes = &ds_type_count;
10394
10395 VkDescriptorPool ds_pool;
10396 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10397 ASSERT_VK_SUCCESS(err);
10398
10399 VkDescriptorSetLayoutBinding dsl_binding = {};
10400 dsl_binding.binding = 0;
10401 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10402 dsl_binding.descriptorCount = 0;
10403 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10404 dsl_binding.pImmutableSamplers = NULL;
10405
10406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10408 ds_layout_ci.pNext = NULL;
10409 ds_layout_ci.bindingCount = 1;
10410 ds_layout_ci.pBindings = &dsl_binding;
10411 VkDescriptorSetLayout ds_layout;
10412 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10413 ASSERT_VK_SUCCESS(err);
10414
10415 VkDescriptorSet descriptor_set;
10416 VkDescriptorSetAllocateInfo alloc_info = {};
10417 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10418 alloc_info.descriptorSetCount = 1;
10419 alloc_info.descriptorPool = ds_pool;
10420 alloc_info.pSetLayouts = &ds_layout;
10421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10422 ASSERT_VK_SUCCESS(err);
10423
10424 VkSamplerCreateInfo sampler_ci = {};
10425 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10426 sampler_ci.magFilter = VK_FILTER_NEAREST;
10427 sampler_ci.minFilter = VK_FILTER_NEAREST;
10428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10432 sampler_ci.mipLodBias = 1.0;
10433 sampler_ci.maxAnisotropy = 1;
10434 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10435 sampler_ci.minLod = 1.0;
10436 sampler_ci.maxLod = 1.0;
10437 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10438
10439 VkSampler sampler;
10440 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10441 ASSERT_VK_SUCCESS(err);
10442
10443 VkDescriptorImageInfo info = {};
10444 info.sampler = sampler;
10445
10446 VkWriteDescriptorSet descriptor_write;
10447 memset(&descriptor_write, 0, sizeof(descriptor_write));
10448 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10449 descriptor_write.dstSet = descriptor_set;
10450 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010451 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010452 // This is the wrong type, but empty binding error will be flagged first
10453 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10454 descriptor_write.pImageInfo = &info;
10455
10456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10458 m_errorMonitor->VerifyFound();
10459
10460 vkDestroySampler(m_device->device(), sampler, NULL);
10461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10463}
10464
Karl Schultz6addd812016-02-02 17:17:23 -070010465TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10466 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10467 // types
10468 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010471
Tobin Ehlis3b780662015-05-28 12:11:26 -060010472 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010473
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010474 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010475 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10476 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010477
10478 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010479 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10480 ds_pool_ci.pNext = NULL;
10481 ds_pool_ci.maxSets = 1;
10482 ds_pool_ci.poolSizeCount = 1;
10483 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010484
Tobin Ehlis3b780662015-05-28 12:11:26 -060010485 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010487 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010489 dsl_binding.binding = 0;
10490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10491 dsl_binding.descriptorCount = 1;
10492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010494
Tony Barboureb254902015-07-15 12:50:33 -060010495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10497 ds_layout_ci.pNext = NULL;
10498 ds_layout_ci.bindingCount = 1;
10499 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010500
Tobin Ehlis3b780662015-05-28 12:11:26 -060010501 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010503 ASSERT_VK_SUCCESS(err);
10504
10505 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010508 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010509 alloc_info.descriptorPool = ds_pool;
10510 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010512 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010513
Tony Barboureb254902015-07-15 12:50:33 -060010514 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10516 sampler_ci.pNext = NULL;
10517 sampler_ci.magFilter = VK_FILTER_NEAREST;
10518 sampler_ci.minFilter = VK_FILTER_NEAREST;
10519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10523 sampler_ci.mipLodBias = 1.0;
10524 sampler_ci.anisotropyEnable = VK_FALSE;
10525 sampler_ci.maxAnisotropy = 1;
10526 sampler_ci.compareEnable = VK_FALSE;
10527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10528 sampler_ci.minLod = 1.0;
10529 sampler_ci.maxLod = 1.0;
10530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010532 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010533 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010534 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010535
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010536 VkDescriptorImageInfo info = {};
10537 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010538
10539 VkWriteDescriptorSet descriptor_write;
10540 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010542 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010543 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010544 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010546 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010547
10548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010550 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010551
Chia-I Wuf7458c52015-10-26 21:10:41 +080010552 vkDestroySampler(m_device->device(), sampler, NULL);
10553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010555}
10556
Karl Schultz6addd812016-02-02 17:17:23 -070010557TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010559 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010560
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010562
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010563 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010564 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10565 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010566 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010567 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10568 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010569
10570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10572 ds_pool_ci.pNext = NULL;
10573 ds_pool_ci.maxSets = 1;
10574 ds_pool_ci.poolSizeCount = 1;
10575 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010576
10577 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579 ASSERT_VK_SUCCESS(err);
10580
10581 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010582 dsl_binding.binding = 0;
10583 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10584 dsl_binding.descriptorCount = 1;
10585 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10586 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010587
10588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10590 ds_layout_ci.pNext = NULL;
10591 ds_layout_ci.bindingCount = 1;
10592 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010595 ASSERT_VK_SUCCESS(err);
10596
10597 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010598 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010600 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010601 alloc_info.descriptorPool = ds_pool;
10602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604 ASSERT_VK_SUCCESS(err);
10605
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010606 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010607
10608 VkDescriptorImageInfo descriptor_info;
10609 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10610 descriptor_info.sampler = sampler;
10611
10612 VkWriteDescriptorSet descriptor_write;
10613 memset(&descriptor_write, 0, sizeof(descriptor_write));
10614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010615 descriptor_write.dstSet = descriptorSet;
10616 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010617 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10619 descriptor_write.pImageInfo = &descriptor_info;
10620
10621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010623 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010624
Chia-I Wuf7458c52015-10-26 21:10:41 +080010625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010627}
10628
Karl Schultz6addd812016-02-02 17:17:23 -070010629TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10630 // Create a single combined Image/Sampler descriptor and send it an invalid
10631 // imageView
10632 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010633
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010635
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010636 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010637 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010638 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10639 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010640
10641 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010642 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10643 ds_pool_ci.pNext = NULL;
10644 ds_pool_ci.maxSets = 1;
10645 ds_pool_ci.poolSizeCount = 1;
10646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010647
10648 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010650 ASSERT_VK_SUCCESS(err);
10651
10652 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010653 dsl_binding.binding = 0;
10654 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10655 dsl_binding.descriptorCount = 1;
10656 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10657 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010658
10659 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010660 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10661 ds_layout_ci.pNext = NULL;
10662 ds_layout_ci.bindingCount = 1;
10663 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010664 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010666 ASSERT_VK_SUCCESS(err);
10667
10668 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010669 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010670 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010671 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010672 alloc_info.descriptorPool = ds_pool;
10673 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010675 ASSERT_VK_SUCCESS(err);
10676
10677 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010678 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10679 sampler_ci.pNext = NULL;
10680 sampler_ci.magFilter = VK_FILTER_NEAREST;
10681 sampler_ci.minFilter = VK_FILTER_NEAREST;
10682 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10683 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10684 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10685 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10686 sampler_ci.mipLodBias = 1.0;
10687 sampler_ci.anisotropyEnable = VK_FALSE;
10688 sampler_ci.maxAnisotropy = 1;
10689 sampler_ci.compareEnable = VK_FALSE;
10690 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10691 sampler_ci.minLod = 1.0;
10692 sampler_ci.maxLod = 1.0;
10693 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10694 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010695
10696 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010697 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010698 ASSERT_VK_SUCCESS(err);
10699
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010701
10702 VkDescriptorImageInfo descriptor_info;
10703 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10704 descriptor_info.sampler = sampler;
10705 descriptor_info.imageView = view;
10706
10707 VkWriteDescriptorSet descriptor_write;
10708 memset(&descriptor_write, 0, sizeof(descriptor_write));
10709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010710 descriptor_write.dstSet = descriptorSet;
10711 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010712 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10714 descriptor_write.pImageInfo = &descriptor_info;
10715
10716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010718 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010719
Chia-I Wuf7458c52015-10-26 21:10:41 +080010720 vkDestroySampler(m_device->device(), sampler, NULL);
10721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010723}
10724
Karl Schultz6addd812016-02-02 17:17:23 -070010725TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10726 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10727 // into the other
10728 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010729
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10731 " binding #1 with type "
10732 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10733 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010734
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010736 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010737 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010738 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10739 ds_type_count[0].descriptorCount = 1;
10740 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10741 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010742
10743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10745 ds_pool_ci.pNext = NULL;
10746 ds_pool_ci.maxSets = 1;
10747 ds_pool_ci.poolSizeCount = 2;
10748 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010749
10750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010752 ASSERT_VK_SUCCESS(err);
10753 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010754 dsl_binding[0].binding = 0;
10755 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10756 dsl_binding[0].descriptorCount = 1;
10757 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10758 dsl_binding[0].pImmutableSamplers = NULL;
10759 dsl_binding[1].binding = 1;
10760 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10761 dsl_binding[1].descriptorCount = 1;
10762 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10763 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010764
10765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10767 ds_layout_ci.pNext = NULL;
10768 ds_layout_ci.bindingCount = 2;
10769 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010770
10771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010773 ASSERT_VK_SUCCESS(err);
10774
10775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010778 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010779 alloc_info.descriptorPool = ds_pool;
10780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010782 ASSERT_VK_SUCCESS(err);
10783
10784 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010785 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10786 sampler_ci.pNext = NULL;
10787 sampler_ci.magFilter = VK_FILTER_NEAREST;
10788 sampler_ci.minFilter = VK_FILTER_NEAREST;
10789 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10790 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10791 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10792 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10793 sampler_ci.mipLodBias = 1.0;
10794 sampler_ci.anisotropyEnable = VK_FALSE;
10795 sampler_ci.maxAnisotropy = 1;
10796 sampler_ci.compareEnable = VK_FALSE;
10797 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10798 sampler_ci.minLod = 1.0;
10799 sampler_ci.maxLod = 1.0;
10800 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10801 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010802
10803 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010804 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010805 ASSERT_VK_SUCCESS(err);
10806
10807 VkDescriptorImageInfo info = {};
10808 info.sampler = sampler;
10809
10810 VkWriteDescriptorSet descriptor_write;
10811 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010814 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010815 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10817 descriptor_write.pImageInfo = &info;
10818 // This write update should succeed
10819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10820 // Now perform a copy update that fails due to type mismatch
10821 VkCopyDescriptorSet copy_ds_update;
10822 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10823 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10824 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010825 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010826 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010827 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10828 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010829 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010831 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010832 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060010834 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10835 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10836 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010837 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010838 copy_ds_update.dstSet = descriptorSet;
10839 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010840 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010841 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10842
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010843 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010844
Tobin Ehlis04356f92015-10-27 16:35:27 -060010845 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10847 " binding#1 with offset index of 1 plus "
10848 "update array offset of 0 and update of "
10849 "5 descriptors oversteps total number "
10850 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010851
Tobin Ehlis04356f92015-10-27 16:35:27 -060010852 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10853 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10854 copy_ds_update.srcSet = descriptorSet;
10855 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010856 copy_ds_update.dstSet = descriptorSet;
10857 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010858 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010859 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010861 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010862
Chia-I Wuf7458c52015-10-26 21:10:41 +080010863 vkDestroySampler(m_device->device(), sampler, NULL);
10864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10865 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010866}
10867
Karl Schultz6addd812016-02-02 17:17:23 -070010868TEST_F(VkLayerTest, NumSamplesMismatch) {
10869 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10870 // sampleCount
10871 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010874
Tobin Ehlis3b780662015-05-28 12:11:26 -060010875 ASSERT_NO_FATAL_FAILURE(InitState());
10876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010877 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010878 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010879 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010880
10881 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010882 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10883 ds_pool_ci.pNext = NULL;
10884 ds_pool_ci.maxSets = 1;
10885 ds_pool_ci.poolSizeCount = 1;
10886 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010887
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010890 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010891
Tony Barboureb254902015-07-15 12:50:33 -060010892 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010893 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010894 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010895 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010896 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10897 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010898
Tony Barboureb254902015-07-15 12:50:33 -060010899 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10900 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10901 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010902 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010903 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010904
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010907 ASSERT_VK_SUCCESS(err);
10908
10909 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010910 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010911 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010912 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010913 alloc_info.descriptorPool = ds_pool;
10914 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010916 ASSERT_VK_SUCCESS(err);
10917
Tony Barboureb254902015-07-15 12:50:33 -060010918 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010920 pipe_ms_state_ci.pNext = NULL;
10921 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10922 pipe_ms_state_ci.sampleShadingEnable = 0;
10923 pipe_ms_state_ci.minSampleShading = 1.0;
10924 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010925
Tony Barboureb254902015-07-15 12:50:33 -060010926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10928 pipeline_layout_ci.pNext = NULL;
10929 pipeline_layout_ci.setLayoutCount = 1;
10930 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010931
10932 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010934 ASSERT_VK_SUCCESS(err);
10935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010937 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010939 VkPipelineObj pipe(m_device);
10940 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010941 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010942 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010943 pipe.SetMSAA(&pipe_ms_state_ci);
10944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010945
Tony Barbour552f6c02016-12-21 14:34:07 -070010946 m_commandBuffer->BeginCommandBuffer();
10947 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010948 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010949
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10952 VkRect2D scissor = {{0, 0}, {16, 16}};
10953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10954
Mark Young29927482016-05-04 14:38:51 -060010955 // Render triangle (the error should trigger on the attempt to draw).
10956 Draw(3, 1, 0, 0);
10957
10958 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010959 m_commandBuffer->EndRenderPass();
10960 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010961
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010962 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010963
Chia-I Wuf7458c52015-10-26 21:10:41 +080010964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010967}
Mark Young29927482016-05-04 14:38:51 -060010968
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010969TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010970 TEST_DESCRIPTION(
10971 "Hit RenderPass incompatible cases. "
10972 "Initial case is drawing with an active renderpass that's "
10973 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010974 VkResult err;
10975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
10979 VkDescriptorSetLayoutBinding dsl_binding = {};
10980 dsl_binding.binding = 0;
10981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10982 dsl_binding.descriptorCount = 1;
10983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10984 dsl_binding.pImmutableSamplers = NULL;
10985
10986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10988 ds_layout_ci.pNext = NULL;
10989 ds_layout_ci.bindingCount = 1;
10990 ds_layout_ci.pBindings = &dsl_binding;
10991
10992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010994 ASSERT_VK_SUCCESS(err);
10995
10996 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10997 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10998 pipeline_layout_ci.pNext = NULL;
10999 pipeline_layout_ci.setLayoutCount = 1;
11000 pipeline_layout_ci.pSetLayouts = &ds_layout;
11001
11002 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011004 ASSERT_VK_SUCCESS(err);
11005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011007 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011009 // Create a renderpass that will be incompatible with default renderpass
11010 VkAttachmentReference attach = {};
11011 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11012 VkAttachmentReference color_att = {};
11013 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11014 VkSubpassDescription subpass = {};
11015 subpass.inputAttachmentCount = 1;
11016 subpass.pInputAttachments = &attach;
11017 subpass.colorAttachmentCount = 1;
11018 subpass.pColorAttachments = &color_att;
11019 VkRenderPassCreateInfo rpci = {};
11020 rpci.subpassCount = 1;
11021 rpci.pSubpasses = &subpass;
11022 rpci.attachmentCount = 1;
11023 VkAttachmentDescription attach_desc = {};
11024 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011025 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11026 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011027 rpci.pAttachments = &attach_desc;
11028 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11029 VkRenderPass rp;
11030 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11031 VkPipelineObj pipe(m_device);
11032 pipe.AddShader(&vs);
11033 pipe.AddShader(&fs);
11034 pipe.AddColorAttachment();
11035 VkViewport view_port = {};
11036 m_viewports.push_back(view_port);
11037 pipe.SetViewport(m_viewports);
11038 VkRect2D rect = {};
11039 m_scissors.push_back(rect);
11040 pipe.SetScissor(m_scissors);
11041 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11042
11043 VkCommandBufferInheritanceInfo cbii = {};
11044 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11045 cbii.renderPass = rp;
11046 cbii.subpass = 0;
11047 VkCommandBufferBeginInfo cbbi = {};
11048 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11049 cbbi.pInheritanceInfo = &cbii;
11050 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11051 VkRenderPassBeginInfo rpbi = {};
11052 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11053 rpbi.framebuffer = m_framebuffer;
11054 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11056 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011059 // Render triangle (the error should trigger on the attempt to draw).
11060 Draw(3, 1, 0, 0);
11061
11062 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011063 m_commandBuffer->EndRenderPass();
11064 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011065
11066 m_errorMonitor->VerifyFound();
11067
11068 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11070 vkDestroyRenderPass(m_device->device(), rp, NULL);
11071}
11072
Mark Youngc89c6312016-03-31 16:03:20 -060011073TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11074 // Create Pipeline where the number of blend attachments doesn't match the
11075 // number of color attachments. In this case, we don't add any color
11076 // blend attachments even though we have a color attachment.
11077 VkResult err;
11078
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011080
11081 ASSERT_NO_FATAL_FAILURE(InitState());
11082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11083 VkDescriptorPoolSize ds_type_count = {};
11084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11085 ds_type_count.descriptorCount = 1;
11086
11087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11089 ds_pool_ci.pNext = NULL;
11090 ds_pool_ci.maxSets = 1;
11091 ds_pool_ci.poolSizeCount = 1;
11092 ds_pool_ci.pPoolSizes = &ds_type_count;
11093
11094 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011096 ASSERT_VK_SUCCESS(err);
11097
11098 VkDescriptorSetLayoutBinding dsl_binding = {};
11099 dsl_binding.binding = 0;
11100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11101 dsl_binding.descriptorCount = 1;
11102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11103 dsl_binding.pImmutableSamplers = NULL;
11104
11105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11107 ds_layout_ci.pNext = NULL;
11108 ds_layout_ci.bindingCount = 1;
11109 ds_layout_ci.pBindings = &dsl_binding;
11110
11111 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011113 ASSERT_VK_SUCCESS(err);
11114
11115 VkDescriptorSet descriptorSet;
11116 VkDescriptorSetAllocateInfo alloc_info = {};
11117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11118 alloc_info.descriptorSetCount = 1;
11119 alloc_info.descriptorPool = ds_pool;
11120 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011122 ASSERT_VK_SUCCESS(err);
11123
11124 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011126 pipe_ms_state_ci.pNext = NULL;
11127 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11128 pipe_ms_state_ci.sampleShadingEnable = 0;
11129 pipe_ms_state_ci.minSampleShading = 1.0;
11130 pipe_ms_state_ci.pSampleMask = NULL;
11131
11132 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11133 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11134 pipeline_layout_ci.pNext = NULL;
11135 pipeline_layout_ci.setLayoutCount = 1;
11136 pipeline_layout_ci.pSetLayouts = &ds_layout;
11137
11138 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011140 ASSERT_VK_SUCCESS(err);
11141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011142 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011143 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011145 VkPipelineObj pipe(m_device);
11146 pipe.AddShader(&vs);
11147 pipe.AddShader(&fs);
11148 pipe.SetMSAA(&pipe_ms_state_ci);
11149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011150 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011151
11152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11155}
Mark Young29927482016-05-04 14:38:51 -060011156
Mark Muellerd4914412016-06-13 17:52:06 -060011157TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011158 TEST_DESCRIPTION(
11159 "Points to a wrong colorAttachment index in a VkClearAttachment "
11160 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011161 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011163
11164 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11165 m_errorMonitor->VerifyFound();
11166}
11167
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011168TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011169 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11170 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011171
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011172 ASSERT_NO_FATAL_FAILURE(InitState());
11173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011174
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11177 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011178
11179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11181 ds_pool_ci.pNext = NULL;
11182 ds_pool_ci.maxSets = 1;
11183 ds_pool_ci.poolSizeCount = 1;
11184 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011185
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011186 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011188 ASSERT_VK_SUCCESS(err);
11189
Tony Barboureb254902015-07-15 12:50:33 -060011190 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011191 dsl_binding.binding = 0;
11192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11193 dsl_binding.descriptorCount = 1;
11194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11195 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011196
Tony Barboureb254902015-07-15 12:50:33 -060011197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11199 ds_layout_ci.pNext = NULL;
11200 ds_layout_ci.bindingCount = 1;
11201 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011202
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011203 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011205 ASSERT_VK_SUCCESS(err);
11206
11207 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011208 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011210 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011211 alloc_info.descriptorPool = ds_pool;
11212 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011214 ASSERT_VK_SUCCESS(err);
11215
Tony Barboureb254902015-07-15 12:50:33 -060011216 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011218 pipe_ms_state_ci.pNext = NULL;
11219 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11220 pipe_ms_state_ci.sampleShadingEnable = 0;
11221 pipe_ms_state_ci.minSampleShading = 1.0;
11222 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011223
Tony Barboureb254902015-07-15 12:50:33 -060011224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11226 pipeline_layout_ci.pNext = NULL;
11227 pipeline_layout_ci.setLayoutCount = 1;
11228 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011229
11230 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011232 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011235 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011236 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011238
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011239 VkPipelineObj pipe(m_device);
11240 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011241 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011242 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011243 pipe.SetMSAA(&pipe_ms_state_ci);
11244 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011245
Tony Barbour552f6c02016-12-21 14:34:07 -070011246 m_commandBuffer->BeginCommandBuffer();
11247 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011248
Karl Schultz6addd812016-02-02 17:17:23 -070011249 // Main thing we care about for this test is that the VkImage obj we're
11250 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011251 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011252 VkClearAttachment color_attachment;
11253 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11254 color_attachment.clearValue.color.float32[0] = 1.0;
11255 color_attachment.clearValue.color.float32[1] = 1.0;
11256 color_attachment.clearValue.color.float32[2] = 1.0;
11257 color_attachment.clearValue.color.float32[3] = 1.0;
11258 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011260
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011261 // Call for full-sized FB Color attachment prior to issuing a Draw
11262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011263 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011265 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011266
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011267 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11268 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11270 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11271 m_errorMonitor->VerifyFound();
11272
11273 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11274 clear_rect.layerCount = 2;
11275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11276 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011278
Chia-I Wuf7458c52015-10-26 21:10:41 +080011279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011282}
11283
Karl Schultz6addd812016-02-02 17:17:23 -070011284TEST_F(VkLayerTest, VtxBufferBadIndex) {
11285 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11288 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011289
Tobin Ehlis502480b2015-06-24 15:53:07 -060011290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011291 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011293
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011295 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11296 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011297
11298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11300 ds_pool_ci.pNext = NULL;
11301 ds_pool_ci.maxSets = 1;
11302 ds_pool_ci.poolSizeCount = 1;
11303 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011304
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011305 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011307 ASSERT_VK_SUCCESS(err);
11308
Tony Barboureb254902015-07-15 12:50:33 -060011309 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 dsl_binding.binding = 0;
11311 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11312 dsl_binding.descriptorCount = 1;
11313 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11314 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011315
Tony Barboureb254902015-07-15 12:50:33 -060011316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11318 ds_layout_ci.pNext = NULL;
11319 ds_layout_ci.bindingCount = 1;
11320 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011321
Tobin Ehlis502480b2015-06-24 15:53:07 -060011322 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011324 ASSERT_VK_SUCCESS(err);
11325
11326 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011327 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011328 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011329 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011330 alloc_info.descriptorPool = ds_pool;
11331 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011333 ASSERT_VK_SUCCESS(err);
11334
Tony Barboureb254902015-07-15 12:50:33 -060011335 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011337 pipe_ms_state_ci.pNext = NULL;
11338 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11339 pipe_ms_state_ci.sampleShadingEnable = 0;
11340 pipe_ms_state_ci.minSampleShading = 1.0;
11341 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011342
Tony Barboureb254902015-07-15 12:50:33 -060011343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11345 pipeline_layout_ci.pNext = NULL;
11346 pipeline_layout_ci.setLayoutCount = 1;
11347 pipeline_layout_ci.pSetLayouts = &ds_layout;
11348 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011351 ASSERT_VK_SUCCESS(err);
11352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011353 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011354 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011355 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011356 VkPipelineObj pipe(m_device);
11357 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011358 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011359 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011360 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011361 pipe.SetViewport(m_viewports);
11362 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011363 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011364
Tony Barbour552f6c02016-12-21 14:34:07 -070011365 m_commandBuffer->BeginCommandBuffer();
11366 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011368 // Don't care about actual data, just need to get to draw to flag error
11369 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011371 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011372 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011374 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011375
Chia-I Wuf7458c52015-10-26 21:10:41 +080011376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11377 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11378 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011379}
Mark Muellerdfe37552016-07-07 14:47:42 -060011380
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011382 TEST_DESCRIPTION(
11383 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11384 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011385 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011386
Mark Mueller880fce52016-08-17 15:23:23 -060011387 // The following test fails with recent NVidia drivers.
11388 // By the time core_validation is reached, the NVidia
11389 // driver has sanitized the invalid condition and core_validation
11390 // is not introduced to the failure condition. This is not the case
11391 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 // uint32_t count = static_cast<uint32_t>(~0);
11393 // VkPhysicalDevice physical_device;
11394 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11395 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011396
Mark Mueller2ee294f2016-08-04 12:59:48 -060011397 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011398 VkDeviceQueueCreateInfo queue_create_info = {};
11399 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11400 queue_create_info.queueCount = 1;
11401 queue_create_info.pQueuePriorities = &queue_priority;
11402 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11403
11404 VkPhysicalDeviceFeatures features = m_device->phy().features();
11405 VkDevice testDevice;
11406 VkDeviceCreateInfo device_create_info = {};
11407 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11408 device_create_info.queueCreateInfoCount = 1;
11409 device_create_info.pQueueCreateInfos = &queue_create_info;
11410 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011411
11412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11413 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex ");
11414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011415 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11416 m_errorMonitor->VerifyFound();
11417
11418 queue_create_info.queueFamilyIndex = 1;
11419
11420 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11421 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11422 for (unsigned i = 0; i < feature_count; i++) {
11423 if (VK_FALSE == feature_array[i]) {
11424 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011425 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11427 "While calling vkCreateDevice(), requesting feature #");
11428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
11429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11430 "You requested features that are unavailable on this device. You should first "
11431 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011432 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11433 m_errorMonitor->VerifyFound();
11434 break;
11435 }
11436 }
11437}
11438
Tobin Ehlis16edf082016-11-21 12:33:49 -070011439TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11440 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11441
11442 ASSERT_NO_FATAL_FAILURE(InitState());
11443
11444 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11445 std::vector<VkDeviceQueueCreateInfo> queue_info;
11446 queue_info.reserve(queue_props.size());
11447 std::vector<std::vector<float>> queue_priorities;
11448 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11449 VkDeviceQueueCreateInfo qi{};
11450 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11451 qi.queueFamilyIndex = i;
11452 qi.queueCount = queue_props[i].queueCount;
11453 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11454 qi.pQueuePriorities = queue_priorities[i].data();
11455 queue_info.push_back(qi);
11456 }
11457
11458 std::vector<const char *> device_extension_names;
11459
11460 VkDevice local_device;
11461 VkDeviceCreateInfo device_create_info = {};
11462 auto features = m_device->phy().features();
11463 // Intentionally disable pipeline stats
11464 features.pipelineStatisticsQuery = VK_FALSE;
11465 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11466 device_create_info.pNext = NULL;
11467 device_create_info.queueCreateInfoCount = queue_info.size();
11468 device_create_info.pQueueCreateInfos = queue_info.data();
11469 device_create_info.enabledLayerCount = 0;
11470 device_create_info.ppEnabledLayerNames = NULL;
11471 device_create_info.pEnabledFeatures = &features;
11472 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11473 ASSERT_VK_SUCCESS(err);
11474
11475 VkQueryPoolCreateInfo qpci{};
11476 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11477 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11478 qpci.queryCount = 1;
11479 VkQueryPool query_pool;
11480
11481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11482 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11483 m_errorMonitor->VerifyFound();
11484
11485 vkDestroyDevice(local_device, nullptr);
11486}
11487
Mark Mueller2ee294f2016-08-04 12:59:48 -060011488TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011489 TEST_DESCRIPTION(
11490 "Use an invalid queue index in a vkCmdWaitEvents call."
11491 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011492
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011493 const char *invalid_queue_index =
11494 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11495 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11496 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011498 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011501
11502 ASSERT_NO_FATAL_FAILURE(InitState());
11503
11504 VkEvent event;
11505 VkEventCreateInfo event_create_info{};
11506 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11507 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11508
Mark Mueller2ee294f2016-08-04 12:59:48 -060011509 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011510 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011511
Tony Barbour552f6c02016-12-21 14:34:07 -070011512 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011513
11514 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011515 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 -060011516 ASSERT_TRUE(image.initialized());
11517 VkImageMemoryBarrier img_barrier = {};
11518 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11519 img_barrier.pNext = NULL;
11520 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11521 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11522 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11523 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11524 img_barrier.image = image.handle();
11525 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011526
11527 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11528 // that layer validation catches the case when it is not.
11529 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011530 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11531 img_barrier.subresourceRange.baseArrayLayer = 0;
11532 img_barrier.subresourceRange.baseMipLevel = 0;
11533 img_barrier.subresourceRange.layerCount = 1;
11534 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11536 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011537 m_errorMonitor->VerifyFound();
11538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011540
11541 VkQueryPool query_pool;
11542 VkQueryPoolCreateInfo query_pool_create_info = {};
11543 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11544 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11545 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011546 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011548 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011549 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11550
11551 vkEndCommandBuffer(m_commandBuffer->handle());
11552 m_errorMonitor->VerifyFound();
11553
11554 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11555 vkDestroyEvent(m_device->device(), event, nullptr);
11556}
11557
Mark Muellerdfe37552016-07-07 14:47:42 -060011558TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011559 TEST_DESCRIPTION(
11560 "Submit a command buffer using deleted vertex buffer, "
11561 "delete a buffer twice, use an invalid offset for each "
11562 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011563
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011564 const char *deleted_buffer_in_command_buffer =
11565 "Cannot submit cmd buffer "
11566 "using deleted buffer ";
11567 const char *invalid_offset_message =
11568 "vkBindBufferMemory(): "
11569 "memoryOffset is 0x";
11570 const char *invalid_storage_buffer_offset_message =
11571 "vkBindBufferMemory(): "
11572 "storage memoryOffset "
11573 "is 0x";
11574 const char *invalid_texel_buffer_offset_message =
11575 "vkBindBufferMemory(): "
11576 "texel memoryOffset "
11577 "is 0x";
11578 const char *invalid_uniform_buffer_offset_message =
11579 "vkBindBufferMemory(): "
11580 "uniform memoryOffset "
11581 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011582
11583 ASSERT_NO_FATAL_FAILURE(InitState());
11584 ASSERT_NO_FATAL_FAILURE(InitViewport());
11585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11586
11587 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011589 pipe_ms_state_ci.pNext = NULL;
11590 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11591 pipe_ms_state_ci.sampleShadingEnable = 0;
11592 pipe_ms_state_ci.minSampleShading = 1.0;
11593 pipe_ms_state_ci.pSampleMask = nullptr;
11594
11595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11597 VkPipelineLayout pipeline_layout;
11598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011600 ASSERT_VK_SUCCESS(err);
11601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011602 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11603 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011604 VkPipelineObj pipe(m_device);
11605 pipe.AddShader(&vs);
11606 pipe.AddShader(&fs);
11607 pipe.AddColorAttachment();
11608 pipe.SetMSAA(&pipe_ms_state_ci);
11609 pipe.SetViewport(m_viewports);
11610 pipe.SetScissor(m_scissors);
11611 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11612
Tony Barbour552f6c02016-12-21 14:34:07 -070011613 m_commandBuffer->BeginCommandBuffer();
11614 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011616
11617 {
11618 // Create and bind a vertex buffer in a reduced scope, which will cause
11619 // it to be deleted upon leaving this scope
11620 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011621 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011622 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11623 draw_verticies.AddVertexInputToPipe(pipe);
11624 }
11625
11626 Draw(1, 0, 0, 0);
11627
Tony Barbour552f6c02016-12-21 14:34:07 -070011628 m_commandBuffer->EndRenderPass();
11629 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011632 QueueCommandBuffer(false);
11633 m_errorMonitor->VerifyFound();
11634
11635 {
11636 // Create and bind a vertex buffer in a reduced scope, and delete it
11637 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011638 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011640 buffer_test.TestDoubleDestroy();
11641 }
11642 m_errorMonitor->VerifyFound();
11643
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011644 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011646 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011648 m_errorMonitor->SetUnexpectedError(
11649 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11650 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011651 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11652 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011653 m_errorMonitor->VerifyFound();
11654 }
11655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11657 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011658 // Create and bind a memory buffer with an invalid offset again,
11659 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011661 m_errorMonitor->SetUnexpectedError(
11662 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11663 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011664 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11665 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011666 m_errorMonitor->VerifyFound();
11667 }
11668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011669 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011670 // Create and bind a memory buffer with an invalid offset again, but
11671 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011673 m_errorMonitor->SetUnexpectedError(
11674 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11675 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011676 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11677 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011678 m_errorMonitor->VerifyFound();
11679 }
11680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011681 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011682 // Create and bind a memory buffer with an invalid offset again, but
11683 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011685 m_errorMonitor->SetUnexpectedError(
11686 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11687 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11689 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011690 m_errorMonitor->VerifyFound();
11691 }
11692
11693 {
11694 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011696 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11697 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11699 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011700 m_errorMonitor->VerifyFound();
11701 }
11702
11703 {
11704 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11707 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011708 }
11709 m_errorMonitor->VerifyFound();
11710
11711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11712}
11713
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011714// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11715TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011716 TEST_DESCRIPTION(
11717 "Hit all possible validation checks associated with the "
11718 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11719 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011720 // 3 in ValidateCmdBufImageLayouts
11721 // * -1 Attempt to submit cmd buf w/ deleted image
11722 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11723 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011724
11725 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011726 auto depth_format = find_depth_stencil_format(m_device);
11727 if (!depth_format) {
11728 printf(" No Depth + Stencil format found. Skipped.\n");
11729 return;
11730 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011731 // Create src & dst images to use for copy operations
11732 VkImage src_image;
11733 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011734 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011735
11736 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11737 const int32_t tex_width = 32;
11738 const int32_t tex_height = 32;
11739
11740 VkImageCreateInfo image_create_info = {};
11741 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11742 image_create_info.pNext = NULL;
11743 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11744 image_create_info.format = tex_format;
11745 image_create_info.extent.width = tex_width;
11746 image_create_info.extent.height = tex_height;
11747 image_create_info.extent.depth = 1;
11748 image_create_info.mipLevels = 1;
11749 image_create_info.arrayLayers = 4;
11750 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11751 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11752 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011753 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011754 image_create_info.flags = 0;
11755
11756 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11757 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011758 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11760 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011761 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11762 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11764 ASSERT_VK_SUCCESS(err);
11765
11766 // Allocate memory
11767 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011768 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011769 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011770 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11771 mem_alloc.pNext = NULL;
11772 mem_alloc.allocationSize = 0;
11773 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011774
11775 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011776 mem_alloc.allocationSize = img_mem_reqs.size;
11777 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011778 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011779 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011780 ASSERT_VK_SUCCESS(err);
11781
11782 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011783 mem_alloc.allocationSize = img_mem_reqs.size;
11784 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011785 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011786 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011787 ASSERT_VK_SUCCESS(err);
11788
11789 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011790 mem_alloc.allocationSize = img_mem_reqs.size;
11791 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011792 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011793 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011794 ASSERT_VK_SUCCESS(err);
11795
11796 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11797 ASSERT_VK_SUCCESS(err);
11798 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11799 ASSERT_VK_SUCCESS(err);
11800 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11801 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011802
Tony Barbour552f6c02016-12-21 14:34:07 -070011803 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011804 VkImageCopy copy_region;
11805 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11806 copy_region.srcSubresource.mipLevel = 0;
11807 copy_region.srcSubresource.baseArrayLayer = 0;
11808 copy_region.srcSubresource.layerCount = 1;
11809 copy_region.srcOffset.x = 0;
11810 copy_region.srcOffset.y = 0;
11811 copy_region.srcOffset.z = 0;
11812 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11813 copy_region.dstSubresource.mipLevel = 0;
11814 copy_region.dstSubresource.baseArrayLayer = 0;
11815 copy_region.dstSubresource.layerCount = 1;
11816 copy_region.dstOffset.x = 0;
11817 copy_region.dstOffset.y = 0;
11818 copy_region.dstOffset.z = 0;
11819 copy_region.extent.width = 1;
11820 copy_region.extent.height = 1;
11821 copy_region.extent.depth = 1;
11822
11823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11824 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011825 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011826 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 -060011827 m_errorMonitor->VerifyFound();
11828 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11830 "Cannot copy from an image whose source layout is "
11831 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11832 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011833 m_errorMonitor->SetUnexpectedError(
11834 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011835 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 -060011836 m_errorMonitor->VerifyFound();
11837 // Final src error is due to bad layout type
11838 m_errorMonitor->SetDesiredFailureMsg(
11839 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11840 "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 -070011841 m_errorMonitor->SetUnexpectedError(
11842 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11843 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011844 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 -060011845 m_errorMonitor->VerifyFound();
11846 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11848 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011849 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011850 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 -060011851 m_errorMonitor->VerifyFound();
11852 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11854 "Cannot copy from an image whose dest layout is "
11855 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11856 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011857 m_errorMonitor->SetUnexpectedError(
11858 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011859 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 -060011860 m_errorMonitor->VerifyFound();
11861 m_errorMonitor->SetDesiredFailureMsg(
11862 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11863 "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 -070011864 m_errorMonitor->SetUnexpectedError(
11865 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11866 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011867 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 -060011868 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011869
Cort3b021012016-12-07 12:00:57 -080011870 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11871 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11872 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11873 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11874 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11875 transfer_dst_image_barrier[0].srcAccessMask = 0;
11876 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11877 transfer_dst_image_barrier[0].image = dst_image;
11878 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11879 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11880 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11881 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11882 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11883 transfer_dst_image_barrier[0].image = depth_image;
11884 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11885 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11886 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11887
11888 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011889 VkClearColorValue color_clear_value = {};
11890 VkImageSubresourceRange clear_range;
11891 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11892 clear_range.baseMipLevel = 0;
11893 clear_range.baseArrayLayer = 0;
11894 clear_range.layerCount = 1;
11895 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011896
Cort3b021012016-12-07 12:00:57 -080011897 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11898 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011901 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011902 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011903 // Fail due to provided layout not matching actual current layout for color clear.
11904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011905 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011906 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011907
Cort530cf382016-12-08 09:59:47 -080011908 VkClearDepthStencilValue depth_clear_value = {};
11909 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011910
11911 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11912 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011915 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011916 m_errorMonitor->VerifyFound();
11917 // Fail due to provided layout not matching actual current layout for depth clear.
11918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011919 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011920 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011921
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011922 // Now cause error due to bad image layout transition in PipelineBarrier
11923 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011924 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011925 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011926 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011927 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011928 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11929 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011930 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11932 "You cannot transition the layout of aspect 1 from "
11933 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11934 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070011935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011936 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11937 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011938 m_errorMonitor->VerifyFound();
11939
11940 // Finally some layout errors at RenderPass create time
11941 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11942 VkAttachmentReference attach = {};
11943 // perf warning for GENERAL layout w/ non-DS input attachment
11944 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11945 VkSubpassDescription subpass = {};
11946 subpass.inputAttachmentCount = 1;
11947 subpass.pInputAttachments = &attach;
11948 VkRenderPassCreateInfo rpci = {};
11949 rpci.subpassCount = 1;
11950 rpci.pSubpasses = &subpass;
11951 rpci.attachmentCount = 1;
11952 VkAttachmentDescription attach_desc = {};
11953 attach_desc.format = VK_FORMAT_UNDEFINED;
11954 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011955 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011956 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11958 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011959 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11960 m_errorMonitor->VerifyFound();
11961 // error w/ non-general layout
11962 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11963
11964 m_errorMonitor->SetDesiredFailureMsg(
11965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11966 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11967 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11968 m_errorMonitor->VerifyFound();
11969 subpass.inputAttachmentCount = 0;
11970 subpass.colorAttachmentCount = 1;
11971 subpass.pColorAttachments = &attach;
11972 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11973 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11975 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011976 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11977 m_errorMonitor->VerifyFound();
11978 // error w/ non-color opt or GENERAL layout for color attachment
11979 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11980 m_errorMonitor->SetDesiredFailureMsg(
11981 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11982 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11983 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11984 m_errorMonitor->VerifyFound();
11985 subpass.colorAttachmentCount = 0;
11986 subpass.pDepthStencilAttachment = &attach;
11987 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11988 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11990 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011991 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11992 m_errorMonitor->VerifyFound();
11993 // error w/ non-ds opt or GENERAL layout for color attachment
11994 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11996 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11997 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011998 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11999 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012000 // For this error we need a valid renderpass so create default one
12001 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12002 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012003 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012004 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12005 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12006 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12007 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12008 // Can't do a CLEAR load on READ_ONLY initialLayout
12009 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12010 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12011 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12013 " with invalid first layout "
12014 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12015 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012016 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12017 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012018
Cort3b021012016-12-07 12:00:57 -080012019 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12020 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12021 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012022 vkDestroyImage(m_device->device(), src_image, NULL);
12023 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012024 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012025}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012026
Tobin Ehlise0936662016-10-11 08:10:51 -060012027TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12028 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12029 VkResult err;
12030
12031 ASSERT_NO_FATAL_FAILURE(InitState());
12032
12033 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12034 VkImageTiling tiling;
12035 VkFormatProperties format_properties;
12036 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12037 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12038 tiling = VK_IMAGE_TILING_LINEAR;
12039 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12040 tiling = VK_IMAGE_TILING_OPTIMAL;
12041 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012042 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012043 return;
12044 }
12045
12046 VkDescriptorPoolSize ds_type = {};
12047 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12048 ds_type.descriptorCount = 1;
12049
12050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12052 ds_pool_ci.maxSets = 1;
12053 ds_pool_ci.poolSizeCount = 1;
12054 ds_pool_ci.pPoolSizes = &ds_type;
12055 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12056
12057 VkDescriptorPool ds_pool;
12058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12059 ASSERT_VK_SUCCESS(err);
12060
12061 VkDescriptorSetLayoutBinding dsl_binding = {};
12062 dsl_binding.binding = 0;
12063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12064 dsl_binding.descriptorCount = 1;
12065 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12066 dsl_binding.pImmutableSamplers = NULL;
12067
12068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12070 ds_layout_ci.pNext = NULL;
12071 ds_layout_ci.bindingCount = 1;
12072 ds_layout_ci.pBindings = &dsl_binding;
12073
12074 VkDescriptorSetLayout ds_layout;
12075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12076 ASSERT_VK_SUCCESS(err);
12077
12078 VkDescriptorSetAllocateInfo alloc_info = {};
12079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12080 alloc_info.descriptorSetCount = 1;
12081 alloc_info.descriptorPool = ds_pool;
12082 alloc_info.pSetLayouts = &ds_layout;
12083 VkDescriptorSet descriptor_set;
12084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12085 ASSERT_VK_SUCCESS(err);
12086
12087 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12088 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12089 pipeline_layout_ci.pNext = NULL;
12090 pipeline_layout_ci.setLayoutCount = 1;
12091 pipeline_layout_ci.pSetLayouts = &ds_layout;
12092 VkPipelineLayout pipeline_layout;
12093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12094 ASSERT_VK_SUCCESS(err);
12095
12096 VkImageObj image(m_device);
12097 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12098 ASSERT_TRUE(image.initialized());
12099 VkImageView view = image.targetView(tex_format);
12100
12101 VkDescriptorImageInfo image_info = {};
12102 image_info.imageView = view;
12103 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12104
12105 VkWriteDescriptorSet descriptor_write = {};
12106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12107 descriptor_write.dstSet = descriptor_set;
12108 descriptor_write.dstBinding = 0;
12109 descriptor_write.descriptorCount = 1;
12110 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12111 descriptor_write.pImageInfo = &image_info;
12112
12113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12114 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12115 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12117 m_errorMonitor->VerifyFound();
12118
12119 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12121 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12123}
12124
Mark Mueller93b938f2016-08-18 10:27:40 -060012125TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012126 TEST_DESCRIPTION(
12127 "Use vkCmdExecuteCommands with invalid state "
12128 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012129
12130 ASSERT_NO_FATAL_FAILURE(InitState());
12131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12132
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012133 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012134 const char *simultaneous_use_message2 =
12135 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12136 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012137
12138 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012140 command_buffer_allocate_info.commandPool = m_commandPool;
12141 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12142 command_buffer_allocate_info.commandBufferCount = 1;
12143
12144 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012146 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12147 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012149 command_buffer_inheritance_info.renderPass = m_renderPass;
12150 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012151
Mark Mueller93b938f2016-08-18 10:27:40 -060012152 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 command_buffer_begin_info.flags =
12154 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012155 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12156
12157 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12158 vkEndCommandBuffer(secondary_command_buffer);
12159
Mark Mueller93b938f2016-08-18 10:27:40 -060012160 VkSubmitInfo submit_info = {};
12161 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12162 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012164
Mark Mueller4042b652016-09-05 22:52:21 -060012165 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012166 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12168 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012169 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012170 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012171 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12172 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012173
Dave Houltonfbf52152017-01-06 12:55:29 -070012174 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012175 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012176 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012177
Mark Mueller4042b652016-09-05 22:52:21 -060012178 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012179 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12180 m_errorMonitor->SetUnexpectedError(
12181 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12182 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012183 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12187 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012188 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012189 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12190 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012191
12192 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012193
12194 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012195}
12196
Tony Barbour626994c2017-02-08 15:29:37 -070012197TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12198 TEST_DESCRIPTION(
12199 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12200 "errors");
12201 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12202 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12203 ASSERT_NO_FATAL_FAILURE(InitState());
12204
12205 VkCommandBuffer cmd_bufs[2];
12206 VkCommandBufferAllocateInfo alloc_info;
12207 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12208 alloc_info.pNext = NULL;
12209 alloc_info.commandBufferCount = 2;
12210 alloc_info.commandPool = m_commandPool;
12211 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12212 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12213
12214 VkCommandBufferBeginInfo cb_binfo;
12215 cb_binfo.pNext = NULL;
12216 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12217 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12218 cb_binfo.flags = 0;
12219 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12220 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12221 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12222 vkEndCommandBuffer(cmd_bufs[0]);
12223 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12224
12225 VkSubmitInfo submit_info = {};
12226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12227 submit_info.commandBufferCount = 2;
12228 submit_info.pCommandBuffers = duplicates;
12229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12230 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12231 m_errorMonitor->VerifyFound();
12232 vkQueueWaitIdle(m_device->m_queue);
12233
12234 // Set one time use and now look for one time submit
12235 duplicates[0] = duplicates[1] = cmd_bufs[1];
12236 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12237 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12238 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12239 vkEndCommandBuffer(cmd_bufs[1]);
12240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12241 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12242 m_errorMonitor->VerifyFound();
12243 vkQueueWaitIdle(m_device->m_queue);
12244}
12245
Tobin Ehlisb093da82017-01-19 12:05:27 -070012246TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012247 TEST_DESCRIPTION(
12248 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12249 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012250
12251 ASSERT_NO_FATAL_FAILURE(InitState());
12252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12253
12254 std::vector<const char *> device_extension_names;
12255 auto features = m_device->phy().features();
12256 // Make sure gs & ts are disabled
12257 features.geometryShader = false;
12258 features.tessellationShader = false;
12259 // The sacrificial device object
12260 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12261
12262 VkCommandPoolCreateInfo pool_create_info{};
12263 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12264 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12265
12266 VkCommandPool command_pool;
12267 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12268
12269 VkCommandBufferAllocateInfo cmd = {};
12270 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12271 cmd.pNext = NULL;
12272 cmd.commandPool = command_pool;
12273 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12274 cmd.commandBufferCount = 1;
12275
12276 VkCommandBuffer cmd_buffer;
12277 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12278 ASSERT_VK_SUCCESS(err);
12279
12280 VkEvent event;
12281 VkEventCreateInfo evci = {};
12282 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12283 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12284 ASSERT_VK_SUCCESS(result);
12285
12286 VkCommandBufferBeginInfo cbbi = {};
12287 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12288 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12290 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12291 m_errorMonitor->VerifyFound();
12292
12293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12294 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12295 m_errorMonitor->VerifyFound();
12296
12297 vkDestroyEvent(test_device.handle(), event, NULL);
12298 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12299}
12300
Mark Mueller917f6bc2016-08-30 10:57:19 -060012301TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012302 TEST_DESCRIPTION(
12303 "Use vkCmdExecuteCommands with invalid state "
12304 "in primary and secondary command buffers. "
12305 "Delete objects that are inuse. Call VkQueueSubmit "
12306 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012307
12308 ASSERT_NO_FATAL_FAILURE(InitState());
12309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12310
Tony Barbour552f6c02016-12-21 14:34:07 -070012311 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312
12313 VkEvent event;
12314 VkEventCreateInfo event_create_info = {};
12315 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12316 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012318
Tony Barbour552f6c02016-12-21 14:34:07 -070012319 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012320 vkDestroyEvent(m_device->device(), event, nullptr);
12321
12322 VkSubmitInfo submit_info = {};
12323 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12324 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012327 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12328 m_errorMonitor->VerifyFound();
12329
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012330 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012331 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12332
12333 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12334
Mark Mueller917f6bc2016-08-30 10:57:19 -060012335 VkSemaphoreCreateInfo semaphore_create_info = {};
12336 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12337 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012338 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012339 VkFenceCreateInfo fence_create_info = {};
12340 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12341 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012343
12344 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012345 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012346 descriptor_pool_type_count.descriptorCount = 1;
12347
12348 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12349 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12350 descriptor_pool_create_info.maxSets = 1;
12351 descriptor_pool_create_info.poolSizeCount = 1;
12352 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012354
12355 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012356 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012357
12358 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012359 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012360 descriptorset_layout_binding.descriptorCount = 1;
12361 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12362
12363 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012365 descriptorset_layout_create_info.bindingCount = 1;
12366 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12367
12368 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 ASSERT_VK_SUCCESS(
12370 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012371
12372 VkDescriptorSet descriptorset;
12373 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012374 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012375 descriptorset_allocate_info.descriptorSetCount = 1;
12376 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12377 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012379
Mark Mueller4042b652016-09-05 22:52:21 -060012380 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12381
12382 VkDescriptorBufferInfo buffer_info = {};
12383 buffer_info.buffer = buffer_test.GetBuffer();
12384 buffer_info.offset = 0;
12385 buffer_info.range = 1024;
12386
12387 VkWriteDescriptorSet write_descriptor_set = {};
12388 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12389 write_descriptor_set.dstSet = descriptorset;
12390 write_descriptor_set.descriptorCount = 1;
12391 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12392 write_descriptor_set.pBufferInfo = &buffer_info;
12393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012396 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12397 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012398
12399 VkPipelineObj pipe(m_device);
12400 pipe.AddColorAttachment();
12401 pipe.AddShader(&vs);
12402 pipe.AddShader(&fs);
12403
12404 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012405 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012406 pipeline_layout_create_info.setLayoutCount = 1;
12407 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12408
12409 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012410 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012411
12412 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12413
Tony Barbour552f6c02016-12-21 14:34:07 -070012414 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12418 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12419 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012420
Tony Barbour552f6c02016-12-21 14:34:07 -070012421 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012422
Mark Mueller917f6bc2016-08-30 10:57:19 -060012423 submit_info.signalSemaphoreCount = 1;
12424 submit_info.pSignalSemaphores = &semaphore;
12425 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012426 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012427
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012429 vkDestroyEvent(m_device->device(), event, nullptr);
12430 m_errorMonitor->VerifyFound();
12431
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012433 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12434 m_errorMonitor->VerifyFound();
12435
Jeremy Hayes08369882017-02-02 10:31:06 -070012436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012437 vkDestroyFence(m_device->device(), fence, nullptr);
12438 m_errorMonitor->VerifyFound();
12439
Tobin Ehlis122207b2016-09-01 08:50:06 -070012440 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012441 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12442 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012443 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012444 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12445 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012446 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012447 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12448 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012449 vkDestroyEvent(m_device->device(), event, nullptr);
12450 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012451 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012452 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12453}
12454
Tobin Ehlis2adda372016-09-01 08:51:06 -070012455TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12456 TEST_DESCRIPTION("Delete in-use query pool.");
12457
12458 ASSERT_NO_FATAL_FAILURE(InitState());
12459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12460
12461 VkQueryPool query_pool;
12462 VkQueryPoolCreateInfo query_pool_ci{};
12463 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12464 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12465 query_pool_ci.queryCount = 1;
12466 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012467 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012468 // Reset query pool to create binding with cmd buffer
12469 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12470
Tony Barbour552f6c02016-12-21 14:34:07 -070012471 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012472
12473 VkSubmitInfo submit_info = {};
12474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12475 submit_info.commandBufferCount = 1;
12476 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12477 // Submit cmd buffer and then destroy query pool while in-flight
12478 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12479
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012481 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12482 m_errorMonitor->VerifyFound();
12483
12484 vkQueueWaitIdle(m_device->m_queue);
12485 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012486 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12487 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012488 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12489}
12490
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012491TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12492 TEST_DESCRIPTION("Delete in-use pipeline.");
12493
12494 ASSERT_NO_FATAL_FAILURE(InitState());
12495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12496
12497 // Empty pipeline layout used for binding PSO
12498 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12499 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12500 pipeline_layout_ci.setLayoutCount = 0;
12501 pipeline_layout_ci.pSetLayouts = NULL;
12502
12503 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012504 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012505 ASSERT_VK_SUCCESS(err);
12506
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012508 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012509 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012511 // Store pipeline handle so we can actually delete it before test finishes
12512 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012513 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012514 VkPipelineObj pipe(m_device);
12515 pipe.AddShader(&vs);
12516 pipe.AddShader(&fs);
12517 pipe.AddColorAttachment();
12518 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12519 delete_this_pipeline = pipe.handle();
12520
Tony Barbour552f6c02016-12-21 14:34:07 -070012521 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012522 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012523 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012524
Tony Barbour552f6c02016-12-21 14:34:07 -070012525 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012526
12527 VkSubmitInfo submit_info = {};
12528 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12529 submit_info.commandBufferCount = 1;
12530 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12531 // Submit cmd buffer and then pipeline destroyed while in-flight
12532 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012533 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012534 m_errorMonitor->VerifyFound();
12535 // Make sure queue finished and then actually delete pipeline
12536 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012537 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12538 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012539 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12540 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12541}
12542
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012543TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12544 TEST_DESCRIPTION("Delete in-use imageView.");
12545
12546 ASSERT_NO_FATAL_FAILURE(InitState());
12547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12548
12549 VkDescriptorPoolSize ds_type_count;
12550 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12551 ds_type_count.descriptorCount = 1;
12552
12553 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12554 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12555 ds_pool_ci.maxSets = 1;
12556 ds_pool_ci.poolSizeCount = 1;
12557 ds_pool_ci.pPoolSizes = &ds_type_count;
12558
12559 VkDescriptorPool ds_pool;
12560 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12561 ASSERT_VK_SUCCESS(err);
12562
12563 VkSamplerCreateInfo sampler_ci = {};
12564 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12565 sampler_ci.pNext = NULL;
12566 sampler_ci.magFilter = VK_FILTER_NEAREST;
12567 sampler_ci.minFilter = VK_FILTER_NEAREST;
12568 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12569 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12570 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12571 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12572 sampler_ci.mipLodBias = 1.0;
12573 sampler_ci.anisotropyEnable = VK_FALSE;
12574 sampler_ci.maxAnisotropy = 1;
12575 sampler_ci.compareEnable = VK_FALSE;
12576 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12577 sampler_ci.minLod = 1.0;
12578 sampler_ci.maxLod = 1.0;
12579 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12580 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12581 VkSampler sampler;
12582
12583 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12584 ASSERT_VK_SUCCESS(err);
12585
12586 VkDescriptorSetLayoutBinding layout_binding;
12587 layout_binding.binding = 0;
12588 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12589 layout_binding.descriptorCount = 1;
12590 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12591 layout_binding.pImmutableSamplers = NULL;
12592
12593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12595 ds_layout_ci.bindingCount = 1;
12596 ds_layout_ci.pBindings = &layout_binding;
12597 VkDescriptorSetLayout ds_layout;
12598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12599 ASSERT_VK_SUCCESS(err);
12600
12601 VkDescriptorSetAllocateInfo alloc_info = {};
12602 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12603 alloc_info.descriptorSetCount = 1;
12604 alloc_info.descriptorPool = ds_pool;
12605 alloc_info.pSetLayouts = &ds_layout;
12606 VkDescriptorSet descriptor_set;
12607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12608 ASSERT_VK_SUCCESS(err);
12609
12610 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12611 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12612 pipeline_layout_ci.pNext = NULL;
12613 pipeline_layout_ci.setLayoutCount = 1;
12614 pipeline_layout_ci.pSetLayouts = &ds_layout;
12615
12616 VkPipelineLayout pipeline_layout;
12617 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12618 ASSERT_VK_SUCCESS(err);
12619
12620 VkImageObj image(m_device);
12621 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12622 ASSERT_TRUE(image.initialized());
12623
12624 VkImageView view;
12625 VkImageViewCreateInfo ivci = {};
12626 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12627 ivci.image = image.handle();
12628 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12629 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12630 ivci.subresourceRange.layerCount = 1;
12631 ivci.subresourceRange.baseMipLevel = 0;
12632 ivci.subresourceRange.levelCount = 1;
12633 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12634
12635 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12636 ASSERT_VK_SUCCESS(err);
12637
12638 VkDescriptorImageInfo image_info{};
12639 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12640 image_info.imageView = view;
12641 image_info.sampler = sampler;
12642
12643 VkWriteDescriptorSet descriptor_write = {};
12644 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12645 descriptor_write.dstSet = descriptor_set;
12646 descriptor_write.dstBinding = 0;
12647 descriptor_write.descriptorCount = 1;
12648 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12649 descriptor_write.pImageInfo = &image_info;
12650
12651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12652
12653 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012654 char const *vsSource =
12655 "#version 450\n"
12656 "\n"
12657 "out gl_PerVertex { \n"
12658 " vec4 gl_Position;\n"
12659 "};\n"
12660 "void main(){\n"
12661 " gl_Position = vec4(1);\n"
12662 "}\n";
12663 char const *fsSource =
12664 "#version 450\n"
12665 "\n"
12666 "layout(set=0, binding=0) uniform sampler2D s;\n"
12667 "layout(location=0) out vec4 x;\n"
12668 "void main(){\n"
12669 " x = texture(s, vec2(1));\n"
12670 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012671 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12672 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12673 VkPipelineObj pipe(m_device);
12674 pipe.AddShader(&vs);
12675 pipe.AddShader(&fs);
12676 pipe.AddColorAttachment();
12677 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12678
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012680
Tony Barbour552f6c02016-12-21 14:34:07 -070012681 m_commandBuffer->BeginCommandBuffer();
12682 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012683 // Bind pipeline to cmd buffer
12684 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12686 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012687
12688 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12689 VkRect2D scissor = {{0, 0}, {16, 16}};
12690 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12691 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12692
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012693 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012694 m_commandBuffer->EndRenderPass();
12695 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012696 // Submit cmd buffer then destroy sampler
12697 VkSubmitInfo submit_info = {};
12698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12699 submit_info.commandBufferCount = 1;
12700 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12701 // Submit cmd buffer and then destroy imageView while in-flight
12702 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12703
12704 vkDestroyImageView(m_device->device(), view, nullptr);
12705 m_errorMonitor->VerifyFound();
12706 vkQueueWaitIdle(m_device->m_queue);
12707 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012708 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12709 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012710 vkDestroyImageView(m_device->device(), view, NULL);
12711 vkDestroySampler(m_device->device(), sampler, nullptr);
12712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12715}
12716
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012717TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12718 TEST_DESCRIPTION("Delete in-use bufferView.");
12719
12720 ASSERT_NO_FATAL_FAILURE(InitState());
12721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12722
12723 VkDescriptorPoolSize ds_type_count;
12724 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12725 ds_type_count.descriptorCount = 1;
12726
12727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12729 ds_pool_ci.maxSets = 1;
12730 ds_pool_ci.poolSizeCount = 1;
12731 ds_pool_ci.pPoolSizes = &ds_type_count;
12732
12733 VkDescriptorPool ds_pool;
12734 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12735 ASSERT_VK_SUCCESS(err);
12736
12737 VkDescriptorSetLayoutBinding layout_binding;
12738 layout_binding.binding = 0;
12739 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12740 layout_binding.descriptorCount = 1;
12741 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12742 layout_binding.pImmutableSamplers = NULL;
12743
12744 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12745 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12746 ds_layout_ci.bindingCount = 1;
12747 ds_layout_ci.pBindings = &layout_binding;
12748 VkDescriptorSetLayout ds_layout;
12749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12750 ASSERT_VK_SUCCESS(err);
12751
12752 VkDescriptorSetAllocateInfo alloc_info = {};
12753 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12754 alloc_info.descriptorSetCount = 1;
12755 alloc_info.descriptorPool = ds_pool;
12756 alloc_info.pSetLayouts = &ds_layout;
12757 VkDescriptorSet descriptor_set;
12758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12759 ASSERT_VK_SUCCESS(err);
12760
12761 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12762 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12763 pipeline_layout_ci.pNext = NULL;
12764 pipeline_layout_ci.setLayoutCount = 1;
12765 pipeline_layout_ci.pSetLayouts = &ds_layout;
12766
12767 VkPipelineLayout pipeline_layout;
12768 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12769 ASSERT_VK_SUCCESS(err);
12770
12771 VkBuffer buffer;
12772 uint32_t queue_family_index = 0;
12773 VkBufferCreateInfo buffer_create_info = {};
12774 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12775 buffer_create_info.size = 1024;
12776 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12777 buffer_create_info.queueFamilyIndexCount = 1;
12778 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12779
12780 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12781 ASSERT_VK_SUCCESS(err);
12782
12783 VkMemoryRequirements memory_reqs;
12784 VkDeviceMemory buffer_memory;
12785
12786 VkMemoryAllocateInfo memory_info = {};
12787 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12788 memory_info.allocationSize = 0;
12789 memory_info.memoryTypeIndex = 0;
12790
12791 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12792 memory_info.allocationSize = memory_reqs.size;
12793 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12794 ASSERT_TRUE(pass);
12795
12796 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12797 ASSERT_VK_SUCCESS(err);
12798 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12799 ASSERT_VK_SUCCESS(err);
12800
12801 VkBufferView view;
12802 VkBufferViewCreateInfo bvci = {};
12803 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12804 bvci.buffer = buffer;
12805 bvci.format = VK_FORMAT_R8_UNORM;
12806 bvci.range = VK_WHOLE_SIZE;
12807
12808 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12809 ASSERT_VK_SUCCESS(err);
12810
12811 VkWriteDescriptorSet descriptor_write = {};
12812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12813 descriptor_write.dstSet = descriptor_set;
12814 descriptor_write.dstBinding = 0;
12815 descriptor_write.descriptorCount = 1;
12816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12817 descriptor_write.pTexelBufferView = &view;
12818
12819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012821 char const *vsSource =
12822 "#version 450\n"
12823 "\n"
12824 "out gl_PerVertex { \n"
12825 " vec4 gl_Position;\n"
12826 "};\n"
12827 "void main(){\n"
12828 " gl_Position = vec4(1);\n"
12829 "}\n";
12830 char const *fsSource =
12831 "#version 450\n"
12832 "\n"
12833 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12834 "layout(location=0) out vec4 x;\n"
12835 "void main(){\n"
12836 " x = imageLoad(s, 0);\n"
12837 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12840 VkPipelineObj pipe(m_device);
12841 pipe.AddShader(&vs);
12842 pipe.AddShader(&fs);
12843 pipe.AddColorAttachment();
12844 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12845
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012847
Tony Barbour552f6c02016-12-21 14:34:07 -070012848 m_commandBuffer->BeginCommandBuffer();
12849 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012850 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12851 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12852 VkRect2D scissor = {{0, 0}, {16, 16}};
12853 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12854 // Bind pipeline to cmd buffer
12855 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12856 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12857 &descriptor_set, 0, nullptr);
12858 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012859 m_commandBuffer->EndRenderPass();
12860 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012861
12862 VkSubmitInfo submit_info = {};
12863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12864 submit_info.commandBufferCount = 1;
12865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12866 // Submit cmd buffer and then destroy bufferView while in-flight
12867 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12868
12869 vkDestroyBufferView(m_device->device(), view, nullptr);
12870 m_errorMonitor->VerifyFound();
12871 vkQueueWaitIdle(m_device->m_queue);
12872 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012873 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12874 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012875 vkDestroyBufferView(m_device->device(), view, NULL);
12876 vkDestroyBuffer(m_device->device(), buffer, NULL);
12877 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12880 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12881}
12882
Tobin Ehlis209532e2016-09-07 13:52:18 -060012883TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12884 TEST_DESCRIPTION("Delete in-use sampler.");
12885
12886 ASSERT_NO_FATAL_FAILURE(InitState());
12887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12888
12889 VkDescriptorPoolSize ds_type_count;
12890 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12891 ds_type_count.descriptorCount = 1;
12892
12893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12895 ds_pool_ci.maxSets = 1;
12896 ds_pool_ci.poolSizeCount = 1;
12897 ds_pool_ci.pPoolSizes = &ds_type_count;
12898
12899 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012900 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012901 ASSERT_VK_SUCCESS(err);
12902
12903 VkSamplerCreateInfo sampler_ci = {};
12904 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12905 sampler_ci.pNext = NULL;
12906 sampler_ci.magFilter = VK_FILTER_NEAREST;
12907 sampler_ci.minFilter = VK_FILTER_NEAREST;
12908 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12909 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12910 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12911 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12912 sampler_ci.mipLodBias = 1.0;
12913 sampler_ci.anisotropyEnable = VK_FALSE;
12914 sampler_ci.maxAnisotropy = 1;
12915 sampler_ci.compareEnable = VK_FALSE;
12916 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12917 sampler_ci.minLod = 1.0;
12918 sampler_ci.maxLod = 1.0;
12919 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12920 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12921 VkSampler sampler;
12922
12923 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12924 ASSERT_VK_SUCCESS(err);
12925
12926 VkDescriptorSetLayoutBinding layout_binding;
12927 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012928 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012929 layout_binding.descriptorCount = 1;
12930 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12931 layout_binding.pImmutableSamplers = NULL;
12932
12933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12935 ds_layout_ci.bindingCount = 1;
12936 ds_layout_ci.pBindings = &layout_binding;
12937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012939 ASSERT_VK_SUCCESS(err);
12940
12941 VkDescriptorSetAllocateInfo alloc_info = {};
12942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12943 alloc_info.descriptorSetCount = 1;
12944 alloc_info.descriptorPool = ds_pool;
12945 alloc_info.pSetLayouts = &ds_layout;
12946 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012948 ASSERT_VK_SUCCESS(err);
12949
12950 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12951 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12952 pipeline_layout_ci.pNext = NULL;
12953 pipeline_layout_ci.setLayoutCount = 1;
12954 pipeline_layout_ci.pSetLayouts = &ds_layout;
12955
12956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012958 ASSERT_VK_SUCCESS(err);
12959
12960 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 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 -060012962 ASSERT_TRUE(image.initialized());
12963
12964 VkImageView view;
12965 VkImageViewCreateInfo ivci = {};
12966 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12967 ivci.image = image.handle();
12968 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12969 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12970 ivci.subresourceRange.layerCount = 1;
12971 ivci.subresourceRange.baseMipLevel = 0;
12972 ivci.subresourceRange.levelCount = 1;
12973 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12974
12975 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12976 ASSERT_VK_SUCCESS(err);
12977
12978 VkDescriptorImageInfo image_info{};
12979 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12980 image_info.imageView = view;
12981 image_info.sampler = sampler;
12982
12983 VkWriteDescriptorSet descriptor_write = {};
12984 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12985 descriptor_write.dstSet = descriptor_set;
12986 descriptor_write.dstBinding = 0;
12987 descriptor_write.descriptorCount = 1;
12988 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12989 descriptor_write.pImageInfo = &image_info;
12990
12991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12992
12993 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012994 char const *vsSource =
12995 "#version 450\n"
12996 "\n"
12997 "out gl_PerVertex { \n"
12998 " vec4 gl_Position;\n"
12999 "};\n"
13000 "void main(){\n"
13001 " gl_Position = vec4(1);\n"
13002 "}\n";
13003 char const *fsSource =
13004 "#version 450\n"
13005 "\n"
13006 "layout(set=0, binding=0) uniform sampler2D s;\n"
13007 "layout(location=0) out vec4 x;\n"
13008 "void main(){\n"
13009 " x = texture(s, vec2(1));\n"
13010 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013011 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13012 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13013 VkPipelineObj pipe(m_device);
13014 pipe.AddShader(&vs);
13015 pipe.AddShader(&fs);
13016 pipe.AddColorAttachment();
13017 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13018
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013020
Tony Barbour552f6c02016-12-21 14:34:07 -070013021 m_commandBuffer->BeginCommandBuffer();
13022 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013023 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13025 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13026 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013027
13028 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13029 VkRect2D scissor = {{0, 0}, {16, 16}};
13030 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13031 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13032
Tobin Ehlis209532e2016-09-07 13:52:18 -060013033 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013034 m_commandBuffer->EndRenderPass();
13035 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013036 // Submit cmd buffer then destroy sampler
13037 VkSubmitInfo submit_info = {};
13038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13039 submit_info.commandBufferCount = 1;
13040 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13041 // Submit cmd buffer and then destroy sampler while in-flight
13042 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013044 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013045 m_errorMonitor->VerifyFound();
13046 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013047
Tobin Ehlis209532e2016-09-07 13:52:18 -060013048 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013049 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13050 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013051 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013052 vkDestroyImageView(m_device->device(), view, NULL);
13053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13054 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13055 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13056}
13057
Mark Mueller1cd9f412016-08-25 13:23:52 -060013058TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 TEST_DESCRIPTION(
13060 "Call VkQueueSubmit with a semaphore that is already "
13061 "signaled but not waited on by the queue. Wait on a "
13062 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013063
13064 ASSERT_NO_FATAL_FAILURE(InitState());
13065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 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 -070013068 const char *invalid_fence_wait_message =
13069 " which has not been submitted on a Queue or during "
13070 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013071
Tony Barbour552f6c02016-12-21 14:34:07 -070013072 m_commandBuffer->BeginCommandBuffer();
13073 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013074
13075 VkSemaphoreCreateInfo semaphore_create_info = {};
13076 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13077 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013078 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013079 VkSubmitInfo submit_info = {};
13080 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13081 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013082 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013083 submit_info.signalSemaphoreCount = 1;
13084 submit_info.pSignalSemaphores = &semaphore;
13085 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013086 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013087 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013088 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013089 m_commandBuffer->BeginCommandBuffer();
13090 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013092 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13093 m_errorMonitor->VerifyFound();
13094
Mark Mueller1cd9f412016-08-25 13:23:52 -060013095 VkFenceCreateInfo fence_create_info = {};
13096 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13097 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013098 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013101 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13102 m_errorMonitor->VerifyFound();
13103
Mark Mueller4042b652016-09-05 22:52:21 -060013104 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013105 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013106 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13107}
13108
Tobin Ehlis4af23302016-07-19 10:50:30 -060013109TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013110 TEST_DESCRIPTION(
13111 "Bind a secondary command buffer with with a framebuffer "
13112 "that does not match the framebuffer for the active "
13113 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013114 ASSERT_NO_FATAL_FAILURE(InitState());
13115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13116
13117 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 VkAttachmentDescription attachment = {0,
13119 VK_FORMAT_B8G8R8A8_UNORM,
13120 VK_SAMPLE_COUNT_1_BIT,
13121 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13122 VK_ATTACHMENT_STORE_OP_STORE,
13123 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13124 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13125 VK_IMAGE_LAYOUT_UNDEFINED,
13126 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013130 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013132 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013133
13134 VkRenderPass rp;
13135 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13136 ASSERT_VK_SUCCESS(err);
13137
13138 // A compatible framebuffer.
13139 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 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 -060013141 ASSERT_TRUE(image.initialized());
13142
13143 VkImageViewCreateInfo ivci = {
13144 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13145 nullptr,
13146 0,
13147 image.handle(),
13148 VK_IMAGE_VIEW_TYPE_2D,
13149 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13151 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013152 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13153 };
13154 VkImageView view;
13155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13156 ASSERT_VK_SUCCESS(err);
13157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013159 VkFramebuffer fb;
13160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13161 ASSERT_VK_SUCCESS(err);
13162
13163 VkCommandBufferAllocateInfo cbai = {};
13164 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13165 cbai.commandPool = m_commandPool;
13166 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13167 cbai.commandBufferCount = 1;
13168
13169 VkCommandBuffer sec_cb;
13170 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13171 ASSERT_VK_SUCCESS(err);
13172 VkCommandBufferBeginInfo cbbi = {};
13173 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013174 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013175 cbii.renderPass = renderPass();
13176 cbii.framebuffer = fb;
13177 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13178 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 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 -060013180 cbbi.pInheritanceInfo = &cbii;
13181 vkBeginCommandBuffer(sec_cb, &cbbi);
13182 vkEndCommandBuffer(sec_cb);
13183
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013184 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013185 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13186 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013189 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013190 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13191 m_errorMonitor->VerifyFound();
13192 // Cleanup
13193 vkDestroyImageView(m_device->device(), view, NULL);
13194 vkDestroyRenderPass(m_device->device(), rp, NULL);
13195 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13196}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013197
13198TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013199 TEST_DESCRIPTION(
13200 "If logicOp is available on the device, set it to an "
13201 "invalid value. If logicOp is not available, attempt to "
13202 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013203 ASSERT_NO_FATAL_FAILURE(InitState());
13204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13205
13206 auto features = m_device->phy().features();
13207 // Set the expected error depending on whether or not logicOp available
13208 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13210 "If logic operations feature not "
13211 "enabled, logicOpEnable must be "
13212 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013213 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013215 }
13216 // Create a pipeline using logicOp
13217 VkResult err;
13218
13219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13221
13222 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013224 ASSERT_VK_SUCCESS(err);
13225
13226 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13227 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13228 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013229 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013230 vp_state_ci.pViewports = &vp;
13231 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013232 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013233 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013234
13235 VkPipelineShaderStageCreateInfo shaderStages[2];
13236 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13239 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013240 shaderStages[0] = vs.GetStageCreateInfo();
13241 shaderStages[1] = fs.GetStageCreateInfo();
13242
13243 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13244 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13245
13246 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13247 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13248 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13249
13250 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13251 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013252 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013253
13254 VkPipelineColorBlendAttachmentState att = {};
13255 att.blendEnable = VK_FALSE;
13256 att.colorWriteMask = 0xf;
13257
13258 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13259 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13260 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13261 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013262 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013263 cb_ci.attachmentCount = 1;
13264 cb_ci.pAttachments = &att;
13265
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013266 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13267 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13268 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13269
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013270 VkGraphicsPipelineCreateInfo gp_ci = {};
13271 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13272 gp_ci.stageCount = 2;
13273 gp_ci.pStages = shaderStages;
13274 gp_ci.pVertexInputState = &vi_ci;
13275 gp_ci.pInputAssemblyState = &ia_ci;
13276 gp_ci.pViewportState = &vp_state_ci;
13277 gp_ci.pRasterizationState = &rs_ci;
13278 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013279 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013280 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13281 gp_ci.layout = pipeline_layout;
13282 gp_ci.renderPass = renderPass();
13283
13284 VkPipelineCacheCreateInfo pc_ci = {};
13285 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13286
13287 VkPipeline pipeline;
13288 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013289 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013290 ASSERT_VK_SUCCESS(err);
13291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013293 m_errorMonitor->VerifyFound();
13294 if (VK_SUCCESS == err) {
13295 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13296 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013297 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13299}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013300
Mike Stroyanaccf7692015-05-12 16:00:45 -060013301#if GTEST_IS_THREADSAFE
13302struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013303 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013304 VkEvent event;
13305 bool bailout;
13306};
13307
Karl Schultz6addd812016-02-02 17:17:23 -070013308extern "C" void *AddToCommandBuffer(void *arg) {
13309 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013310
Mike Stroyana6d14942016-07-13 15:10:05 -060013311 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013312 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013313 if (data->bailout) {
13314 break;
13315 }
13316 }
13317 return NULL;
13318}
13319
Karl Schultz6addd812016-02-02 17:17:23 -070013320TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013321 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013324
Mike Stroyanaccf7692015-05-12 16:00:45 -060013325 ASSERT_NO_FATAL_FAILURE(InitState());
13326 ASSERT_NO_FATAL_FAILURE(InitViewport());
13327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13328
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013329 // Calls AllocateCommandBuffers
13330 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013331
13332 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013334
13335 VkEventCreateInfo event_info;
13336 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013337 VkResult err;
13338
13339 memset(&event_info, 0, sizeof(event_info));
13340 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13341
Chia-I Wuf7458c52015-10-26 21:10:41 +080013342 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013343 ASSERT_VK_SUCCESS(err);
13344
Mike Stroyanaccf7692015-05-12 16:00:45 -060013345 err = vkResetEvent(device(), event);
13346 ASSERT_VK_SUCCESS(err);
13347
13348 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013349 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013350 data.event = event;
13351 data.bailout = false;
13352 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013353
13354 // First do some correct operations using multiple threads.
13355 // Add many entries to command buffer from another thread.
13356 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13357 // Make non-conflicting calls from this thread at the same time.
13358 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013359 uint32_t count;
13360 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013361 }
13362 test_platform_thread_join(thread, NULL);
13363
13364 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013365 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013366 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013367 // Add many entries to command buffer from this thread at the same time.
13368 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013369
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013370 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013371 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013372
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013373 m_errorMonitor->SetBailout(NULL);
13374
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013375 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013376
Chia-I Wuf7458c52015-10-26 21:10:41 +080013377 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013378}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013379#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013380
Karl Schultz6addd812016-02-02 17:17:23 -070013381TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013382 TEST_DESCRIPTION(
13383 "Test that an error is produced for a spirv module "
13384 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013387
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013388 ASSERT_NO_FATAL_FAILURE(InitState());
13389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13390
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013391 VkShaderModule module;
13392 VkShaderModuleCreateInfo moduleCreateInfo;
13393 struct icd_spv_header spv;
13394
13395 spv.magic = ICD_SPV_MAGIC;
13396 spv.version = ICD_SPV_VERSION;
13397 spv.gen_magic = 0;
13398
13399 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13400 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013401 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013402 moduleCreateInfo.codeSize = 4;
13403 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013404 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013405
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013406 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013407}
13408
Karl Schultz6addd812016-02-02 17:17:23 -070013409TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013410 TEST_DESCRIPTION(
13411 "Test that an error is produced for a spirv module "
13412 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013415
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013416 ASSERT_NO_FATAL_FAILURE(InitState());
13417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13418
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013419 VkShaderModule module;
13420 VkShaderModuleCreateInfo moduleCreateInfo;
13421 struct icd_spv_header spv;
13422
13423 spv.magic = ~ICD_SPV_MAGIC;
13424 spv.version = ICD_SPV_VERSION;
13425 spv.gen_magic = 0;
13426
13427 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13428 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013429 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013430 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13431 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013432 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013433
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013434 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013435}
13436
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013437#if 0
13438// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013439TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013441 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013442
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013443 ASSERT_NO_FATAL_FAILURE(InitState());
13444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13445
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013446 VkShaderModule module;
13447 VkShaderModuleCreateInfo moduleCreateInfo;
13448 struct icd_spv_header spv;
13449
13450 spv.magic = ICD_SPV_MAGIC;
13451 spv.version = ~ICD_SPV_VERSION;
13452 spv.gen_magic = 0;
13453
13454 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13455 moduleCreateInfo.pNext = NULL;
13456
Karl Schultz6addd812016-02-02 17:17:23 -070013457 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013458 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13459 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013460 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013461
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013462 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013463}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013464#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013465
Karl Schultz6addd812016-02-02 17:17:23 -070013466TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013467 TEST_DESCRIPTION(
13468 "Test that a warning is produced for a vertex output that "
13469 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013471
Chris Forbes9f7ff632015-05-25 11:13:08 +120013472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013475 char const *vsSource =
13476 "#version 450\n"
13477 "\n"
13478 "layout(location=0) out float x;\n"
13479 "out gl_PerVertex {\n"
13480 " vec4 gl_Position;\n"
13481 "};\n"
13482 "void main(){\n"
13483 " gl_Position = vec4(1);\n"
13484 " x = 0;\n"
13485 "}\n";
13486 char const *fsSource =
13487 "#version 450\n"
13488 "\n"
13489 "layout(location=0) out vec4 color;\n"
13490 "void main(){\n"
13491 " color = vec4(1);\n"
13492 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013493
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013496
13497 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013498 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013499 pipe.AddShader(&vs);
13500 pipe.AddShader(&fs);
13501
Chris Forbes9f7ff632015-05-25 11:13:08 +120013502 VkDescriptorSetObj descriptorSet(m_device);
13503 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013505
Tony Barbour5781e8f2015-08-04 16:23:11 -060013506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013507
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013508 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013509}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013510
Mark Mueller098c9cb2016-09-08 09:01:57 -060013511TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13512 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13513
13514 ASSERT_NO_FATAL_FAILURE(InitState());
13515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13516
13517 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013518 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013520 char const *vsSource =
13521 "#version 450\n"
13522 "\n"
13523 "out gl_PerVertex {\n"
13524 " vec4 gl_Position;\n"
13525 "};\n"
13526 "void main(){\n"
13527 " gl_Position = vec4(1);\n"
13528 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013530 char const *fsSource =
13531 "#version 450\n"
13532 "\n"
13533 "layout (constant_id = 0) const float r = 0.0f;\n"
13534 "layout(location = 0) out vec4 uFragColor;\n"
13535 "void main(){\n"
13536 " uFragColor = vec4(r,1,0,1);\n"
13537 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013538
13539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13541
13542 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13543 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13544
13545 VkPipelineLayout pipeline_layout;
13546 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13547
13548 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13549 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13550 vp_state_create_info.viewportCount = 1;
13551 VkViewport viewport = {};
13552 vp_state_create_info.pViewports = &viewport;
13553 vp_state_create_info.scissorCount = 1;
13554 VkRect2D scissors = {};
13555 vp_state_create_info.pScissors = &scissors;
13556
13557 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13558
13559 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13560 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13561 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13562 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13563
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013564 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013565
13566 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13567 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13568
13569 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13570 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13571 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13572
13573 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13574 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13575 rasterization_state_create_info.pNext = nullptr;
13576 rasterization_state_create_info.lineWidth = 1.0f;
13577 rasterization_state_create_info.rasterizerDiscardEnable = true;
13578
13579 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13580 color_blend_attachment_state.blendEnable = VK_FALSE;
13581 color_blend_attachment_state.colorWriteMask = 0xf;
13582
13583 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13584 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13585 color_blend_state_create_info.attachmentCount = 1;
13586 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13587
13588 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13589 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13590 graphicspipe_create_info.stageCount = 2;
13591 graphicspipe_create_info.pStages = shader_stage_create_info;
13592 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13593 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13594 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13595 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13596 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13597 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13598 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13599 graphicspipe_create_info.layout = pipeline_layout;
13600 graphicspipe_create_info.renderPass = renderPass();
13601
13602 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13603 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13604
13605 VkPipelineCache pipelineCache;
13606 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13607
13608 // This structure maps constant ids to data locations.
13609 const VkSpecializationMapEntry entry =
13610 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013611 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013612
13613 uint32_t data = 1;
13614
13615 // Set up the info describing spec map and data
13616 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013617 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013618 };
13619 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13620
13621 VkPipeline pipeline;
13622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13623 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13624 m_errorMonitor->VerifyFound();
13625
13626 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13627 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13628}
13629
13630TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13631 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13632
13633 ASSERT_NO_FATAL_FAILURE(InitState());
13634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13635
13636 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13637
13638 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13639 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13640 descriptor_pool_type_count[0].descriptorCount = 1;
13641 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13642 descriptor_pool_type_count[1].descriptorCount = 1;
13643
13644 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13645 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13646 descriptor_pool_create_info.maxSets = 1;
13647 descriptor_pool_create_info.poolSizeCount = 2;
13648 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13649 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13650
13651 VkDescriptorPool descriptorset_pool;
13652 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13653
13654 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13655 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13656 descriptorset_layout_binding.descriptorCount = 1;
13657 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013658 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013659
13660 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13661 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13662 descriptorset_layout_create_info.bindingCount = 1;
13663 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13664
13665 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013666 ASSERT_VK_SUCCESS(
13667 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013668
13669 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13670 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13671 descriptorset_allocate_info.descriptorSetCount = 1;
13672 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13673 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13674 VkDescriptorSet descriptorset;
13675 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13676
13677 // Challenge core_validation with a non uniform buffer type.
13678 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13679
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013680 char const *vsSource =
13681 "#version 450\n"
13682 "\n"
13683 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13684 " mat4 mvp;\n"
13685 "} ubuf;\n"
13686 "out gl_PerVertex {\n"
13687 " vec4 gl_Position;\n"
13688 "};\n"
13689 "void main(){\n"
13690 " gl_Position = ubuf.mvp * vec4(1);\n"
13691 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013692
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013693 char const *fsSource =
13694 "#version 450\n"
13695 "\n"
13696 "layout(location = 0) out vec4 uFragColor;\n"
13697 "void main(){\n"
13698 " uFragColor = vec4(0,1,0,1);\n"
13699 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013700
13701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13703
13704 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13705 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13706 pipeline_layout_create_info.setLayoutCount = 1;
13707 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13708
13709 VkPipelineLayout pipeline_layout;
13710 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13711
13712 VkPipelineObj pipe(m_device);
13713 pipe.AddColorAttachment();
13714 pipe.AddShader(&vs);
13715 pipe.AddShader(&fs);
13716
13717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13718 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13719 m_errorMonitor->VerifyFound();
13720
13721 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13722 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13723 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13724}
13725
13726TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13727 TEST_DESCRIPTION(
13728 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13729
13730 ASSERT_NO_FATAL_FAILURE(InitState());
13731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13732
13733 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13734
13735 VkDescriptorPoolSize descriptor_pool_type_count = {};
13736 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13737 descriptor_pool_type_count.descriptorCount = 1;
13738
13739 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13740 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13741 descriptor_pool_create_info.maxSets = 1;
13742 descriptor_pool_create_info.poolSizeCount = 1;
13743 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13744 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13745
13746 VkDescriptorPool descriptorset_pool;
13747 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13748
13749 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13750 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13751 descriptorset_layout_binding.descriptorCount = 1;
13752 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13753 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013754 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013755
13756 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13757 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13758 descriptorset_layout_create_info.bindingCount = 1;
13759 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13760
13761 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013762 ASSERT_VK_SUCCESS(
13763 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013764
13765 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13766 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13767 descriptorset_allocate_info.descriptorSetCount = 1;
13768 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13769 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13770 VkDescriptorSet descriptorset;
13771 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13772
13773 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13774
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013775 char const *vsSource =
13776 "#version 450\n"
13777 "\n"
13778 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13779 " mat4 mvp;\n"
13780 "} ubuf;\n"
13781 "out gl_PerVertex {\n"
13782 " vec4 gl_Position;\n"
13783 "};\n"
13784 "void main(){\n"
13785 " gl_Position = ubuf.mvp * vec4(1);\n"
13786 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013788 char const *fsSource =
13789 "#version 450\n"
13790 "\n"
13791 "layout(location = 0) out vec4 uFragColor;\n"
13792 "void main(){\n"
13793 " uFragColor = vec4(0,1,0,1);\n"
13794 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013795
13796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13798
13799 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13800 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13801 pipeline_layout_create_info.setLayoutCount = 1;
13802 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13803
13804 VkPipelineLayout pipeline_layout;
13805 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13806
13807 VkPipelineObj pipe(m_device);
13808 pipe.AddColorAttachment();
13809 pipe.AddShader(&vs);
13810 pipe.AddShader(&fs);
13811
13812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13813 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13814 m_errorMonitor->VerifyFound();
13815
13816 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13817 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13818 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13819}
13820
13821TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013822 TEST_DESCRIPTION(
13823 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13824 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013825
13826 ASSERT_NO_FATAL_FAILURE(InitState());
13827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13828
13829 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013830 "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 -060013831
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013832 char const *vsSource =
13833 "#version 450\n"
13834 "\n"
13835 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13836 "out gl_PerVertex {\n"
13837 " vec4 gl_Position;\n"
13838 "};\n"
13839 "void main(){\n"
13840 " gl_Position = vec4(consts.x);\n"
13841 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013842
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013843 char const *fsSource =
13844 "#version 450\n"
13845 "\n"
13846 "layout(location = 0) out vec4 uFragColor;\n"
13847 "void main(){\n"
13848 " uFragColor = vec4(0,1,0,1);\n"
13849 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013850
13851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13853
13854 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13855 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13856
13857 // Set up a push constant range
13858 VkPushConstantRange push_constant_ranges = {};
13859 // Set to the wrong stage to challenge core_validation
13860 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13861 push_constant_ranges.size = 4;
13862
13863 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13864 pipeline_layout_create_info.pushConstantRangeCount = 1;
13865
13866 VkPipelineLayout pipeline_layout;
13867 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13868
13869 VkPipelineObj pipe(m_device);
13870 pipe.AddColorAttachment();
13871 pipe.AddShader(&vs);
13872 pipe.AddShader(&fs);
13873
13874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13875 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13876 m_errorMonitor->VerifyFound();
13877
13878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13879}
13880
13881TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13882 TEST_DESCRIPTION(
13883 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13884
13885 ASSERT_NO_FATAL_FAILURE(InitState());
13886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13887
13888 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013889 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013890
13891 // Some awkward steps are required to test with custom device features.
13892 std::vector<const char *> device_extension_names;
13893 auto features = m_device->phy().features();
13894 // Disable support for 64 bit floats
13895 features.shaderFloat64 = false;
13896 // The sacrificial device object
13897 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13898
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013899 char const *vsSource =
13900 "#version 450\n"
13901 "\n"
13902 "out gl_PerVertex {\n"
13903 " vec4 gl_Position;\n"
13904 "};\n"
13905 "void main(){\n"
13906 " gl_Position = vec4(1);\n"
13907 "}\n";
13908 char const *fsSource =
13909 "#version 450\n"
13910 "\n"
13911 "layout(location=0) out vec4 color;\n"
13912 "void main(){\n"
13913 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13914 " color = vec4(green);\n"
13915 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013916
13917 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13918 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13919
13920 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013921
13922 VkPipelineObj pipe(&test_device);
13923 pipe.AddColorAttachment();
13924 pipe.AddShader(&vs);
13925 pipe.AddShader(&fs);
13926
13927 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13928 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13929 VkPipelineLayout pipeline_layout;
13930 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13931
13932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13933 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13934 m_errorMonitor->VerifyFound();
13935
13936 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13937}
13938
13939TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13940 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13941
13942 ASSERT_NO_FATAL_FAILURE(InitState());
13943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13944
13945 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13946
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013947 char const *vsSource =
13948 "#version 450\n"
13949 "\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "layout(xfb_buffer = 1) out;"
13954 "void main(){\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource =
13958 "#version 450\n"
13959 "\n"
13960 "layout(location=0) out vec4 color;\n"
13961 "void main(){\n"
13962 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13963 " color = vec4(green);\n"
13964 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013965
13966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13968
13969 VkPipelineObj pipe(m_device);
13970 pipe.AddColorAttachment();
13971 pipe.AddShader(&vs);
13972 pipe.AddShader(&fs);
13973
13974 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13975 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13976 VkPipelineLayout pipeline_layout;
13977 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13978
13979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13980 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13981 m_errorMonitor->VerifyFound();
13982
13983 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13984}
13985
Karl Schultz6addd812016-02-02 17:17:23 -070013986TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013987 TEST_DESCRIPTION(
13988 "Test that an error is produced for a fragment shader input "
13989 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013992
Chris Forbes59cb88d2015-05-25 11:13:13 +120013993 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013996 char const *vsSource =
13997 "#version 450\n"
13998 "\n"
13999 "out gl_PerVertex {\n"
14000 " vec4 gl_Position;\n"
14001 "};\n"
14002 "void main(){\n"
14003 " gl_Position = vec4(1);\n"
14004 "}\n";
14005 char const *fsSource =
14006 "#version 450\n"
14007 "\n"
14008 "layout(location=0) in float x;\n"
14009 "layout(location=0) out vec4 color;\n"
14010 "void main(){\n"
14011 " color = vec4(x);\n"
14012 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014013
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014016
14017 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014018 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014019 pipe.AddShader(&vs);
14020 pipe.AddShader(&fs);
14021
Chris Forbes59cb88d2015-05-25 11:13:13 +120014022 VkDescriptorSetObj descriptorSet(m_device);
14023 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014025
Tony Barbour5781e8f2015-08-04 16:23:11 -060014026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014027
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014028 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014029}
14030
Karl Schultz6addd812016-02-02 17:17:23 -070014031TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014032 TEST_DESCRIPTION(
14033 "Test that an error is produced for a fragment shader input "
14034 "within an interace block, which is not present in the outputs "
14035 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014037
14038 ASSERT_NO_FATAL_FAILURE(InitState());
14039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14040
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014041 char const *vsSource =
14042 "#version 450\n"
14043 "\n"
14044 "out gl_PerVertex {\n"
14045 " vec4 gl_Position;\n"
14046 "};\n"
14047 "void main(){\n"
14048 " gl_Position = vec4(1);\n"
14049 "}\n";
14050 char const *fsSource =
14051 "#version 450\n"
14052 "\n"
14053 "in block { layout(location=0) float x; } ins;\n"
14054 "layout(location=0) out vec4 color;\n"
14055 "void main(){\n"
14056 " color = vec4(ins.x);\n"
14057 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014058
14059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14061
14062 VkPipelineObj pipe(m_device);
14063 pipe.AddColorAttachment();
14064 pipe.AddShader(&vs);
14065 pipe.AddShader(&fs);
14066
14067 VkDescriptorSetObj descriptorSet(m_device);
14068 descriptorSet.AppendDummy();
14069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14070
14071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014073 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014074}
14075
Karl Schultz6addd812016-02-02 17:17:23 -070014076TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014077 TEST_DESCRIPTION(
14078 "Test that an error is produced for mismatched array sizes "
14079 "across the vertex->fragment shader interface");
14080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14081 "Type mismatch on location 0.0: 'ptr to "
14082 "output arr[2] of float32' vs 'ptr to "
14083 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014084
14085 ASSERT_NO_FATAL_FAILURE(InitState());
14086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14087
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014088 char const *vsSource =
14089 "#version 450\n"
14090 "\n"
14091 "layout(location=0) out float x[2];\n"
14092 "out gl_PerVertex {\n"
14093 " vec4 gl_Position;\n"
14094 "};\n"
14095 "void main(){\n"
14096 " x[0] = 0; x[1] = 0;\n"
14097 " gl_Position = vec4(1);\n"
14098 "}\n";
14099 char const *fsSource =
14100 "#version 450\n"
14101 "\n"
14102 "layout(location=0) in float x[1];\n"
14103 "layout(location=0) out vec4 color;\n"
14104 "void main(){\n"
14105 " color = vec4(x[0]);\n"
14106 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014107
14108 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14109 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14110
14111 VkPipelineObj pipe(m_device);
14112 pipe.AddColorAttachment();
14113 pipe.AddShader(&vs);
14114 pipe.AddShader(&fs);
14115
14116 VkDescriptorSetObj descriptorSet(m_device);
14117 descriptorSet.AppendDummy();
14118 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14119
14120 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14121
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014122 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014123}
14124
Karl Schultz6addd812016-02-02 17:17:23 -070014125TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014126 TEST_DESCRIPTION(
14127 "Test that an error is produced for mismatched types across "
14128 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014130
Chris Forbesb56af562015-05-25 11:13:17 +120014131 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "layout(location=0) out int x;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " x = 0;\n"
14143 " gl_Position = vec4(1);\n"
14144 "}\n";
14145 char const *fsSource =
14146 "#version 450\n"
14147 "\n"
14148 "layout(location=0) in float x;\n" /* VS writes int */
14149 "layout(location=0) out vec4 color;\n"
14150 "void main(){\n"
14151 " color = vec4(x);\n"
14152 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014153
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014156
14157 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014158 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
Chris Forbesb56af562015-05-25 11:13:17 +120014162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014165
Tony Barbour5781e8f2015-08-04 16:23:11 -060014166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014169}
14170
Karl Schultz6addd812016-02-02 17:17:23 -070014171TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014172 TEST_DESCRIPTION(
14173 "Test that an error is produced for mismatched types across "
14174 "the vertex->fragment shader interface, when the variable is contained within "
14175 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014177
14178 ASSERT_NO_FATAL_FAILURE(InitState());
14179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014181 char const *vsSource =
14182 "#version 450\n"
14183 "\n"
14184 "out block { layout(location=0) int x; } outs;\n"
14185 "out gl_PerVertex {\n"
14186 " vec4 gl_Position;\n"
14187 "};\n"
14188 "void main(){\n"
14189 " outs.x = 0;\n"
14190 " gl_Position = vec4(1);\n"
14191 "}\n";
14192 char const *fsSource =
14193 "#version 450\n"
14194 "\n"
14195 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14196 "layout(location=0) out vec4 color;\n"
14197 "void main(){\n"
14198 " color = vec4(ins.x);\n"
14199 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014200
14201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14203
14204 VkPipelineObj pipe(m_device);
14205 pipe.AddColorAttachment();
14206 pipe.AddShader(&vs);
14207 pipe.AddShader(&fs);
14208
14209 VkDescriptorSetObj descriptorSet(m_device);
14210 descriptorSet.AppendDummy();
14211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14212
14213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014215 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014216}
14217
14218TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014219 TEST_DESCRIPTION(
14220 "Test that an error is produced for location mismatches across "
14221 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14222 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 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 +130014224
14225 ASSERT_NO_FATAL_FAILURE(InitState());
14226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014228 char const *vsSource =
14229 "#version 450\n"
14230 "\n"
14231 "out block { layout(location=1) float x; } outs;\n"
14232 "out gl_PerVertex {\n"
14233 " vec4 gl_Position;\n"
14234 "};\n"
14235 "void main(){\n"
14236 " outs.x = 0;\n"
14237 " gl_Position = vec4(1);\n"
14238 "}\n";
14239 char const *fsSource =
14240 "#version 450\n"
14241 "\n"
14242 "in block { layout(location=0) float x; } ins;\n"
14243 "layout(location=0) out vec4 color;\n"
14244 "void main(){\n"
14245 " color = vec4(ins.x);\n"
14246 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014247
14248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14250
14251 VkPipelineObj pipe(m_device);
14252 pipe.AddColorAttachment();
14253 pipe.AddShader(&vs);
14254 pipe.AddShader(&fs);
14255
14256 VkDescriptorSetObj descriptorSet(m_device);
14257 descriptorSet.AppendDummy();
14258 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14259
14260 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014262 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014263}
14264
14265TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014266 TEST_DESCRIPTION(
14267 "Test that an error is produced for component mismatches across the "
14268 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14269 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014270 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 +130014271
14272 ASSERT_NO_FATAL_FAILURE(InitState());
14273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14274
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014275 char const *vsSource =
14276 "#version 450\n"
14277 "\n"
14278 "out block { layout(location=0, component=0) float x; } outs;\n"
14279 "out gl_PerVertex {\n"
14280 " vec4 gl_Position;\n"
14281 "};\n"
14282 "void main(){\n"
14283 " outs.x = 0;\n"
14284 " gl_Position = vec4(1);\n"
14285 "}\n";
14286 char const *fsSource =
14287 "#version 450\n"
14288 "\n"
14289 "in block { layout(location=0, component=1) float x; } ins;\n"
14290 "layout(location=0) out vec4 color;\n"
14291 "void main(){\n"
14292 " color = vec4(ins.x);\n"
14293 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014294
14295 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14296 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14297
14298 VkPipelineObj pipe(m_device);
14299 pipe.AddColorAttachment();
14300 pipe.AddShader(&vs);
14301 pipe.AddShader(&fs);
14302
14303 VkDescriptorSetObj descriptorSet(m_device);
14304 descriptorSet.AppendDummy();
14305 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14306
14307 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014309 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014310}
14311
Chris Forbes1f3b0152016-11-30 12:48:40 +130014312TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14313 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14314
14315 ASSERT_NO_FATAL_FAILURE(InitState());
14316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14317
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014318 char const *vsSource =
14319 "#version 450\n"
14320 "layout(location=0) out mediump float x;\n"
14321 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14322 char const *fsSource =
14323 "#version 450\n"
14324 "layout(location=0) in highp float x;\n"
14325 "layout(location=0) out vec4 color;\n"
14326 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014327
14328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14330
14331 VkPipelineObj pipe(m_device);
14332 pipe.AddColorAttachment();
14333 pipe.AddShader(&vs);
14334 pipe.AddShader(&fs);
14335
14336 VkDescriptorSetObj descriptorSet(m_device);
14337 descriptorSet.AppendDummy();
14338 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14339
14340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14341
14342 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14343
14344 m_errorMonitor->VerifyFound();
14345}
14346
Chris Forbes870a39e2016-11-30 12:55:56 +130014347TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14348 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
14351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014353 char const *vsSource =
14354 "#version 450\n"
14355 "out block { layout(location=0) mediump float x; };\n"
14356 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14357 char const *fsSource =
14358 "#version 450\n"
14359 "in block { layout(location=0) highp float x; };\n"
14360 "layout(location=0) out vec4 color;\n"
14361 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014362
14363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14365
14366 VkPipelineObj pipe(m_device);
14367 pipe.AddColorAttachment();
14368 pipe.AddShader(&vs);
14369 pipe.AddShader(&fs);
14370
14371 VkDescriptorSetObj descriptorSet(m_device);
14372 descriptorSet.AppendDummy();
14373 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14374
14375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14376
14377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14378
14379 m_errorMonitor->VerifyFound();
14380}
14381
Karl Schultz6addd812016-02-02 17:17:23 -070014382TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014383 TEST_DESCRIPTION(
14384 "Test that a warning is produced for a vertex attribute which is "
14385 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014387
Chris Forbesde136e02015-05-25 11:13:28 +120014388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014390
14391 VkVertexInputBindingDescription input_binding;
14392 memset(&input_binding, 0, sizeof(input_binding));
14393
14394 VkVertexInputAttributeDescription input_attrib;
14395 memset(&input_attrib, 0, sizeof(input_attrib));
14396 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14397
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014398 char const *vsSource =
14399 "#version 450\n"
14400 "\n"
14401 "out gl_PerVertex {\n"
14402 " vec4 gl_Position;\n"
14403 "};\n"
14404 "void main(){\n"
14405 " gl_Position = vec4(1);\n"
14406 "}\n";
14407 char const *fsSource =
14408 "#version 450\n"
14409 "\n"
14410 "layout(location=0) out vec4 color;\n"
14411 "void main(){\n"
14412 " color = vec4(1);\n"
14413 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014414
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014415 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14416 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014417
14418 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014419 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014420 pipe.AddShader(&vs);
14421 pipe.AddShader(&fs);
14422
14423 pipe.AddVertexInputBindings(&input_binding, 1);
14424 pipe.AddVertexInputAttribs(&input_attrib, 1);
14425
Chris Forbesde136e02015-05-25 11:13:28 +120014426 VkDescriptorSetObj descriptorSet(m_device);
14427 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014429
Tony Barbour5781e8f2015-08-04 16:23:11 -060014430 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014431
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014432 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014433}
14434
Karl Schultz6addd812016-02-02 17:17:23 -070014435TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014436 TEST_DESCRIPTION(
14437 "Test that a warning is produced for a location mismatch on "
14438 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014440
14441 ASSERT_NO_FATAL_FAILURE(InitState());
14442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14443
14444 VkVertexInputBindingDescription input_binding;
14445 memset(&input_binding, 0, sizeof(input_binding));
14446
14447 VkVertexInputAttributeDescription input_attrib;
14448 memset(&input_attrib, 0, sizeof(input_attrib));
14449 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14450
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014451 char const *vsSource =
14452 "#version 450\n"
14453 "\n"
14454 "layout(location=1) in float x;\n"
14455 "out gl_PerVertex {\n"
14456 " vec4 gl_Position;\n"
14457 "};\n"
14458 "void main(){\n"
14459 " gl_Position = vec4(x);\n"
14460 "}\n";
14461 char const *fsSource =
14462 "#version 450\n"
14463 "\n"
14464 "layout(location=0) out vec4 color;\n"
14465 "void main(){\n"
14466 " color = vec4(1);\n"
14467 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014468
14469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14471
14472 VkPipelineObj pipe(m_device);
14473 pipe.AddColorAttachment();
14474 pipe.AddShader(&vs);
14475 pipe.AddShader(&fs);
14476
14477 pipe.AddVertexInputBindings(&input_binding, 1);
14478 pipe.AddVertexInputAttribs(&input_attrib, 1);
14479
14480 VkDescriptorSetObj descriptorSet(m_device);
14481 descriptorSet.AppendDummy();
14482 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14483
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014484 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014485 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14486
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014487 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014488}
14489
Karl Schultz6addd812016-02-02 17:17:23 -070014490TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014491 TEST_DESCRIPTION(
14492 "Test that an error is produced for a vertex shader input which is not "
14493 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14495 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014496
Chris Forbes62e8e502015-05-25 11:13:29 +120014497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 char const *vsSource =
14501 "#version 450\n"
14502 "\n"
14503 "layout(location=0) in vec4 x;\n" /* not provided */
14504 "out gl_PerVertex {\n"
14505 " vec4 gl_Position;\n"
14506 "};\n"
14507 "void main(){\n"
14508 " gl_Position = x;\n"
14509 "}\n";
14510 char const *fsSource =
14511 "#version 450\n"
14512 "\n"
14513 "layout(location=0) out vec4 color;\n"
14514 "void main(){\n"
14515 " color = vec4(1);\n"
14516 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014520
14521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014522 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014523 pipe.AddShader(&vs);
14524 pipe.AddShader(&fs);
14525
Chris Forbes62e8e502015-05-25 11:13:29 +120014526 VkDescriptorSetObj descriptorSet(m_device);
14527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014529
Tony Barbour5781e8f2015-08-04 16:23:11 -060014530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014532 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014533}
14534
Karl Schultz6addd812016-02-02 17:17:23 -070014535TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014536 TEST_DESCRIPTION(
14537 "Test that an error is produced for a mismatch between the "
14538 "fundamental type (float/int/uint) of an attribute and the "
14539 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014540 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 -060014541
Chris Forbesc97d98e2015-05-25 11:13:31 +120014542 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014544
14545 VkVertexInputBindingDescription input_binding;
14546 memset(&input_binding, 0, sizeof(input_binding));
14547
14548 VkVertexInputAttributeDescription input_attrib;
14549 memset(&input_attrib, 0, sizeof(input_attrib));
14550 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14551
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014552 char const *vsSource =
14553 "#version 450\n"
14554 "\n"
14555 "layout(location=0) in int x;\n" /* attrib provided float */
14556 "out gl_PerVertex {\n"
14557 " vec4 gl_Position;\n"
14558 "};\n"
14559 "void main(){\n"
14560 " gl_Position = vec4(x);\n"
14561 "}\n";
14562 char const *fsSource =
14563 "#version 450\n"
14564 "\n"
14565 "layout(location=0) out vec4 color;\n"
14566 "void main(){\n"
14567 " color = vec4(1);\n"
14568 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014569
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014572
14573 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014574 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014575 pipe.AddShader(&vs);
14576 pipe.AddShader(&fs);
14577
14578 pipe.AddVertexInputBindings(&input_binding, 1);
14579 pipe.AddVertexInputAttribs(&input_attrib, 1);
14580
Chris Forbesc97d98e2015-05-25 11:13:31 +120014581 VkDescriptorSetObj descriptorSet(m_device);
14582 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014583 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014584
Tony Barbour5781e8f2015-08-04 16:23:11 -060014585 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014586
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014587 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014588}
14589
Chris Forbesc68b43c2016-04-06 11:18:47 +120014590TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014591 TEST_DESCRIPTION(
14592 "Test that an error is produced for a pipeline containing multiple "
14593 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14595 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014596
14597 ASSERT_NO_FATAL_FAILURE(InitState());
14598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14599
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014600 char const *vsSource =
14601 "#version 450\n"
14602 "\n"
14603 "out gl_PerVertex {\n"
14604 " vec4 gl_Position;\n"
14605 "};\n"
14606 "void main(){\n"
14607 " gl_Position = vec4(1);\n"
14608 "}\n";
14609 char const *fsSource =
14610 "#version 450\n"
14611 "\n"
14612 "layout(location=0) out vec4 color;\n"
14613 "void main(){\n"
14614 " color = vec4(1);\n"
14615 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014616
14617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14619
14620 VkPipelineObj pipe(m_device);
14621 pipe.AddColorAttachment();
14622 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014623 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014624 pipe.AddShader(&fs);
14625
14626 VkDescriptorSetObj descriptorSet(m_device);
14627 descriptorSet.AppendDummy();
14628 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14629
14630 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14631
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014632 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014633}
14634
Chris Forbes82ff92a2016-09-09 10:50:24 +120014635TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014637
14638 ASSERT_NO_FATAL_FAILURE(InitState());
14639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14640
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014641 char const *vsSource =
14642 "#version 450\n"
14643 "out gl_PerVertex {\n"
14644 " vec4 gl_Position;\n"
14645 "};\n"
14646 "void main(){\n"
14647 " gl_Position = vec4(0);\n"
14648 "}\n";
14649 char const *fsSource =
14650 "#version 450\n"
14651 "\n"
14652 "layout(location=0) out vec4 color;\n"
14653 "void main(){\n"
14654 " color = vec4(1);\n"
14655 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014656
14657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14659
14660 VkPipelineObj pipe(m_device);
14661 pipe.AddColorAttachment();
14662 pipe.AddShader(&vs);
14663 pipe.AddShader(&fs);
14664
14665 VkDescriptorSetObj descriptorSet(m_device);
14666 descriptorSet.AppendDummy();
14667 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14668
14669 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14670
14671 m_errorMonitor->VerifyFound();
14672}
14673
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014674TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14676 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14677 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014678
14679 ASSERT_NO_FATAL_FAILURE(InitState());
14680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14681
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014682 char const *vsSource =
14683 "#version 450\n"
14684 "void main(){ gl_Position = vec4(0); }\n";
14685 char const *fsSource =
14686 "#version 450\n"
14687 "\n"
14688 "layout(location=0) out vec4 color;\n"
14689 "void main(){\n"
14690 " color = vec4(1);\n"
14691 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014692
14693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14695
14696 VkPipelineObj pipe(m_device);
14697 pipe.AddColorAttachment();
14698 pipe.AddShader(&vs);
14699 pipe.AddShader(&fs);
14700
14701 VkDescriptorSetObj descriptorSet(m_device);
14702 descriptorSet.AppendDummy();
14703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14704
14705 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014706 {
14707 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14708 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14709 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014710 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014711 {
14712 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14714 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014715 },
14716 };
14717 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014718 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014719 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014720 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14721 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014722 VkRenderPass rp;
14723 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14724 ASSERT_VK_SUCCESS(err);
14725
14726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14727
14728 m_errorMonitor->VerifyFound();
14729
14730 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14731}
14732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014734 TEST_DESCRIPTION(
14735 "Test that an error is produced for a variable output from "
14736 "the TCS without the patch decoration, but consumed in the TES "
14737 "with the decoration.");
14738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14739 "is per-vertex in tessellation control shader stage "
14740 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014741
14742 ASSERT_NO_FATAL_FAILURE(InitState());
14743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14744
Chris Forbesc1e852d2016-04-04 19:26:42 +120014745 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014746 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014747 return;
14748 }
14749
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014750 char const *vsSource =
14751 "#version 450\n"
14752 "void main(){}\n";
14753 char const *tcsSource =
14754 "#version 450\n"
14755 "layout(location=0) out int x[];\n"
14756 "layout(vertices=3) out;\n"
14757 "void main(){\n"
14758 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14759 " gl_TessLevelInner[0] = 1;\n"
14760 " x[gl_InvocationID] = gl_InvocationID;\n"
14761 "}\n";
14762 char const *tesSource =
14763 "#version 450\n"
14764 "layout(triangles, equal_spacing, cw) in;\n"
14765 "layout(location=0) patch in int x;\n"
14766 "out gl_PerVertex { vec4 gl_Position; };\n"
14767 "void main(){\n"
14768 " gl_Position.xyz = gl_TessCoord;\n"
14769 " gl_Position.w = x;\n"
14770 "}\n";
14771 char const *fsSource =
14772 "#version 450\n"
14773 "layout(location=0) out vec4 color;\n"
14774 "void main(){\n"
14775 " color = vec4(1);\n"
14776 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014777
14778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14779 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14780 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014783 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14784 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014786 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014787
14788 VkPipelineObj pipe(m_device);
14789 pipe.SetInputAssembly(&iasci);
14790 pipe.SetTessellation(&tsci);
14791 pipe.AddColorAttachment();
14792 pipe.AddShader(&vs);
14793 pipe.AddShader(&tcs);
14794 pipe.AddShader(&tes);
14795 pipe.AddShader(&fs);
14796
14797 VkDescriptorSetObj descriptorSet(m_device);
14798 descriptorSet.AppendDummy();
14799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14800
14801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14802
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014803 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014804}
14805
Karl Schultz6addd812016-02-02 17:17:23 -070014806TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014807 TEST_DESCRIPTION(
14808 "Test that an error is produced for a vertex attribute setup where multiple "
14809 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14811 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014812
Chris Forbes280ba2c2015-06-12 11:16:41 +120014813 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014815
14816 /* Two binding descriptions for binding 0 */
14817 VkVertexInputBindingDescription input_bindings[2];
14818 memset(input_bindings, 0, sizeof(input_bindings));
14819
14820 VkVertexInputAttributeDescription input_attrib;
14821 memset(&input_attrib, 0, sizeof(input_attrib));
14822 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014824 char const *vsSource =
14825 "#version 450\n"
14826 "\n"
14827 "layout(location=0) in float x;\n" /* attrib provided float */
14828 "out gl_PerVertex {\n"
14829 " vec4 gl_Position;\n"
14830 "};\n"
14831 "void main(){\n"
14832 " gl_Position = vec4(x);\n"
14833 "}\n";
14834 char const *fsSource =
14835 "#version 450\n"
14836 "\n"
14837 "layout(location=0) out vec4 color;\n"
14838 "void main(){\n"
14839 " color = vec4(1);\n"
14840 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014841
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014844
14845 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014846 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014847 pipe.AddShader(&vs);
14848 pipe.AddShader(&fs);
14849
14850 pipe.AddVertexInputBindings(input_bindings, 2);
14851 pipe.AddVertexInputAttribs(&input_attrib, 1);
14852
Chris Forbes280ba2c2015-06-12 11:16:41 +120014853 VkDescriptorSetObj descriptorSet(m_device);
14854 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014855 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014856
Tony Barbour5781e8f2015-08-04 16:23:11 -060014857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014859 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014860}
Chris Forbes8f68b562015-05-25 11:13:32 +120014861
Karl Schultz6addd812016-02-02 17:17:23 -070014862TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014863 TEST_DESCRIPTION(
14864 "Test that an error is produced for a fragment shader which does not "
14865 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014867
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014868 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014869
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014870 char const *vsSource =
14871 "#version 450\n"
14872 "\n"
14873 "out gl_PerVertex {\n"
14874 " vec4 gl_Position;\n"
14875 "};\n"
14876 "void main(){\n"
14877 " gl_Position = vec4(1);\n"
14878 "}\n";
14879 char const *fsSource =
14880 "#version 450\n"
14881 "\n"
14882 "void main(){\n"
14883 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014884
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014887
14888 VkPipelineObj pipe(m_device);
14889 pipe.AddShader(&vs);
14890 pipe.AddShader(&fs);
14891
Chia-I Wu08accc62015-07-07 11:50:03 +080014892 /* set up CB 0, not written */
14893 pipe.AddColorAttachment();
14894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014895
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014896 VkDescriptorSetObj descriptorSet(m_device);
14897 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014899
Tony Barbour5781e8f2015-08-04 16:23:11 -060014900 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014902 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014903}
14904
Karl Schultz6addd812016-02-02 17:17:23 -070014905TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014906 TEST_DESCRIPTION(
14907 "Test that a warning is produced for a fragment shader which provides a spurious "
14908 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014910 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014911
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014912 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014914 char const *vsSource =
14915 "#version 450\n"
14916 "\n"
14917 "out gl_PerVertex {\n"
14918 " vec4 gl_Position;\n"
14919 "};\n"
14920 "void main(){\n"
14921 " gl_Position = vec4(1);\n"
14922 "}\n";
14923 char const *fsSource =
14924 "#version 450\n"
14925 "\n"
14926 "layout(location=0) out vec4 x;\n"
14927 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14928 "void main(){\n"
14929 " x = vec4(1);\n"
14930 " y = vec4(1);\n"
14931 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014932
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014935
14936 VkPipelineObj pipe(m_device);
14937 pipe.AddShader(&vs);
14938 pipe.AddShader(&fs);
14939
Chia-I Wu08accc62015-07-07 11:50:03 +080014940 /* set up CB 0, not written */
14941 pipe.AddColorAttachment();
14942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014943 /* FS writes CB 1, but we don't configure it */
14944
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014945 VkDescriptorSetObj descriptorSet(m_device);
14946 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014948
Tony Barbour5781e8f2015-08-04 16:23:11 -060014949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014951 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014952}
14953
Karl Schultz6addd812016-02-02 17:17:23 -070014954TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014955 TEST_DESCRIPTION(
14956 "Test that an error is produced for a mismatch between the fundamental "
14957 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014959
Chris Forbesa36d69e2015-05-25 11:13:44 +120014960 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014961
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014962 char const *vsSource =
14963 "#version 450\n"
14964 "\n"
14965 "out gl_PerVertex {\n"
14966 " vec4 gl_Position;\n"
14967 "};\n"
14968 "void main(){\n"
14969 " gl_Position = vec4(1);\n"
14970 "}\n";
14971 char const *fsSource =
14972 "#version 450\n"
14973 "\n"
14974 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14975 "void main(){\n"
14976 " x = ivec4(1);\n"
14977 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014978
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014981
14982 VkPipelineObj pipe(m_device);
14983 pipe.AddShader(&vs);
14984 pipe.AddShader(&fs);
14985
Chia-I Wu08accc62015-07-07 11:50:03 +080014986 /* set up CB 0; type is UNORM by default */
14987 pipe.AddColorAttachment();
14988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014989
Chris Forbesa36d69e2015-05-25 11:13:44 +120014990 VkDescriptorSetObj descriptorSet(m_device);
14991 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014993
Tony Barbour5781e8f2015-08-04 16:23:11 -060014994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014995
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014996 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014997}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014998
Karl Schultz6addd812016-02-02 17:17:23 -070014999TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015000 TEST_DESCRIPTION(
15001 "Test that an error is produced for a shader consuming a uniform "
15002 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015004
Chris Forbes556c76c2015-08-14 12:04:59 +120015005 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015006
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015007 char const *vsSource =
15008 "#version 450\n"
15009 "\n"
15010 "out gl_PerVertex {\n"
15011 " vec4 gl_Position;\n"
15012 "};\n"
15013 "void main(){\n"
15014 " gl_Position = vec4(1);\n"
15015 "}\n";
15016 char const *fsSource =
15017 "#version 450\n"
15018 "\n"
15019 "layout(location=0) out vec4 x;\n"
15020 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15021 "void main(){\n"
15022 " x = vec4(bar.y);\n"
15023 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015024
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015027
Chris Forbes556c76c2015-08-14 12:04:59 +120015028 VkPipelineObj pipe(m_device);
15029 pipe.AddShader(&vs);
15030 pipe.AddShader(&fs);
15031
15032 /* set up CB 0; type is UNORM by default */
15033 pipe.AddColorAttachment();
15034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15035
15036 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015038
15039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015041 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015042}
15043
Chris Forbes5c59e902016-02-26 16:56:09 +130015044TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015045 TEST_DESCRIPTION(
15046 "Test that an error is produced for a shader consuming push constants "
15047 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015049
15050 ASSERT_NO_FATAL_FAILURE(InitState());
15051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015052 char const *vsSource =
15053 "#version 450\n"
15054 "\n"
15055 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15056 "out gl_PerVertex {\n"
15057 " vec4 gl_Position;\n"
15058 "};\n"
15059 "void main(){\n"
15060 " gl_Position = vec4(consts.x);\n"
15061 "}\n";
15062 char const *fsSource =
15063 "#version 450\n"
15064 "\n"
15065 "layout(location=0) out vec4 x;\n"
15066 "void main(){\n"
15067 " x = vec4(1);\n"
15068 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015069
15070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15072
15073 VkPipelineObj pipe(m_device);
15074 pipe.AddShader(&vs);
15075 pipe.AddShader(&fs);
15076
15077 /* set up CB 0; type is UNORM by default */
15078 pipe.AddColorAttachment();
15079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15080
15081 VkDescriptorSetObj descriptorSet(m_device);
15082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15083
15084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15085
15086 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015087 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015088}
15089
Chris Forbes3fb17902016-08-22 14:57:55 +120015090TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015091 TEST_DESCRIPTION(
15092 "Test that an error is produced for a shader consuming an input attachment "
15093 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15095 "consumes input attachment index 0 but not provided in subpass");
15096
15097 ASSERT_NO_FATAL_FAILURE(InitState());
15098
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015099 char const *vsSource =
15100 "#version 450\n"
15101 "\n"
15102 "out gl_PerVertex {\n"
15103 " vec4 gl_Position;\n"
15104 "};\n"
15105 "void main(){\n"
15106 " gl_Position = vec4(1);\n"
15107 "}\n";
15108 char const *fsSource =
15109 "#version 450\n"
15110 "\n"
15111 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15112 "layout(location=0) out vec4 color;\n"
15113 "void main() {\n"
15114 " color = subpassLoad(x);\n"
15115 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015116
15117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15119
15120 VkPipelineObj pipe(m_device);
15121 pipe.AddShader(&vs);
15122 pipe.AddShader(&fs);
15123 pipe.AddColorAttachment();
15124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015126 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15127 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015128 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015130 ASSERT_VK_SUCCESS(err);
15131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015133 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015135 ASSERT_VK_SUCCESS(err);
15136
15137 // error here.
15138 pipe.CreateVKPipeline(pl, renderPass());
15139
15140 m_errorMonitor->VerifyFound();
15141
15142 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15143 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15144}
15145
Chris Forbes5a9a0472016-08-22 16:02:09 +120015146TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015147 TEST_DESCRIPTION(
15148 "Test that an error is produced for a shader consuming an input attachment "
15149 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15151 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15152
15153 ASSERT_NO_FATAL_FAILURE(InitState());
15154
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015155 char const *vsSource =
15156 "#version 450\n"
15157 "\n"
15158 "out gl_PerVertex {\n"
15159 " vec4 gl_Position;\n"
15160 "};\n"
15161 "void main(){\n"
15162 " gl_Position = vec4(1);\n"
15163 "}\n";
15164 char const *fsSource =
15165 "#version 450\n"
15166 "\n"
15167 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15168 "layout(location=0) out vec4 color;\n"
15169 "void main() {\n"
15170 " color = subpassLoad(x);\n"
15171 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015172
15173 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15174 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15175
15176 VkPipelineObj pipe(m_device);
15177 pipe.AddShader(&vs);
15178 pipe.AddShader(&fs);
15179 pipe.AddColorAttachment();
15180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15183 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015184 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015186 ASSERT_VK_SUCCESS(err);
15187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015188 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015189 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015191 ASSERT_VK_SUCCESS(err);
15192
15193 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15195 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15196 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15197 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15198 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 +120015199 };
15200 VkAttachmentReference color = {
15201 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15202 };
15203 VkAttachmentReference input = {
15204 1, VK_IMAGE_LAYOUT_GENERAL,
15205 };
15206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015210 VkRenderPass rp;
15211 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15212 ASSERT_VK_SUCCESS(err);
15213
15214 // error here.
15215 pipe.CreateVKPipeline(pl, rp);
15216
15217 m_errorMonitor->VerifyFound();
15218
15219 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15220 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15221 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15222}
15223
Chris Forbes541f7b02016-08-22 15:30:27 +120015224TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015225 TEST_DESCRIPTION(
15226 "Test that an error is produced for a shader consuming an input attachment "
15227 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015229 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015230
15231 ASSERT_NO_FATAL_FAILURE(InitState());
15232
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015233 char const *vsSource =
15234 "#version 450\n"
15235 "\n"
15236 "out gl_PerVertex {\n"
15237 " vec4 gl_Position;\n"
15238 "};\n"
15239 "void main(){\n"
15240 " gl_Position = vec4(1);\n"
15241 "}\n";
15242 char const *fsSource =
15243 "#version 450\n"
15244 "\n"
15245 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15246 "layout(location=0) out vec4 color;\n"
15247 "void main() {\n"
15248 " color = subpassLoad(xs[0]);\n"
15249 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015250
15251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15253
15254 VkPipelineObj pipe(m_device);
15255 pipe.AddShader(&vs);
15256 pipe.AddShader(&fs);
15257 pipe.AddColorAttachment();
15258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15261 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015262 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015264 ASSERT_VK_SUCCESS(err);
15265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015267 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015269 ASSERT_VK_SUCCESS(err);
15270
15271 // error here.
15272 pipe.CreateVKPipeline(pl, renderPass());
15273
15274 m_errorMonitor->VerifyFound();
15275
15276 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15277 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15278}
15279
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015280TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015281 TEST_DESCRIPTION(
15282 "Test that an error is produced for a compute pipeline consuming a "
15283 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015285
15286 ASSERT_NO_FATAL_FAILURE(InitState());
15287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015288 char const *csSource =
15289 "#version 450\n"
15290 "\n"
15291 "layout(local_size_x=1) in;\n"
15292 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15293 "void main(){\n"
15294 " x = vec4(1);\n"
15295 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015296
15297 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15298
15299 VkDescriptorSetObj descriptorSet(m_device);
15300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015302 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15303 nullptr,
15304 0,
15305 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15306 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15307 descriptorSet.GetPipelineLayout(),
15308 VK_NULL_HANDLE,
15309 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015310
15311 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015312 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015313
15314 m_errorMonitor->VerifyFound();
15315
15316 if (err == VK_SUCCESS) {
15317 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15318 }
15319}
15320
Chris Forbes22a9b092016-07-19 14:34:05 +120015321TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015322 TEST_DESCRIPTION(
15323 "Test that an error is produced for a pipeline consuming a "
15324 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15326 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015327
15328 ASSERT_NO_FATAL_FAILURE(InitState());
15329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015330 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15331 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015332 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015333 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015334 ASSERT_VK_SUCCESS(err);
15335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015337 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015339 ASSERT_VK_SUCCESS(err);
15340
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015341 char const *csSource =
15342 "#version 450\n"
15343 "\n"
15344 "layout(local_size_x=1) in;\n"
15345 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15346 "void main() {\n"
15347 " x.x = 1.0f;\n"
15348 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015349 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15352 nullptr,
15353 0,
15354 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15355 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15356 pl,
15357 VK_NULL_HANDLE,
15358 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015359
15360 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015361 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015362
15363 m_errorMonitor->VerifyFound();
15364
15365 if (err == VK_SUCCESS) {
15366 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15367 }
15368
15369 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15370 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15371}
15372
Chris Forbes50020592016-07-27 13:52:41 +120015373TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015374 TEST_DESCRIPTION(
15375 "Test that an error is produced when an image view type "
15376 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015378 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 +120015379
15380 ASSERT_NO_FATAL_FAILURE(InitState());
15381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15382
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015383 char const *vsSource =
15384 "#version 450\n"
15385 "\n"
15386 "out gl_PerVertex { vec4 gl_Position; };\n"
15387 "void main() { gl_Position = vec4(0); }\n";
15388 char const *fsSource =
15389 "#version 450\n"
15390 "\n"
15391 "layout(set=0, binding=0) uniform sampler3D s;\n"
15392 "layout(location=0) out vec4 color;\n"
15393 "void main() {\n"
15394 " color = texture(s, vec3(0));\n"
15395 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15398
15399 VkPipelineObj pipe(m_device);
15400 pipe.AddShader(&vs);
15401 pipe.AddShader(&fs);
15402 pipe.AddColorAttachment();
15403
15404 VkTextureObj texture(m_device, nullptr);
15405 VkSamplerObj sampler(m_device);
15406
15407 VkDescriptorSetObj descriptorSet(m_device);
15408 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15409 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15410
15411 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15412 ASSERT_VK_SUCCESS(err);
15413
Tony Barbour552f6c02016-12-21 14:34:07 -070015414 m_commandBuffer->BeginCommandBuffer();
15415 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015416
15417 m_commandBuffer->BindPipeline(pipe);
15418 m_commandBuffer->BindDescriptorSet(descriptorSet);
15419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015420 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015421 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015422 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015423 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15424
15425 // error produced here.
15426 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15427
15428 m_errorMonitor->VerifyFound();
15429
Tony Barbour552f6c02016-12-21 14:34:07 -070015430 m_commandBuffer->EndRenderPass();
15431 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015432}
15433
Chris Forbes5533bfc2016-07-27 14:12:34 +120015434TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015435 TEST_DESCRIPTION(
15436 "Test that an error is produced when a multisampled images "
15437 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15443
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015444 char const *vsSource =
15445 "#version 450\n"
15446 "\n"
15447 "out gl_PerVertex { vec4 gl_Position; };\n"
15448 "void main() { gl_Position = vec4(0); }\n";
15449 char const *fsSource =
15450 "#version 450\n"
15451 "\n"
15452 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15453 "layout(location=0) out vec4 color;\n"
15454 "void main() {\n"
15455 " color = texelFetch(s, ivec2(0), 0);\n"
15456 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15459
15460 VkPipelineObj pipe(m_device);
15461 pipe.AddShader(&vs);
15462 pipe.AddShader(&fs);
15463 pipe.AddColorAttachment();
15464
15465 VkTextureObj texture(m_device, nullptr);
15466 VkSamplerObj sampler(m_device);
15467
15468 VkDescriptorSetObj descriptorSet(m_device);
15469 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15470 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15471
15472 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15473 ASSERT_VK_SUCCESS(err);
15474
Tony Barbour552f6c02016-12-21 14:34:07 -070015475 m_commandBuffer->BeginCommandBuffer();
15476 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015477
15478 m_commandBuffer->BindPipeline(pipe);
15479 m_commandBuffer->BindDescriptorSet(descriptorSet);
15480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015482 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015484 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15485
15486 // error produced here.
15487 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15488
15489 m_errorMonitor->VerifyFound();
15490
Tony Barbour552f6c02016-12-21 14:34:07 -070015491 m_commandBuffer->EndRenderPass();
15492 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015493}
15494
Mark Youngc48c4c12016-04-11 14:26:49 -060015495TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015497
15498 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015499
15500 // Create an image
15501 VkImage image;
15502
Karl Schultz6addd812016-02-02 17:17:23 -070015503 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15504 const int32_t tex_width = 32;
15505 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015506
15507 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015508 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15509 image_create_info.pNext = NULL;
15510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15511 image_create_info.format = tex_format;
15512 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015513 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015514 image_create_info.extent.depth = 1;
15515 image_create_info.mipLevels = 1;
15516 image_create_info.arrayLayers = 1;
15517 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15518 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15519 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15520 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015521
15522 // Introduce error by sending down a bogus width extent
15523 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015524 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015526 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015527}
15528
Mark Youngc48c4c12016-04-11 14:26:49 -060015529TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015531
15532 ASSERT_NO_FATAL_FAILURE(InitState());
15533
15534 // Create an image
15535 VkImage image;
15536
15537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15538 const int32_t tex_width = 32;
15539 const int32_t tex_height = 32;
15540
15541 VkImageCreateInfo image_create_info = {};
15542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15543 image_create_info.pNext = NULL;
15544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15545 image_create_info.format = tex_format;
15546 image_create_info.extent.width = tex_width;
15547 image_create_info.extent.height = tex_height;
15548 image_create_info.extent.depth = 1;
15549 image_create_info.mipLevels = 1;
15550 image_create_info.arrayLayers = 1;
15551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15552 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15553 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15554 image_create_info.flags = 0;
15555
15556 // Introduce error by sending down a bogus width extent
15557 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015558 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015559 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15560
15561 m_errorMonitor->VerifyFound();
15562}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015563
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015564TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015565 TEST_DESCRIPTION(
15566 "Create a render pass with an attachment description "
15567 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015568
15569 ASSERT_NO_FATAL_FAILURE(InitState());
15570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15571
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015573
15574 VkAttachmentReference color_attach = {};
15575 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15576 color_attach.attachment = 0;
15577 VkSubpassDescription subpass = {};
15578 subpass.colorAttachmentCount = 1;
15579 subpass.pColorAttachments = &color_attach;
15580
15581 VkRenderPassCreateInfo rpci = {};
15582 rpci.subpassCount = 1;
15583 rpci.pSubpasses = &subpass;
15584 rpci.attachmentCount = 1;
15585 VkAttachmentDescription attach_desc = {};
15586 attach_desc.format = VK_FORMAT_UNDEFINED;
15587 rpci.pAttachments = &attach_desc;
15588 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15589 VkRenderPass rp;
15590 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15591
15592 m_errorMonitor->VerifyFound();
15593
15594 if (result == VK_SUCCESS) {
15595 vkDestroyRenderPass(m_device->device(), rp, NULL);
15596 }
15597}
15598
Karl Schultz6addd812016-02-02 17:17:23 -070015599TEST_F(VkLayerTest, InvalidImageView) {
Tobin Ehliscde08892015-09-22 10:11:37 -060015600 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015601
Mike Stroyana3082432015-09-25 13:39:21 -060015602 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015603 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15604 const int32_t tex_width = 32;
15605 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015606
15607 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015608 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15609 image_create_info.pNext = NULL;
15610 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15611 image_create_info.format = tex_format;
15612 image_create_info.extent.width = tex_width;
15613 image_create_info.extent.height = tex_height;
15614 image_create_info.extent.depth = 1;
15615 image_create_info.mipLevels = 1;
15616 image_create_info.arrayLayers = 1;
15617 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15618 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15619 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15620 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015621
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015622 VkImage image;
15623 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015624 ASSERT_VK_SUCCESS(err);
15625
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015626 VkMemoryRequirements requirements;
15627 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
15628
15629 VkMemoryAllocateInfo alloc_info{};
15630 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15631 alloc_info.pNext = NULL;
15632 alloc_info.memoryTypeIndex = 0;
15633 alloc_info.allocationSize = requirements.size;
15634 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15635 ASSERT_TRUE(pass);
15636
15637 VkDeviceMemory memory;
15638 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
15639 ASSERT_VK_SUCCESS(err);
15640
15641 err = vkBindImageMemory(m_device->device(), image, memory, 0);
15642
Tobin Ehliscde08892015-09-22 10:11:37 -060015643 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015644 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015645 image_view_create_info.image = image;
15646 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15647 image_view_create_info.format = tex_format;
15648 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015649 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015650 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015651 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015652
15653 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015656 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015657
15658 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060015659 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015660}
Mike Stroyana3082432015-09-25 13:39:21 -060015661
Mark Youngd339ba32016-05-30 13:28:35 -060015662TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15663 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015665 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015666
15667 ASSERT_NO_FATAL_FAILURE(InitState());
15668
15669 // Create an image and try to create a view with no memory backing the image
15670 VkImage image;
15671
15672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15673 const int32_t tex_width = 32;
15674 const int32_t tex_height = 32;
15675
15676 VkImageCreateInfo image_create_info = {};
15677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15678 image_create_info.pNext = NULL;
15679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15680 image_create_info.format = tex_format;
15681 image_create_info.extent.width = tex_width;
15682 image_create_info.extent.height = tex_height;
15683 image_create_info.extent.depth = 1;
15684 image_create_info.mipLevels = 1;
15685 image_create_info.arrayLayers = 1;
15686 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15687 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15688 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15689 image_create_info.flags = 0;
15690
15691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15692 ASSERT_VK_SUCCESS(err);
15693
15694 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015695 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015696 image_view_create_info.image = image;
15697 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15698 image_view_create_info.format = tex_format;
15699 image_view_create_info.subresourceRange.layerCount = 1;
15700 image_view_create_info.subresourceRange.baseMipLevel = 0;
15701 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015702 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015703
15704 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015705 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015706
15707 m_errorMonitor->VerifyFound();
15708 vkDestroyImage(m_device->device(), image, NULL);
15709 // If last error is success, it still created the view, so delete it.
15710 if (err == VK_SUCCESS) {
15711 vkDestroyImageView(m_device->device(), view, NULL);
15712 }
Mark Youngd339ba32016-05-30 13:28:35 -060015713}
15714
Karl Schultz6addd812016-02-02 17:17:23 -070015715TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015718
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015719 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015720
Karl Schultz6addd812016-02-02 17:17:23 -070015721 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015722 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015724 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015725
15726 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015727 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015728 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015729 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15730 image_view_create_info.format = tex_format;
15731 image_view_create_info.subresourceRange.baseMipLevel = 0;
15732 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015733 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015734 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015735 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015736
15737 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015738 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015739
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015740 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015741}
15742
Mike Weiblena1e13f42017-02-09 21:25:59 -070015743TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15744 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15745
15746 ASSERT_NO_FATAL_FAILURE(InitState());
15747 VkSubresourceLayout subres_layout = {};
15748
15749 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15750 {
15751 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15752 VkImageObj img(m_device);
15753 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15754 ASSERT_TRUE(img.initialized());
15755
15756 VkImageSubresource subres = {};
15757 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15758 subres.mipLevel = 0;
15759 subres.arrayLayer = 0;
15760
15761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15762 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15763 m_errorMonitor->VerifyFound();
15764 }
15765
15766 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15767 {
15768 VkImageObj img(m_device);
15769 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15770 ASSERT_TRUE(img.initialized());
15771
15772 VkImageSubresource subres = {};
15773 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15774 subres.mipLevel = 0;
15775 subres.arrayLayer = 0;
15776
15777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15779 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15780 m_errorMonitor->VerifyFound();
15781 }
15782
15783 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15784 {
15785 VkImageObj img(m_device);
15786 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15787 ASSERT_TRUE(img.initialized());
15788
15789 VkImageSubresource subres = {};
15790 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15791 subres.mipLevel = 1; // ERROR: triggers VU 00739
15792 subres.arrayLayer = 0;
15793
15794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15795 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15796 m_errorMonitor->VerifyFound();
15797 }
15798
15799 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15800 {
15801 VkImageObj img(m_device);
15802 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15803 ASSERT_TRUE(img.initialized());
15804
15805 VkImageSubresource subres = {};
15806 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15807 subres.mipLevel = 0;
15808 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15809
15810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15811 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15812 m_errorMonitor->VerifyFound();
15813 }
15814}
15815
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015816TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015817 VkResult err;
15818 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015819
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015821
Mike Stroyana3082432015-09-25 13:39:21 -060015822 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015823
15824 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015825 VkImage srcImage;
15826 VkImage dstImage;
15827 VkDeviceMemory srcMem;
15828 VkDeviceMemory destMem;
15829 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015830
15831 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015832 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15833 image_create_info.pNext = NULL;
15834 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15835 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15836 image_create_info.extent.width = 32;
15837 image_create_info.extent.height = 32;
15838 image_create_info.extent.depth = 1;
15839 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015840 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015841 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15842 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15843 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15844 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015847 ASSERT_VK_SUCCESS(err);
15848
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015849 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015851 ASSERT_VK_SUCCESS(err);
15852
15853 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015854 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015855 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15856 memAlloc.pNext = NULL;
15857 memAlloc.allocationSize = 0;
15858 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015859
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015860 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015861 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015862 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015863 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015864 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015865 ASSERT_VK_SUCCESS(err);
15866
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015867 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015868 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015869 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015870 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015871 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015872 ASSERT_VK_SUCCESS(err);
15873
15874 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15875 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015876 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015877 ASSERT_VK_SUCCESS(err);
15878
Tony Barbour552f6c02016-12-21 14:34:07 -070015879 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015880 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015881 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015882 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015883 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015884 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015885 copyRegion.srcOffset.x = 0;
15886 copyRegion.srcOffset.y = 0;
15887 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015888 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015889 copyRegion.dstSubresource.mipLevel = 0;
15890 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015891 // Introduce failure by forcing the dst layerCount to differ from src
15892 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015893 copyRegion.dstOffset.x = 0;
15894 copyRegion.dstOffset.y = 0;
15895 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015896 copyRegion.extent.width = 1;
15897 copyRegion.extent.height = 1;
15898 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015899 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015900 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015902 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015903
Chia-I Wuf7458c52015-10-26 21:10:41 +080015904 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015905 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015906 vkFreeMemory(m_device->device(), srcMem, NULL);
15907 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015908}
15909
Tony Barbourd6673642016-05-05 14:46:39 -060015910TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015911 TEST_DESCRIPTION("Creating images with unsuported formats ");
15912
15913 ASSERT_NO_FATAL_FAILURE(InitState());
15914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060015915
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015916 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015917 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15920 image_create_info.format = VK_FORMAT_UNDEFINED;
15921 image_create_info.extent.width = 32;
15922 image_create_info.extent.height = 32;
15923 image_create_info.extent.depth = 1;
15924 image_create_info.mipLevels = 1;
15925 image_create_info.arrayLayers = 1;
15926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15927 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15928 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15931 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015932
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015933 VkImage image;
15934 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015935 m_errorMonitor->VerifyFound();
15936
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015937 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015938 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060015939 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15940 VkFormat format = static_cast<VkFormat>(f);
15941 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015942 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015943 unsupported = format;
15944 break;
15945 }
15946 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015947
Tony Barbourd6673642016-05-05 14:46:39 -060015948 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015949 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015951
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015952 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060015953 m_errorMonitor->VerifyFound();
15954 }
15955}
15956
15957TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015958 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15959
15960 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015961 auto depth_format = find_depth_stencil_format(m_device);
15962 if (!depth_format) {
15963 return;
15964 }
Tony Barbourd6673642016-05-05 14:46:39 -060015965
15966 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015967 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 -060015968 VK_IMAGE_TILING_OPTIMAL, 0);
15969 ASSERT_TRUE(image.initialized());
15970
15971 VkImageView imgView;
15972 VkImageViewCreateInfo imgViewInfo = {};
15973 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15974 imgViewInfo.image = image.handle();
15975 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15976 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15977 imgViewInfo.subresourceRange.layerCount = 1;
15978 imgViewInfo.subresourceRange.baseMipLevel = 0;
15979 imgViewInfo.subresourceRange.levelCount = 1;
15980 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15981
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015982 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060015983 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015985 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15986 m_errorMonitor->VerifyFound();
15987 imgViewInfo.subresourceRange.baseMipLevel = 0;
15988
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015989 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060015990 imgViewInfo.subresourceRange.baseArrayLayer = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015992 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15993 m_errorMonitor->VerifyFound();
15994 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15995
Tony Barbourd6673642016-05-05 14:46:39 -060015996 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15997 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015999 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16000 m_errorMonitor->VerifyFound();
16001 imgViewInfo.subresourceRange.levelCount = 1;
16002
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016003 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16004 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016005 m_errorMonitor->SetDesiredFailureMsg(
16006 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16007 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016008 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16009 m_errorMonitor->VerifyFound();
16010 imgViewInfo.subresourceRange.layerCount = 1;
16011
Tony Barbourd6673642016-05-05 14:46:39 -060016012 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016013 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016014 m_errorMonitor->SetDesiredFailureMsg(
16015 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16016 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016017 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16018 m_errorMonitor->VerifyFound();
16019 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16020
Tony Barbourd6673642016-05-05 14:46:39 -060016021 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16022 // VIEW_CREATE_ERROR
16023 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016025 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16026 m_errorMonitor->VerifyFound();
16027 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16028
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016029 // TODO: Update framework to easily passing mutable flag into ImageObj init
16030 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016031 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16032 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16033 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016034 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16035 // VIEW_CREATE_ERROR
16036 VkImageCreateInfo mutImgInfo = image.create_info();
16037 VkImage mutImage;
16038 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016039 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016040 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16041 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016042 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016043 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016044
16045 VkMemoryRequirements requirements;
16046 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16047
16048 VkMemoryAllocateInfo alloc_info{};
16049 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16050 alloc_info.pNext = NULL;
16051 alloc_info.memoryTypeIndex = 0;
16052 alloc_info.allocationSize = requirements.size;
16053 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16054 ASSERT_TRUE(pass);
16055
16056 VkDeviceMemory memory;
16057 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16058 ASSERT_VK_SUCCESS(ret);
16059
16060 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16061 ASSERT_VK_SUCCESS(ret);
16062
Tony Barbourd6673642016-05-05 14:46:39 -060016063 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016065 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16066 m_errorMonitor->VerifyFound();
16067 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016068
16069 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016070 vkDestroyImage(m_device->handle(), mutImage, NULL);
16071}
16072
Dave Houlton75967fc2017-03-06 17:21:16 -070016073TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16074 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16075
16076 ASSERT_NO_FATAL_FAILURE(InitState());
16077
Jamie Madill35127872017-03-15 16:17:46 -040016078 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016079 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16080 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16081 if (device_features.textureCompressionBC) {
16082 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16083 } else if (device_features.textureCompressionETC2) {
16084 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16085 } else if (device_features.textureCompressionASTC_LDR) {
16086 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16087 } else {
16088 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16089 return;
16090 }
16091
16092 VkImageCreateInfo ci;
16093 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16094 ci.pNext = NULL;
16095 ci.flags = 0;
16096 ci.imageType = VK_IMAGE_TYPE_2D;
16097 ci.format = compressed_format;
16098 ci.extent = {32, 32, 1};
16099 ci.mipLevels = 6;
16100 ci.arrayLayers = 1;
16101 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16102 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16103 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16104 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16105 ci.queueFamilyIndexCount = 0;
16106 ci.pQueueFamilyIndices = NULL;
16107 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16108
16109 VkImageObj image(m_device);
16110 image.init(&ci);
16111 ASSERT_TRUE(image.initialized());
16112
16113 VkImageObj odd_image(m_device);
16114 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16115 odd_image.init(&ci);
16116 ASSERT_TRUE(odd_image.initialized());
16117
16118 // Allocate buffers
16119 VkMemoryPropertyFlags reqs = 0;
16120 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16121 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16122 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16123 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16124 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16125
16126 VkBufferImageCopy region = {};
16127 region.bufferRowLength = 0;
16128 region.bufferImageHeight = 0;
16129 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16130 region.imageSubresource.layerCount = 1;
16131 region.imageOffset = {0, 0, 0};
16132 region.bufferOffset = 0;
16133
16134 // start recording
16135 m_commandBuffer->BeginCommandBuffer();
16136
16137 // Mip level copies that work - 5 levels
16138 m_errorMonitor->ExpectSuccess();
16139
16140 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16141 region.imageExtent = {32, 32, 1};
16142 region.imageSubresource.mipLevel = 0;
16143 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16144 &region);
16145 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16146 &region);
16147
16148 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16149 region.imageExtent = {8, 8, 1};
16150 region.imageSubresource.mipLevel = 2;
16151 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16152 &region);
16153 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16154 &region);
16155
16156 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16157 region.imageExtent = {4, 4, 1};
16158 region.imageSubresource.mipLevel = 3;
16159 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16160 &region);
16161 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16162 &region);
16163
16164 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16165 region.imageExtent = {2, 2, 1};
16166 region.imageSubresource.mipLevel = 4;
16167 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16168 &region);
16169 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16170 &region);
16171
16172 region.imageExtent = {1, 1, 1};
16173 region.imageSubresource.mipLevel = 5;
16174 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16175 &region);
16176 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16177 &region);
16178 m_errorMonitor->VerifyNotFound();
16179
16180 // Buffer must accomodate a full compressed block, regardless of texel count
16181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16182 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16183 &region);
16184 m_errorMonitor->VerifyFound();
16185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16186 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16187 &region);
16188 m_errorMonitor->VerifyFound();
16189
16190 // Copy width < compressed block size, but not the full mip width
16191 region.imageExtent = {1, 2, 1};
16192 region.imageSubresource.mipLevel = 4;
16193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16194 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16195 &region);
16196 m_errorMonitor->VerifyFound();
16197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16198 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16199 &region);
16200 m_errorMonitor->VerifyFound();
16201
16202 // Copy height < compressed block size but not the full mip height
16203 region.imageExtent = {2, 1, 1};
16204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16205 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16206 &region);
16207 m_errorMonitor->VerifyFound();
16208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16210 &region);
16211 m_errorMonitor->VerifyFound();
16212
16213 // Offsets must be multiple of compressed block size
16214 region.imageOffset = {1, 1, 0};
16215 region.imageExtent = {1, 1, 1};
16216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16217 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16218 &region);
16219 m_errorMonitor->VerifyFound();
16220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16221 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16222 &region);
16223 m_errorMonitor->VerifyFound();
16224
16225 // Offset + extent width = mip width - should succeed
16226 region.imageOffset = {4, 4, 0};
16227 region.imageExtent = {3, 4, 1};
16228 region.imageSubresource.mipLevel = 2;
16229 m_errorMonitor->ExpectSuccess();
16230 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16231 &region);
16232 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16233 &region);
16234 m_errorMonitor->VerifyNotFound();
16235
16236 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16237 region.imageExtent = {4, 4, 1};
16238 m_errorMonitor->ExpectSuccess();
16239 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16240 &region);
16241 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16242 &region);
16243 m_errorMonitor->VerifyNotFound();
16244
16245 // Offset + extent width < mip width and not a multiple of block width - should fail
16246 region.imageExtent = {3, 3, 1};
16247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16248 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16249 &region);
16250 m_errorMonitor->VerifyFound();
16251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16252 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16253 &region);
16254 m_errorMonitor->VerifyFound();
16255}
16256
Dave Houlton59a20702017-02-02 17:26:23 -070016257TEST_F(VkLayerTest, ImageBufferCopyTests) {
16258 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16259
16260 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016261 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16262 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16263 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16264 return;
16265 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016266
16267 // Bail if any dimension of transfer granularity is 0.
16268 auto index = m_device->graphics_queue_node_index_;
16269 auto queue_family_properties = m_device->phy().queue_properties();
16270 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16271 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16272 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16273 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16274 return;
16275 }
16276
Dave Houlton59a20702017-02-02 17:26:23 -070016277 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16278 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16279 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016280 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16281 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16282 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16283 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16284
Dave Houlton59a20702017-02-02 17:26:23 -070016285 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16286 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16287 VK_IMAGE_TILING_OPTIMAL, 0);
16288 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16289 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16290 VK_IMAGE_TILING_OPTIMAL, 0);
16291 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16292 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016293 ASSERT_TRUE(image_64k.initialized());
16294 ASSERT_TRUE(image_16k.initialized());
16295 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016296
Dave Houltonf3229d52017-02-21 15:59:08 -070016297 // Verify all needed Depth/Stencil formats are supported
16298 bool missing_ds_support = false;
16299 VkFormatProperties props = {0, 0, 0};
16300 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16301 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16302 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16303 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16304 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16305 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16306 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16307 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16308
16309 if (!missing_ds_support) {
16310 ds_image_4D_1S.init(
16311 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16312 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16313 VK_IMAGE_TILING_OPTIMAL, 0);
16314 ASSERT_TRUE(ds_image_4D_1S.initialized());
16315
16316 ds_image_3D_1S.init(
16317 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16318 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16319 VK_IMAGE_TILING_OPTIMAL, 0);
16320 ASSERT_TRUE(ds_image_3D_1S.initialized());
16321
16322 ds_image_2D.init(
16323 256, 256, VK_FORMAT_D16_UNORM,
16324 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16325 VK_IMAGE_TILING_OPTIMAL, 0);
16326 ASSERT_TRUE(ds_image_2D.initialized());
16327
16328 ds_image_1S.init(
16329 256, 256, VK_FORMAT_S8_UINT,
16330 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16331 VK_IMAGE_TILING_OPTIMAL, 0);
16332 ASSERT_TRUE(ds_image_1S.initialized());
16333 }
16334
16335 // Allocate buffers
16336 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016337 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016338 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16339 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16340 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16341 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016342
16343 VkBufferImageCopy region = {};
16344 region.bufferRowLength = 0;
16345 region.bufferImageHeight = 0;
16346 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16347 region.imageSubresource.layerCount = 1;
16348 region.imageOffset = {0, 0, 0};
16349 region.imageExtent = {64, 64, 1};
16350 region.bufferOffset = 0;
16351
16352 // attempt copies before putting command buffer in recording state
16353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16354 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16355 &region);
16356 m_errorMonitor->VerifyFound();
16357
16358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16359 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16360 &region);
16361 m_errorMonitor->VerifyFound();
16362
16363 // start recording
16364 m_commandBuffer->BeginCommandBuffer();
16365
16366 // successful copies
16367 m_errorMonitor->ExpectSuccess();
16368 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16369 &region);
16370 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16371 &region);
16372 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16373 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16374 &region);
16375 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16376 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16377 &region);
16378 region.imageOffset.x = 0;
16379 region.imageExtent.height = 64;
16380 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16381 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16382 &region);
16383 m_errorMonitor->VerifyNotFound();
16384
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016385 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016386 region.imageExtent = {65, 64, 1};
16387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16388 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16389 &region);
16390 m_errorMonitor->VerifyFound();
16391
16392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16393 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16394 &region);
16395 m_errorMonitor->VerifyFound();
16396
16397 // image/buffer too small (offset) on copy to image
16398 region.imageExtent = {64, 64, 1};
16399 region.imageOffset = {0, 4, 0};
16400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16401 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16402 &region);
16403 m_errorMonitor->VerifyFound();
16404
16405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16406 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16407 &region);
16408 m_errorMonitor->VerifyFound();
16409
16410 // image/buffer too small on copy to buffer
16411 region.imageExtent = {64, 64, 1};
16412 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016413 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16415 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16416 &region);
16417 m_errorMonitor->VerifyFound();
16418
16419 region.imageExtent = {64, 65, 1};
16420 region.bufferOffset = 0;
16421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16422 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16423 &region);
16424 m_errorMonitor->VerifyFound();
16425
16426 // buffer size ok but rowlength causes loose packing
16427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16428 region.imageExtent = {64, 64, 1};
16429 region.bufferRowLength = 68;
16430 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16431 &region);
16432 m_errorMonitor->VerifyFound();
16433
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016434 // An extent with zero area should produce a warning, but no error
16435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16436 region.imageExtent.width = 0;
16437 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16438 &region);
16439 m_errorMonitor->VerifyFound();
16440
Dave Houlton59a20702017-02-02 17:26:23 -070016441 // aspect bits
16442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16443 region.imageExtent = {64, 64, 1};
16444 region.bufferRowLength = 0;
16445 region.bufferImageHeight = 0;
16446 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16447 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16448 buffer_16k.handle(), 1, &region);
16449 m_errorMonitor->VerifyFound();
16450
16451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16452 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16453 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16454 &region);
16455 m_errorMonitor->VerifyFound();
16456
16457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16458 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16459 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16460 buffer_16k.handle(), 1, &region);
16461 m_errorMonitor->VerifyFound();
16462
Dave Houltonf3229d52017-02-21 15:59:08 -070016463 // Test Depth/Stencil copies
16464 if (missing_ds_support) {
16465 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16466 } else {
16467 VkBufferImageCopy ds_region = {};
16468 ds_region.bufferOffset = 0;
16469 ds_region.bufferRowLength = 0;
16470 ds_region.bufferImageHeight = 0;
16471 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16472 ds_region.imageSubresource.mipLevel = 0;
16473 ds_region.imageSubresource.baseArrayLayer = 0;
16474 ds_region.imageSubresource.layerCount = 1;
16475 ds_region.imageOffset = {0, 0, 0};
16476 ds_region.imageExtent = {256, 256, 1};
16477
16478 // Depth copies that should succeed
16479 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16480 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16481 buffer_256k.handle(), 1, &ds_region);
16482 m_errorMonitor->VerifyNotFound();
16483
16484 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16485 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16486 buffer_256k.handle(), 1, &ds_region);
16487 m_errorMonitor->VerifyNotFound();
16488
16489 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16490 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16491 buffer_128k.handle(), 1, &ds_region);
16492 m_errorMonitor->VerifyNotFound();
16493
16494 // Depth copies that should fail
16495 ds_region.bufferOffset = 4;
16496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16497 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16498 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16499 buffer_256k.handle(), 1, &ds_region);
16500 m_errorMonitor->VerifyFound();
16501
16502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16503 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16504 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16505 buffer_256k.handle(), 1, &ds_region);
16506 m_errorMonitor->VerifyFound();
16507
16508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16509 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16510 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16511 buffer_128k.handle(), 1, &ds_region);
16512 m_errorMonitor->VerifyFound();
16513
16514 // Stencil copies that should succeed
16515 ds_region.bufferOffset = 0;
16516 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16517 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16518 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16519 buffer_64k.handle(), 1, &ds_region);
16520 m_errorMonitor->VerifyNotFound();
16521
16522 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16523 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16524 buffer_64k.handle(), 1, &ds_region);
16525 m_errorMonitor->VerifyNotFound();
16526
16527 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16528 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16529 buffer_64k.handle(), 1, &ds_region);
16530 m_errorMonitor->VerifyNotFound();
16531
16532 // Stencil copies that should fail
16533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16534 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16535 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16536 buffer_16k.handle(), 1, &ds_region);
16537 m_errorMonitor->VerifyFound();
16538
16539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16540 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16541 ds_region.bufferRowLength = 260;
16542 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16543 buffer_64k.handle(), 1, &ds_region);
16544 m_errorMonitor->VerifyFound();
16545
16546 ds_region.bufferRowLength = 0;
16547 ds_region.bufferOffset = 4;
16548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16549 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16550 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16551 buffer_64k.handle(), 1, &ds_region);
16552 m_errorMonitor->VerifyFound();
16553 }
16554
Dave Houlton584d51e2017-02-16 12:52:54 -070016555 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040016556 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070016557 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016558 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16559 device_features.textureCompressionASTC_LDR)) {
16560 printf(" No compressed formats supported - block compression tests skipped.\n");
16561 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016562 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16563 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016564 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016565 image_16k_4x4comp.init(128, 128, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016566 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16567 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016568 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016569 image_16k_4x4comp.init(128, 128, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070016570 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016571 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16572 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016573 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016574 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16575 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016576 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16577 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016578 }
16579 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016580
Dave Houlton584d51e2017-02-16 12:52:54 -070016581 // Just fits
16582 m_errorMonitor->ExpectSuccess();
16583 region.imageExtent = {128, 128, 1};
16584 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16585 buffer_16k.handle(), 1, &region);
16586 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016587
Dave Houlton584d51e2017-02-16 12:52:54 -070016588 // with offset, too big for buffer
16589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16590 region.bufferOffset = 16;
16591 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16592 buffer_16k.handle(), 1, &region);
16593 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016594 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016595
Dave Houlton67e9b532017-03-02 17:00:10 -070016596 // extents that are not a multiple of compressed block size
16597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16598 region.imageExtent.width = 66;
16599 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16600 buffer_16k.handle(), 1, &region);
16601 m_errorMonitor->VerifyFound();
16602 region.imageExtent.width = 128;
16603
16604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016605 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016606 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16607 buffer_16k.handle(), 1, &region);
16608 m_errorMonitor->VerifyFound();
16609 region.imageExtent.height = 128;
16610
16611 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16612
16613 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16614 m_errorMonitor->ExpectSuccess();
16615 region.imageExtent.width = 66;
16616 region.imageOffset.x = 64;
16617 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16618 buffer_16k.handle(), 1, &region);
16619 region.imageExtent.width = 16;
16620 region.imageOffset.x = 0;
16621 region.imageExtent.height = 2;
16622 region.imageOffset.y = 128;
16623 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016624 buffer_16k.handle(), 1, &region);
16625 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016626 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016627
Dave Houlton584d51e2017-02-16 12:52:54 -070016628 // buffer offset must be a multiple of texel block size (16)
16629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16631 region.imageExtent = {64, 64, 1};
16632 region.bufferOffset = 24;
16633 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16634 buffer_16k.handle(), 1, &region);
16635 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016636
Dave Houlton584d51e2017-02-16 12:52:54 -070016637 // rowlength not a multiple of block width (4)
16638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16639 region.bufferOffset = 0;
16640 region.bufferRowLength = 130;
16641 region.bufferImageHeight = 0;
16642 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16643 buffer_64k.handle(), 1, &region);
16644 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016645
Dave Houlton584d51e2017-02-16 12:52:54 -070016646 // imageheight not a multiple of block height (4)
16647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16648 region.bufferRowLength = 0;
16649 region.bufferImageHeight = 130;
16650 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16651 buffer_64k.handle(), 1, &region);
16652 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016653 }
Dave Houlton59a20702017-02-02 17:26:23 -070016654}
16655
Tony Barbourd6673642016-05-05 14:46:39 -060016656TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016657 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016658
16659 ASSERT_NO_FATAL_FAILURE(InitState());
16660
Rene Lindsay135204f2016-12-22 17:11:09 -070016661 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016662 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016663 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 -070016664 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016665 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016666 vk_testing::Buffer buffer;
16667 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016668 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016669 VkBufferImageCopy region = {};
16670 region.bufferRowLength = 128;
16671 region.bufferImageHeight = 128;
16672 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16673 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016674 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016675 region.imageExtent.height = 4;
16676 region.imageExtent.width = 4;
16677 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016678
16679 VkImageObj image2(m_device);
16680 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 -070016681 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016682 ASSERT_TRUE(image2.initialized());
16683 vk_testing::Buffer buffer2;
16684 VkMemoryPropertyFlags reqs2 = 0;
16685 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16686 VkBufferImageCopy region2 = {};
16687 region2.bufferRowLength = 128;
16688 region2.bufferImageHeight = 128;
16689 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16690 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16691 region2.imageSubresource.layerCount = 1;
16692 region2.imageExtent.height = 4;
16693 region2.imageExtent.width = 4;
16694 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016695 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016696
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016697 // Image must have offset.z of 0 and extent.depth of 1
16698 // Introduce failure by setting imageExtent.depth to 0
16699 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016701 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016702 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016703 m_errorMonitor->VerifyFound();
16704
16705 region.imageExtent.depth = 1;
16706
16707 // Image must have offset.z of 0 and extent.depth of 1
16708 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016709 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016710 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016713 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016714 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016715 m_errorMonitor->VerifyFound();
16716
16717 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016718 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16719 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016720 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016722 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16723 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016724 m_errorMonitor->VerifyFound();
16725
16726 // BufferOffset must be a multiple of 4
16727 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016728 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016730 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16731 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016732 m_errorMonitor->VerifyFound();
16733
16734 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16735 region.bufferOffset = 0;
16736 region.imageExtent.height = 128;
16737 region.imageExtent.width = 128;
16738 // Introduce failure by setting bufferRowLength > 0 but less than width
16739 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016741 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16742 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016743 m_errorMonitor->VerifyFound();
16744
16745 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16746 region.bufferRowLength = 128;
16747 // Introduce failure by setting bufferRowHeight > 0 but less than height
16748 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016750 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16751 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016752 m_errorMonitor->VerifyFound();
16753
16754 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016755 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016756 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16757 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016758 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016759 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16760 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016761 VkImageBlit blitRegion = {};
16762 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16763 blitRegion.srcSubresource.baseArrayLayer = 0;
16764 blitRegion.srcSubresource.layerCount = 1;
16765 blitRegion.srcSubresource.mipLevel = 0;
16766 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16767 blitRegion.dstSubresource.baseArrayLayer = 0;
16768 blitRegion.dstSubresource.layerCount = 1;
16769 blitRegion.dstSubresource.mipLevel = 0;
16770
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016771 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060016772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
16773 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
16774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
16775 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016776 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16777 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016778 m_errorMonitor->VerifyFound();
16779
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016781 VkImageMemoryBarrier img_barrier;
16782 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16783 img_barrier.pNext = NULL;
16784 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16785 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16786 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16787 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16788 img_barrier.image = image.handle();
16789 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16790 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16791 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16792 img_barrier.subresourceRange.baseArrayLayer = 0;
16793 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016794 img_barrier.subresourceRange.layerCount = 0;
16795 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016796 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16797 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016798 m_errorMonitor->VerifyFound();
16799 img_barrier.subresourceRange.layerCount = 1;
16800}
16801
16802TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016803 TEST_DESCRIPTION("Exceed the limits of image format ");
16804
Cody Northropc31a84f2016-08-22 10:41:47 -060016805 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016807 VkImageCreateInfo image_create_info = {};
16808 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16809 image_create_info.pNext = NULL;
16810 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16811 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16812 image_create_info.extent.width = 32;
16813 image_create_info.extent.height = 32;
16814 image_create_info.extent.depth = 1;
16815 image_create_info.mipLevels = 1;
16816 image_create_info.arrayLayers = 1;
16817 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16818 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16819 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16820 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16821 image_create_info.flags = 0;
16822
16823 VkImage nullImg;
16824 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016825 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16826 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016827 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016828 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16829 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16830 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016831 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016832
Tony Barbour0907e362017-03-09 15:05:30 -070016833 uint32_t maxDim =
16834 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16835 // If max mip levels exceeds image extents, skip the max mip levels test
16836 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16838 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16839 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16840 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16841 m_errorMonitor->VerifyFound();
16842 image_create_info.mipLevels = 1;
16843 }
Tony Barbourd6673642016-05-05 14:46:39 -060016844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016846 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16847 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16848 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16849 m_errorMonitor->VerifyFound();
16850 image_create_info.arrayLayers = 1;
16851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016853 int samples = imgFmtProps.sampleCounts >> 1;
16854 image_create_info.samples = (VkSampleCountFlagBits)samples;
16855 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16856 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16857 m_errorMonitor->VerifyFound();
16858 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16861 "pCreateInfo->initialLayout, must be "
16862 "VK_IMAGE_LAYOUT_UNDEFINED or "
16863 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016864 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16865 // Expect INVALID_LAYOUT
16866 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16867 m_errorMonitor->VerifyFound();
16868 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16869}
16870
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016871TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016872 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016874
16875 ASSERT_NO_FATAL_FAILURE(InitState());
16876
16877 VkImageObj src_image(m_device);
16878 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16879 VkImageObj dst_image(m_device);
16880 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16881
Tony Barbour552f6c02016-12-21 14:34:07 -070016882 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016883 VkImageCopy copy_region;
16884 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16885 copy_region.srcSubresource.mipLevel = 0;
16886 copy_region.srcSubresource.baseArrayLayer = 0;
16887 copy_region.srcSubresource.layerCount = 0;
16888 copy_region.srcOffset.x = 0;
16889 copy_region.srcOffset.y = 0;
16890 copy_region.srcOffset.z = 0;
16891 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16892 copy_region.dstSubresource.mipLevel = 0;
16893 copy_region.dstSubresource.baseArrayLayer = 0;
16894 copy_region.dstSubresource.layerCount = 0;
16895 copy_region.dstOffset.x = 0;
16896 copy_region.dstOffset.y = 0;
16897 copy_region.dstOffset.z = 0;
16898 copy_region.extent.width = 64;
16899 copy_region.extent.height = 64;
16900 copy_region.extent.depth = 1;
16901 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16902 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016903 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016904
16905 m_errorMonitor->VerifyFound();
16906}
16907
16908TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016909 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016911
16912 ASSERT_NO_FATAL_FAILURE(InitState());
16913
16914 VkImageObj src_image(m_device);
16915 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16916 VkImageObj dst_image(m_device);
16917 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16918
Tony Barbour552f6c02016-12-21 14:34:07 -070016919 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016920 VkImageCopy copy_region;
16921 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16922 copy_region.srcSubresource.mipLevel = 0;
16923 copy_region.srcSubresource.baseArrayLayer = 0;
16924 copy_region.srcSubresource.layerCount = 0;
16925 copy_region.srcOffset.x = 0;
16926 copy_region.srcOffset.y = 0;
16927 copy_region.srcOffset.z = 0;
16928 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16929 copy_region.dstSubresource.mipLevel = 0;
16930 copy_region.dstSubresource.baseArrayLayer = 0;
16931 copy_region.dstSubresource.layerCount = 0;
16932 copy_region.dstOffset.x = 0;
16933 copy_region.dstOffset.y = 0;
16934 copy_region.dstOffset.z = 0;
16935 copy_region.extent.width = 64;
16936 copy_region.extent.height = 64;
16937 copy_region.extent.depth = 1;
16938 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16939 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016940 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016941
16942 m_errorMonitor->VerifyFound();
16943}
16944
Karl Schultz6addd812016-02-02 17:17:23 -070016945TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016946 VkResult err;
16947 bool pass;
16948
16949 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016951
16952 ASSERT_NO_FATAL_FAILURE(InitState());
16953
16954 // Create two images of different types and try to copy between them
16955 VkImage srcImage;
16956 VkImage dstImage;
16957 VkDeviceMemory srcMem;
16958 VkDeviceMemory destMem;
16959 VkMemoryRequirements memReqs;
16960
16961 VkImageCreateInfo image_create_info = {};
16962 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16963 image_create_info.pNext = NULL;
16964 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16965 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16966 image_create_info.extent.width = 32;
16967 image_create_info.extent.height = 32;
16968 image_create_info.extent.depth = 1;
16969 image_create_info.mipLevels = 1;
16970 image_create_info.arrayLayers = 1;
16971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16972 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16973 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16974 image_create_info.flags = 0;
16975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016976 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016977 ASSERT_VK_SUCCESS(err);
16978
16979 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16980 // Introduce failure by creating second image with a different-sized format.
16981 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16982
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016983 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016984 ASSERT_VK_SUCCESS(err);
16985
16986 // Allocate memory
16987 VkMemoryAllocateInfo memAlloc = {};
16988 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16989 memAlloc.pNext = NULL;
16990 memAlloc.allocationSize = 0;
16991 memAlloc.memoryTypeIndex = 0;
16992
16993 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16994 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016995 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016996 ASSERT_TRUE(pass);
16997 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16998 ASSERT_VK_SUCCESS(err);
16999
17000 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
17001 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017002 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017003 ASSERT_TRUE(pass);
17004 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
17005 ASSERT_VK_SUCCESS(err);
17006
17007 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17008 ASSERT_VK_SUCCESS(err);
17009 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17010 ASSERT_VK_SUCCESS(err);
17011
Tony Barbour552f6c02016-12-21 14:34:07 -070017012 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017013 VkImageCopy copyRegion;
17014 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17015 copyRegion.srcSubresource.mipLevel = 0;
17016 copyRegion.srcSubresource.baseArrayLayer = 0;
17017 copyRegion.srcSubresource.layerCount = 0;
17018 copyRegion.srcOffset.x = 0;
17019 copyRegion.srcOffset.y = 0;
17020 copyRegion.srcOffset.z = 0;
17021 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17022 copyRegion.dstSubresource.mipLevel = 0;
17023 copyRegion.dstSubresource.baseArrayLayer = 0;
17024 copyRegion.dstSubresource.layerCount = 0;
17025 copyRegion.dstOffset.x = 0;
17026 copyRegion.dstOffset.y = 0;
17027 copyRegion.dstOffset.z = 0;
17028 copyRegion.extent.width = 1;
17029 copyRegion.extent.height = 1;
17030 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017031 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017032 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017033
17034 m_errorMonitor->VerifyFound();
17035
17036 vkDestroyImage(m_device->device(), srcImage, NULL);
17037 vkDestroyImage(m_device->device(), dstImage, NULL);
17038 vkFreeMemory(m_device->device(), srcMem, NULL);
17039 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017040}
17041
Karl Schultz6addd812016-02-02 17:17:23 -070017042TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
17043 VkResult err;
17044 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017045
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017046 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17048 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017049
Mike Stroyana3082432015-09-25 13:39:21 -060017050 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017051 auto depth_format = find_depth_stencil_format(m_device);
17052 if (!depth_format) {
17053 return;
17054 }
Mike Stroyana3082432015-09-25 13:39:21 -060017055
17056 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017057 VkImage srcImage;
17058 VkImage dstImage;
17059 VkDeviceMemory srcMem;
17060 VkDeviceMemory destMem;
17061 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017062
17063 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017064 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17065 image_create_info.pNext = NULL;
17066 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17067 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17068 image_create_info.extent.width = 32;
17069 image_create_info.extent.height = 32;
17070 image_create_info.extent.depth = 1;
17071 image_create_info.mipLevels = 1;
17072 image_create_info.arrayLayers = 1;
17073 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17074 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17075 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17076 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017078 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017079 ASSERT_VK_SUCCESS(err);
17080
Karl Schultzbdb75952016-04-19 11:36:49 -060017081 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17082
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017083 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070017084 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070017085 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060017086 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017089 ASSERT_VK_SUCCESS(err);
17090
17091 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017092 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017093 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17094 memAlloc.pNext = NULL;
17095 memAlloc.allocationSize = 0;
17096 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017097
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017098 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017099 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017100 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017101 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017102 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017103 ASSERT_VK_SUCCESS(err);
17104
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017105 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017106 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017107 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017108 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017109 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017110 ASSERT_VK_SUCCESS(err);
17111
17112 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17113 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017114 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017115 ASSERT_VK_SUCCESS(err);
17116
Tony Barbour552f6c02016-12-21 14:34:07 -070017117 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017118 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017119 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017120 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017121 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017122 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017123 copyRegion.srcOffset.x = 0;
17124 copyRegion.srcOffset.y = 0;
17125 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017126 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017127 copyRegion.dstSubresource.mipLevel = 0;
17128 copyRegion.dstSubresource.baseArrayLayer = 0;
17129 copyRegion.dstSubresource.layerCount = 0;
17130 copyRegion.dstOffset.x = 0;
17131 copyRegion.dstOffset.y = 0;
17132 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017133 copyRegion.extent.width = 1;
17134 copyRegion.extent.height = 1;
17135 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017136 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017137 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017139 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017140
Chia-I Wuf7458c52015-10-26 21:10:41 +080017141 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017142 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017143 vkFreeMemory(m_device->device(), srcMem, NULL);
17144 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017145}
17146
Karl Schultz6addd812016-02-02 17:17:23 -070017147TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17148 VkResult err;
17149 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17152 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017153
Mike Stroyana3082432015-09-25 13:39:21 -060017154 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017155
17156 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017157 VkImage srcImage;
17158 VkImage dstImage;
17159 VkDeviceMemory srcMem;
17160 VkDeviceMemory destMem;
17161 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017162
17163 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017164 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17165 image_create_info.pNext = NULL;
17166 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17167 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17168 image_create_info.extent.width = 32;
17169 image_create_info.extent.height = 1;
17170 image_create_info.extent.depth = 1;
17171 image_create_info.mipLevels = 1;
17172 image_create_info.arrayLayers = 1;
17173 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17174 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17175 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17176 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017178 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017179 ASSERT_VK_SUCCESS(err);
17180
Karl Schultz6addd812016-02-02 17:17:23 -070017181 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017183 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017184 ASSERT_VK_SUCCESS(err);
17185
17186 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017187 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017188 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17189 memAlloc.pNext = NULL;
17190 memAlloc.allocationSize = 0;
17191 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017192
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017193 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017194 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017195 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017196 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017197 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017198 ASSERT_VK_SUCCESS(err);
17199
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017200 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017201 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017202 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017203 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017204 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017205 ASSERT_VK_SUCCESS(err);
17206
17207 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17208 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017209 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017210 ASSERT_VK_SUCCESS(err);
17211
Tony Barbour552f6c02016-12-21 14:34:07 -070017212 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017213 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017214 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17215 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017216 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017217 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017218 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017219 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017220 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017221 resolveRegion.srcOffset.x = 0;
17222 resolveRegion.srcOffset.y = 0;
17223 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017224 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017225 resolveRegion.dstSubresource.mipLevel = 0;
17226 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017227 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017228 resolveRegion.dstOffset.x = 0;
17229 resolveRegion.dstOffset.y = 0;
17230 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017231 resolveRegion.extent.width = 1;
17232 resolveRegion.extent.height = 1;
17233 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017234 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017235 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017236
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017237 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017238
Chia-I Wuf7458c52015-10-26 21:10:41 +080017239 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017240 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017241 vkFreeMemory(m_device->device(), srcMem, NULL);
17242 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017243}
17244
Karl Schultz6addd812016-02-02 17:17:23 -070017245TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17246 VkResult err;
17247 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17250 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017251
Mike Stroyana3082432015-09-25 13:39:21 -060017252 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017253
Chris Forbesa7530692016-05-08 12:35:39 +120017254 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017255 VkImage srcImage;
17256 VkImage dstImage;
17257 VkDeviceMemory srcMem;
17258 VkDeviceMemory destMem;
17259 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017260
17261 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17263 image_create_info.pNext = NULL;
17264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17265 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17266 image_create_info.extent.width = 32;
17267 image_create_info.extent.height = 1;
17268 image_create_info.extent.depth = 1;
17269 image_create_info.mipLevels = 1;
17270 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017271 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17273 // Note: Some implementations expect color attachment usage for any
17274 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017275 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017276 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017278 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017279 ASSERT_VK_SUCCESS(err);
17280
Karl Schultz6addd812016-02-02 17:17:23 -070017281 // Note: Some implementations expect color attachment usage for any
17282 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017283 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017285 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017286 ASSERT_VK_SUCCESS(err);
17287
17288 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017289 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017290 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17291 memAlloc.pNext = NULL;
17292 memAlloc.allocationSize = 0;
17293 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017294
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017295 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017296 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017297 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017298 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017299 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017300 ASSERT_VK_SUCCESS(err);
17301
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017302 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017303 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017304 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017305 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017306 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017307 ASSERT_VK_SUCCESS(err);
17308
17309 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17310 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017311 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017312 ASSERT_VK_SUCCESS(err);
17313
Tony Barbour552f6c02016-12-21 14:34:07 -070017314 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017315 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017316 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17317 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017318 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017319 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017320 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017321 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017322 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017323 resolveRegion.srcOffset.x = 0;
17324 resolveRegion.srcOffset.y = 0;
17325 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017326 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017327 resolveRegion.dstSubresource.mipLevel = 0;
17328 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017329 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017330 resolveRegion.dstOffset.x = 0;
17331 resolveRegion.dstOffset.y = 0;
17332 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017333 resolveRegion.extent.width = 1;
17334 resolveRegion.extent.height = 1;
17335 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017336 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017337 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017338
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017339 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017340
Chia-I Wuf7458c52015-10-26 21:10:41 +080017341 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017342 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017343 vkFreeMemory(m_device->device(), srcMem, NULL);
17344 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017345}
17346
Karl Schultz6addd812016-02-02 17:17:23 -070017347TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17348 VkResult err;
17349 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017350
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017352 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017353
Mike Stroyana3082432015-09-25 13:39:21 -060017354 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017355
17356 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017357 VkImage srcImage;
17358 VkImage dstImage;
17359 VkDeviceMemory srcMem;
17360 VkDeviceMemory destMem;
17361 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017362
17363 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17365 image_create_info.pNext = NULL;
17366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17367 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17368 image_create_info.extent.width = 32;
17369 image_create_info.extent.height = 1;
17370 image_create_info.extent.depth = 1;
17371 image_create_info.mipLevels = 1;
17372 image_create_info.arrayLayers = 1;
17373 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17375 // Note: Some implementations expect color attachment usage for any
17376 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017378 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017381 ASSERT_VK_SUCCESS(err);
17382
Karl Schultz6addd812016-02-02 17:17:23 -070017383 // Set format to something other than source image
17384 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17385 // Note: Some implementations expect color attachment usage for any
17386 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017388 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017390 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017391 ASSERT_VK_SUCCESS(err);
17392
17393 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017394 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017395 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17396 memAlloc.pNext = NULL;
17397 memAlloc.allocationSize = 0;
17398 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017399
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017400 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017401 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017402 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017403 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017404 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017405 ASSERT_VK_SUCCESS(err);
17406
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017407 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017408 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017409 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017410 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017411 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017412 ASSERT_VK_SUCCESS(err);
17413
17414 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17415 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017416 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017417 ASSERT_VK_SUCCESS(err);
17418
Tony Barbour552f6c02016-12-21 14:34:07 -070017419 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017420 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017421 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17422 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017423 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017424 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017425 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017426 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017427 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017428 resolveRegion.srcOffset.x = 0;
17429 resolveRegion.srcOffset.y = 0;
17430 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017431 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017432 resolveRegion.dstSubresource.mipLevel = 0;
17433 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017434 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017435 resolveRegion.dstOffset.x = 0;
17436 resolveRegion.dstOffset.y = 0;
17437 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017438 resolveRegion.extent.width = 1;
17439 resolveRegion.extent.height = 1;
17440 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017441 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017442 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017444 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017445
Chia-I Wuf7458c52015-10-26 21:10:41 +080017446 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017447 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017448 vkFreeMemory(m_device->device(), srcMem, NULL);
17449 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017450}
17451
Karl Schultz6addd812016-02-02 17:17:23 -070017452TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17453 VkResult err;
17454 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017455
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017457 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017458
Mike Stroyana3082432015-09-25 13:39:21 -060017459 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017460
17461 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017462 VkImage srcImage;
17463 VkImage dstImage;
17464 VkDeviceMemory srcMem;
17465 VkDeviceMemory destMem;
17466 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017467
17468 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017469 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17470 image_create_info.pNext = NULL;
17471 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17472 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17473 image_create_info.extent.width = 32;
17474 image_create_info.extent.height = 1;
17475 image_create_info.extent.depth = 1;
17476 image_create_info.mipLevels = 1;
17477 image_create_info.arrayLayers = 1;
17478 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17479 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17480 // Note: Some implementations expect color attachment usage for any
17481 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017482 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017483 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017484
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017485 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017486 ASSERT_VK_SUCCESS(err);
17487
Karl Schultz6addd812016-02-02 17:17:23 -070017488 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17489 // Note: Some implementations expect color attachment usage for any
17490 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017491 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017492 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017494 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017495 ASSERT_VK_SUCCESS(err);
17496
17497 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017498 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017499 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17500 memAlloc.pNext = NULL;
17501 memAlloc.allocationSize = 0;
17502 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017503
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017504 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017505 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017506 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017507 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017508 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017509 ASSERT_VK_SUCCESS(err);
17510
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017511 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017512 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017513 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017514 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017515 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017516 ASSERT_VK_SUCCESS(err);
17517
17518 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17519 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017520 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017521 ASSERT_VK_SUCCESS(err);
17522
Tony Barbour552f6c02016-12-21 14:34:07 -070017523 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017524 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017525 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17526 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017527 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017528 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017529 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017530 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017531 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017532 resolveRegion.srcOffset.x = 0;
17533 resolveRegion.srcOffset.y = 0;
17534 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017535 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017536 resolveRegion.dstSubresource.mipLevel = 0;
17537 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017538 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017539 resolveRegion.dstOffset.x = 0;
17540 resolveRegion.dstOffset.y = 0;
17541 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017542 resolveRegion.extent.width = 1;
17543 resolveRegion.extent.height = 1;
17544 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017545 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017546 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017547
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017548 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017549
Chia-I Wuf7458c52015-10-26 21:10:41 +080017550 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017551 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017552 vkFreeMemory(m_device->device(), srcMem, NULL);
17553 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017554}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017555
Karl Schultz6addd812016-02-02 17:17:23 -070017556TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017557 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017558 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17559 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017560 // The image format check comes 2nd in validation so we trigger it first,
17561 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017562 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17565 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017566
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017567 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017568 auto depth_format = find_depth_stencil_format(m_device);
17569 if (!depth_format) {
17570 return;
17571 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017572
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017573 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017574 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17575 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017576
17577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17579 ds_pool_ci.pNext = NULL;
17580 ds_pool_ci.maxSets = 1;
17581 ds_pool_ci.poolSizeCount = 1;
17582 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017583
17584 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017585 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017586 ASSERT_VK_SUCCESS(err);
17587
17588 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017589 dsl_binding.binding = 0;
17590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17591 dsl_binding.descriptorCount = 1;
17592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17593 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017594
17595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17597 ds_layout_ci.pNext = NULL;
17598 ds_layout_ci.bindingCount = 1;
17599 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017600 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017601 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017602 ASSERT_VK_SUCCESS(err);
17603
17604 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017605 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017606 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017607 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017608 alloc_info.descriptorPool = ds_pool;
17609 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017610 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017611 ASSERT_VK_SUCCESS(err);
17612
Karl Schultz6addd812016-02-02 17:17:23 -070017613 VkImage image_bad;
17614 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017615 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017616 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017617 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017618 const int32_t tex_width = 32;
17619 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017620
17621 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017622 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17623 image_create_info.pNext = NULL;
17624 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17625 image_create_info.format = tex_format_bad;
17626 image_create_info.extent.width = tex_width;
17627 image_create_info.extent.height = tex_height;
17628 image_create_info.extent.depth = 1;
17629 image_create_info.mipLevels = 1;
17630 image_create_info.arrayLayers = 1;
17631 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17632 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017633 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017634 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017636 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017637 ASSERT_VK_SUCCESS(err);
17638 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17640 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017641 ASSERT_VK_SUCCESS(err);
17642
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017643 // ---Bind image memory---
17644 VkMemoryRequirements img_mem_reqs;
17645 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17646 VkMemoryAllocateInfo image_alloc_info = {};
17647 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17648 image_alloc_info.pNext = NULL;
17649 image_alloc_info.memoryTypeIndex = 0;
17650 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017651 bool pass =
17652 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 -070017653 ASSERT_TRUE(pass);
17654 VkDeviceMemory mem;
17655 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17656 ASSERT_VK_SUCCESS(err);
17657 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17658 ASSERT_VK_SUCCESS(err);
17659 // -----------------------
17660
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017661 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017662 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017663 image_view_create_info.image = image_bad;
17664 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17665 image_view_create_info.format = tex_format_bad;
17666 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17667 image_view_create_info.subresourceRange.baseMipLevel = 0;
17668 image_view_create_info.subresourceRange.layerCount = 1;
17669 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017670 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017671
17672 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017673 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017674
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017675 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017676
Chia-I Wuf7458c52015-10-26 21:10:41 +080017677 vkDestroyImage(m_device->device(), image_bad, NULL);
17678 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017681
17682 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017683}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017684
17685TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017686 TEST_DESCRIPTION(
17687 "Call ClearColorImage w/ a depth|stencil image and "
17688 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017689
17690 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017691 auto depth_format = find_depth_stencil_format(m_device);
17692 if (!depth_format) {
17693 return;
17694 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17696
Tony Barbour552f6c02016-12-21 14:34:07 -070017697 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017698
17699 // Color image
17700 VkClearColorValue clear_color;
17701 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17702 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17703 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17704 const int32_t img_width = 32;
17705 const int32_t img_height = 32;
17706 VkImageCreateInfo image_create_info = {};
17707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17708 image_create_info.pNext = NULL;
17709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17710 image_create_info.format = color_format;
17711 image_create_info.extent.width = img_width;
17712 image_create_info.extent.height = img_height;
17713 image_create_info.extent.depth = 1;
17714 image_create_info.mipLevels = 1;
17715 image_create_info.arrayLayers = 1;
17716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17717 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17718 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17719
17720 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017721 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017723 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017724
17725 // Depth/Stencil image
17726 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017727 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017728 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17729 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017730 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017731 ds_image_create_info.extent.width = 64;
17732 ds_image_create_info.extent.height = 64;
17733 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017734 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 -060017735
17736 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017737 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017739 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 -060017740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017743 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017744 &color_range);
17745
17746 m_errorMonitor->VerifyFound();
17747
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17749 "vkCmdClearColorImage called with "
17750 "image created without "
17751 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017752
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017753 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017754 &color_range);
17755
17756 m_errorMonitor->VerifyFound();
17757
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017758 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17760 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017761
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017762 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17763 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017764
17765 m_errorMonitor->VerifyFound();
17766}
Tobin Ehliscde08892015-09-22 10:11:37 -060017767
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017768// WSI Enabled Tests
17769//
Chris Forbes09368e42016-10-13 11:59:22 +130017770#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017771TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17772
17773#if defined(VK_USE_PLATFORM_XCB_KHR)
17774 VkSurfaceKHR surface = VK_NULL_HANDLE;
17775
17776 VkResult err;
17777 bool pass;
17778 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17779 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17780 // uint32_t swapchain_image_count = 0;
17781 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17782 // uint32_t image_index = 0;
17783 // VkPresentInfoKHR present_info = {};
17784
17785 ASSERT_NO_FATAL_FAILURE(InitState());
17786
17787 // Use the create function from one of the VK_KHR_*_surface extension in
17788 // order to create a surface, testing all known errors in the process,
17789 // before successfully creating a surface:
17790 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17792 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17793 pass = (err != VK_SUCCESS);
17794 ASSERT_TRUE(pass);
17795 m_errorMonitor->VerifyFound();
17796
17797 // Next, try to create a surface with the wrong
17798 // VkXcbSurfaceCreateInfoKHR::sType:
17799 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17800 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17802 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17803 pass = (err != VK_SUCCESS);
17804 ASSERT_TRUE(pass);
17805 m_errorMonitor->VerifyFound();
17806
17807 // Create a native window, and then correctly create a surface:
17808 xcb_connection_t *connection;
17809 xcb_screen_t *screen;
17810 xcb_window_t xcb_window;
17811 xcb_intern_atom_reply_t *atom_wm_delete_window;
17812
17813 const xcb_setup_t *setup;
17814 xcb_screen_iterator_t iter;
17815 int scr;
17816 uint32_t value_mask, value_list[32];
17817 int width = 1;
17818 int height = 1;
17819
17820 connection = xcb_connect(NULL, &scr);
17821 ASSERT_TRUE(connection != NULL);
17822 setup = xcb_get_setup(connection);
17823 iter = xcb_setup_roots_iterator(setup);
17824 while (scr-- > 0)
17825 xcb_screen_next(&iter);
17826 screen = iter.data;
17827
17828 xcb_window = xcb_generate_id(connection);
17829
17830 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17831 value_list[0] = screen->black_pixel;
17832 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17833
17834 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17835 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17836
17837 /* Magic code that will send notification when window is destroyed */
17838 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17839 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17840
17841 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17842 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17843 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17844 free(reply);
17845
17846 xcb_map_window(connection, xcb_window);
17847
17848 // Force the x/y coordinates to 100,100 results are identical in consecutive
17849 // runs
17850 const uint32_t coords[] = { 100, 100 };
17851 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17852
17853 // Finally, try to correctly create a surface:
17854 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17855 xcb_create_info.pNext = NULL;
17856 xcb_create_info.flags = 0;
17857 xcb_create_info.connection = connection;
17858 xcb_create_info.window = xcb_window;
17859 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17860 pass = (err == VK_SUCCESS);
17861 ASSERT_TRUE(pass);
17862
17863 // Check if surface supports presentation:
17864
17865 // 1st, do so without having queried the queue families:
17866 VkBool32 supported = false;
17867 // TODO: Get the following error to come out:
17868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17869 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17870 "function");
17871 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17872 pass = (err != VK_SUCCESS);
17873 // ASSERT_TRUE(pass);
17874 // m_errorMonitor->VerifyFound();
17875
17876 // Next, query a queue family index that's too large:
17877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17878 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17879 pass = (err != VK_SUCCESS);
17880 ASSERT_TRUE(pass);
17881 m_errorMonitor->VerifyFound();
17882
17883 // Finally, do so correctly:
17884 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17885 // SUPPORTED
17886 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17887 pass = (err == VK_SUCCESS);
17888 ASSERT_TRUE(pass);
17889
17890 // Before proceeding, try to create a swapchain without having called
17891 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17892 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17893 swapchain_create_info.pNext = NULL;
17894 swapchain_create_info.flags = 0;
17895 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17896 swapchain_create_info.surface = surface;
17897 swapchain_create_info.imageArrayLayers = 1;
17898 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17899 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17901 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17902 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17903 pass = (err != VK_SUCCESS);
17904 ASSERT_TRUE(pass);
17905 m_errorMonitor->VerifyFound();
17906
17907 // Get the surface capabilities:
17908 VkSurfaceCapabilitiesKHR surface_capabilities;
17909
17910 // Do so correctly (only error logged by this entrypoint is if the
17911 // extension isn't enabled):
17912 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17913 pass = (err == VK_SUCCESS);
17914 ASSERT_TRUE(pass);
17915
17916 // Get the surface formats:
17917 uint32_t surface_format_count;
17918
17919 // First, try without a pointer to surface_format_count:
17920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17921 "specified as NULL");
17922 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17923 pass = (err == VK_SUCCESS);
17924 ASSERT_TRUE(pass);
17925 m_errorMonitor->VerifyFound();
17926
17927 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17928 // correctly done a 1st try (to get the count):
17929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17930 surface_format_count = 0;
17931 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17932 pass = (err == VK_SUCCESS);
17933 ASSERT_TRUE(pass);
17934 m_errorMonitor->VerifyFound();
17935
17936 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17937 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17938 pass = (err == VK_SUCCESS);
17939 ASSERT_TRUE(pass);
17940
17941 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17942 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17943
17944 // Next, do a 2nd try with surface_format_count being set too high:
17945 surface_format_count += 5;
17946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17947 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17948 pass = (err == VK_SUCCESS);
17949 ASSERT_TRUE(pass);
17950 m_errorMonitor->VerifyFound();
17951
17952 // Finally, do a correct 1st and 2nd try:
17953 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17954 pass = (err == VK_SUCCESS);
17955 ASSERT_TRUE(pass);
17956 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17957 pass = (err == VK_SUCCESS);
17958 ASSERT_TRUE(pass);
17959
17960 // Get the surface present modes:
17961 uint32_t surface_present_mode_count;
17962
17963 // First, try without a pointer to surface_format_count:
17964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17965 "specified as NULL");
17966
17967 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17968 pass = (err == VK_SUCCESS);
17969 ASSERT_TRUE(pass);
17970 m_errorMonitor->VerifyFound();
17971
17972 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17973 // correctly done a 1st try (to get the count):
17974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17975 surface_present_mode_count = 0;
17976 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17977 (VkPresentModeKHR *)&surface_present_mode_count);
17978 pass = (err == VK_SUCCESS);
17979 ASSERT_TRUE(pass);
17980 m_errorMonitor->VerifyFound();
17981
17982 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17983 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17984 pass = (err == VK_SUCCESS);
17985 ASSERT_TRUE(pass);
17986
17987 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17988 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17989
17990 // Next, do a 2nd try with surface_format_count being set too high:
17991 surface_present_mode_count += 5;
17992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17993 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17994 pass = (err == VK_SUCCESS);
17995 ASSERT_TRUE(pass);
17996 m_errorMonitor->VerifyFound();
17997
17998 // Finally, do a correct 1st and 2nd try:
17999 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
18000 pass = (err == VK_SUCCESS);
18001 ASSERT_TRUE(pass);
18002 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
18003 pass = (err == VK_SUCCESS);
18004 ASSERT_TRUE(pass);
18005
18006 // Create a swapchain:
18007
18008 // First, try without a pointer to swapchain_create_info:
18009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
18010 "specified as NULL");
18011
18012 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
18013 pass = (err != VK_SUCCESS);
18014 ASSERT_TRUE(pass);
18015 m_errorMonitor->VerifyFound();
18016
18017 // Next, call with a non-NULL swapchain_create_info, that has the wrong
18018 // sType:
18019 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18021
18022 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18023 pass = (err != VK_SUCCESS);
18024 ASSERT_TRUE(pass);
18025 m_errorMonitor->VerifyFound();
18026
18027 // Next, call with a NULL swapchain pointer:
18028 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
18029 swapchain_create_info.pNext = NULL;
18030 swapchain_create_info.flags = 0;
18031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
18032 "specified as NULL");
18033
18034 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
18035 pass = (err != VK_SUCCESS);
18036 ASSERT_TRUE(pass);
18037 m_errorMonitor->VerifyFound();
18038
18039 // TODO: Enhance swapchain layer so that
18040 // swapchain_create_info.queueFamilyIndexCount is checked against something?
18041
18042 // Next, call with a queue family index that's too large:
18043 uint32_t queueFamilyIndex[2] = { 100000, 0 };
18044 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18045 swapchain_create_info.queueFamilyIndexCount = 2;
18046 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
18047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
18048 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18049 pass = (err != VK_SUCCESS);
18050 ASSERT_TRUE(pass);
18051 m_errorMonitor->VerifyFound();
18052
18053 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
18054 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18055 swapchain_create_info.queueFamilyIndexCount = 1;
18056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18057 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
18058 "pCreateInfo->pQueueFamilyIndices).");
18059 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18060 pass = (err != VK_SUCCESS);
18061 ASSERT_TRUE(pass);
18062 m_errorMonitor->VerifyFound();
18063
18064 // Next, call with an invalid imageSharingMode:
18065 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
18066 swapchain_create_info.queueFamilyIndexCount = 1;
18067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18068 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
18069 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18070 pass = (err != VK_SUCCESS);
18071 ASSERT_TRUE(pass);
18072 m_errorMonitor->VerifyFound();
18073 // Fix for the future:
18074 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
18075 // SUPPORTED
18076 swapchain_create_info.queueFamilyIndexCount = 0;
18077 queueFamilyIndex[0] = 0;
18078 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
18079
18080 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
18081 // Get the images from a swapchain:
18082 // Acquire an image from a swapchain:
18083 // Present an image to a swapchain:
18084 // Destroy the swapchain:
18085
18086 // TODOs:
18087 //
18088 // - Try destroying the device without first destroying the swapchain
18089 //
18090 // - Try destroying the device without first destroying the surface
18091 //
18092 // - Try destroying the surface without first destroying the swapchain
18093
18094 // Destroy the surface:
18095 vkDestroySurfaceKHR(instance(), surface, NULL);
18096
18097 // Tear down the window:
18098 xcb_destroy_window(connection, xcb_window);
18099 xcb_disconnect(connection);
18100
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018101#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018102 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018103#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018104}
Chris Forbes09368e42016-10-13 11:59:22 +130018105#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018106
18107//
18108// POSITIVE VALIDATION TESTS
18109//
18110// These tests do not expect to encounter ANY validation errors pass only if this is true
18111
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018112TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18113 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18114 ASSERT_NO_FATAL_FAILURE(InitState());
18115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18116
18117 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18118 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18119 command_buffer_allocate_info.commandPool = m_commandPool;
18120 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18121 command_buffer_allocate_info.commandBufferCount = 1;
18122
18123 VkCommandBuffer secondary_command_buffer;
18124 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18125 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18126 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18127 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18128 command_buffer_inheritance_info.renderPass = m_renderPass;
18129 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18130
18131 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18132 command_buffer_begin_info.flags =
18133 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18134 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18135
18136 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18137 VkClearAttachment color_attachment;
18138 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18139 color_attachment.clearValue.color.float32[0] = 0;
18140 color_attachment.clearValue.color.float32[1] = 0;
18141 color_attachment.clearValue.color.float32[2] = 0;
18142 color_attachment.clearValue.color.float32[3] = 0;
18143 color_attachment.colorAttachment = 0;
18144 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18145 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18146}
18147
Tobin Ehlise0006882016-11-03 10:14:28 -060018148TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018149 TEST_DESCRIPTION(
18150 "Perform an image layout transition in a secondary command buffer followed "
18151 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018152 VkResult err;
18153 m_errorMonitor->ExpectSuccess();
18154 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018155 auto depth_format = find_depth_stencil_format(m_device);
18156 if (!depth_format) {
18157 return;
18158 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18160 // Allocate a secondary and primary cmd buffer
18161 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18162 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18163 command_buffer_allocate_info.commandPool = m_commandPool;
18164 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18165 command_buffer_allocate_info.commandBufferCount = 1;
18166
18167 VkCommandBuffer secondary_command_buffer;
18168 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18169 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18170 VkCommandBuffer primary_command_buffer;
18171 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18172 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18173 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18174 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18175 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18176 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18177 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18178
18179 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18180 ASSERT_VK_SUCCESS(err);
18181 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018182 image.init(128, 128, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060018183 ASSERT_TRUE(image.initialized());
18184 VkImageMemoryBarrier img_barrier = {};
18185 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18186 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18187 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18188 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18189 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18190 img_barrier.image = image.handle();
18191 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18192 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18193 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18194 img_barrier.subresourceRange.baseArrayLayer = 0;
18195 img_barrier.subresourceRange.baseMipLevel = 0;
18196 img_barrier.subresourceRange.layerCount = 1;
18197 img_barrier.subresourceRange.levelCount = 1;
18198 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18199 0, nullptr, 1, &img_barrier);
18200 err = vkEndCommandBuffer(secondary_command_buffer);
18201 ASSERT_VK_SUCCESS(err);
18202
18203 // Now update primary cmd buffer to execute secondary and transitions image
18204 command_buffer_begin_info.pInheritanceInfo = nullptr;
18205 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18206 ASSERT_VK_SUCCESS(err);
18207 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18208 VkImageMemoryBarrier img_barrier2 = {};
18209 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18210 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18211 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18212 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18213 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18214 img_barrier2.image = image.handle();
18215 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18216 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18217 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18218 img_barrier2.subresourceRange.baseArrayLayer = 0;
18219 img_barrier2.subresourceRange.baseMipLevel = 0;
18220 img_barrier2.subresourceRange.layerCount = 1;
18221 img_barrier2.subresourceRange.levelCount = 1;
18222 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18223 nullptr, 1, &img_barrier2);
18224 err = vkEndCommandBuffer(primary_command_buffer);
18225 ASSERT_VK_SUCCESS(err);
18226 VkSubmitInfo submit_info = {};
18227 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18228 submit_info.commandBufferCount = 1;
18229 submit_info.pCommandBuffers = &primary_command_buffer;
18230 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18231 ASSERT_VK_SUCCESS(err);
18232 m_errorMonitor->VerifyNotFound();
18233 err = vkDeviceWaitIdle(m_device->device());
18234 ASSERT_VK_SUCCESS(err);
18235 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18236 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18237}
18238
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018239// This is a positive test. No failures are expected.
18240TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018241 TEST_DESCRIPTION(
18242 "Ensure that the vkUpdateDescriptorSets validation code "
18243 "is ignoring VkWriteDescriptorSet members that are not "
18244 "related to the descriptor type specified by "
18245 "VkWriteDescriptorSet::descriptorType. Correct "
18246 "validation behavior will result in the test running to "
18247 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018248
18249 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18250
18251 ASSERT_NO_FATAL_FAILURE(InitState());
18252
18253 // Image Case
18254 {
18255 m_errorMonitor->ExpectSuccess();
18256
18257 VkImage image;
18258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18259 const int32_t tex_width = 32;
18260 const int32_t tex_height = 32;
18261 VkImageCreateInfo image_create_info = {};
18262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18263 image_create_info.pNext = NULL;
18264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18265 image_create_info.format = tex_format;
18266 image_create_info.extent.width = tex_width;
18267 image_create_info.extent.height = tex_height;
18268 image_create_info.extent.depth = 1;
18269 image_create_info.mipLevels = 1;
18270 image_create_info.arrayLayers = 1;
18271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18273 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18274 image_create_info.flags = 0;
18275 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18276 ASSERT_VK_SUCCESS(err);
18277
18278 VkMemoryRequirements memory_reqs;
18279 VkDeviceMemory image_memory;
18280 bool pass;
18281 VkMemoryAllocateInfo memory_info = {};
18282 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18283 memory_info.pNext = NULL;
18284 memory_info.allocationSize = 0;
18285 memory_info.memoryTypeIndex = 0;
18286 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18287 memory_info.allocationSize = memory_reqs.size;
18288 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18289 ASSERT_TRUE(pass);
18290 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18291 ASSERT_VK_SUCCESS(err);
18292 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18293 ASSERT_VK_SUCCESS(err);
18294
18295 VkImageViewCreateInfo image_view_create_info = {};
18296 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18297 image_view_create_info.image = image;
18298 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18299 image_view_create_info.format = tex_format;
18300 image_view_create_info.subresourceRange.layerCount = 1;
18301 image_view_create_info.subresourceRange.baseMipLevel = 0;
18302 image_view_create_info.subresourceRange.levelCount = 1;
18303 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18304
18305 VkImageView view;
18306 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18307 ASSERT_VK_SUCCESS(err);
18308
18309 VkDescriptorPoolSize ds_type_count = {};
18310 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18311 ds_type_count.descriptorCount = 1;
18312
18313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18315 ds_pool_ci.pNext = NULL;
18316 ds_pool_ci.maxSets = 1;
18317 ds_pool_ci.poolSizeCount = 1;
18318 ds_pool_ci.pPoolSizes = &ds_type_count;
18319
18320 VkDescriptorPool ds_pool;
18321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18322 ASSERT_VK_SUCCESS(err);
18323
18324 VkDescriptorSetLayoutBinding dsl_binding = {};
18325 dsl_binding.binding = 0;
18326 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18327 dsl_binding.descriptorCount = 1;
18328 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18329 dsl_binding.pImmutableSamplers = NULL;
18330
18331 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18332 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18333 ds_layout_ci.pNext = NULL;
18334 ds_layout_ci.bindingCount = 1;
18335 ds_layout_ci.pBindings = &dsl_binding;
18336 VkDescriptorSetLayout ds_layout;
18337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18338 ASSERT_VK_SUCCESS(err);
18339
18340 VkDescriptorSet descriptor_set;
18341 VkDescriptorSetAllocateInfo alloc_info = {};
18342 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18343 alloc_info.descriptorSetCount = 1;
18344 alloc_info.descriptorPool = ds_pool;
18345 alloc_info.pSetLayouts = &ds_layout;
18346 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18347 ASSERT_VK_SUCCESS(err);
18348
18349 VkDescriptorImageInfo image_info = {};
18350 image_info.imageView = view;
18351 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18352
18353 VkWriteDescriptorSet descriptor_write;
18354 memset(&descriptor_write, 0, sizeof(descriptor_write));
18355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18356 descriptor_write.dstSet = descriptor_set;
18357 descriptor_write.dstBinding = 0;
18358 descriptor_write.descriptorCount = 1;
18359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18360 descriptor_write.pImageInfo = &image_info;
18361
18362 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18363 // be
18364 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18365 // This will most likely produce a crash if the parameter_validation
18366 // layer
18367 // does not correctly ignore pBufferInfo.
18368 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18369 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18370
18371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18372
18373 m_errorMonitor->VerifyNotFound();
18374
18375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18376 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18377 vkDestroyImageView(m_device->device(), view, NULL);
18378 vkDestroyImage(m_device->device(), image, NULL);
18379 vkFreeMemory(m_device->device(), image_memory, NULL);
18380 }
18381
18382 // Buffer Case
18383 {
18384 m_errorMonitor->ExpectSuccess();
18385
18386 VkBuffer buffer;
18387 uint32_t queue_family_index = 0;
18388 VkBufferCreateInfo buffer_create_info = {};
18389 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18390 buffer_create_info.size = 1024;
18391 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18392 buffer_create_info.queueFamilyIndexCount = 1;
18393 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18394
18395 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18396 ASSERT_VK_SUCCESS(err);
18397
18398 VkMemoryRequirements memory_reqs;
18399 VkDeviceMemory buffer_memory;
18400 bool pass;
18401 VkMemoryAllocateInfo memory_info = {};
18402 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18403 memory_info.pNext = NULL;
18404 memory_info.allocationSize = 0;
18405 memory_info.memoryTypeIndex = 0;
18406
18407 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18408 memory_info.allocationSize = memory_reqs.size;
18409 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18410 ASSERT_TRUE(pass);
18411
18412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18413 ASSERT_VK_SUCCESS(err);
18414 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18415 ASSERT_VK_SUCCESS(err);
18416
18417 VkDescriptorPoolSize ds_type_count = {};
18418 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18419 ds_type_count.descriptorCount = 1;
18420
18421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18423 ds_pool_ci.pNext = NULL;
18424 ds_pool_ci.maxSets = 1;
18425 ds_pool_ci.poolSizeCount = 1;
18426 ds_pool_ci.pPoolSizes = &ds_type_count;
18427
18428 VkDescriptorPool ds_pool;
18429 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18430 ASSERT_VK_SUCCESS(err);
18431
18432 VkDescriptorSetLayoutBinding dsl_binding = {};
18433 dsl_binding.binding = 0;
18434 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18435 dsl_binding.descriptorCount = 1;
18436 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18437 dsl_binding.pImmutableSamplers = NULL;
18438
18439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18441 ds_layout_ci.pNext = NULL;
18442 ds_layout_ci.bindingCount = 1;
18443 ds_layout_ci.pBindings = &dsl_binding;
18444 VkDescriptorSetLayout ds_layout;
18445 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18446 ASSERT_VK_SUCCESS(err);
18447
18448 VkDescriptorSet descriptor_set;
18449 VkDescriptorSetAllocateInfo alloc_info = {};
18450 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18451 alloc_info.descriptorSetCount = 1;
18452 alloc_info.descriptorPool = ds_pool;
18453 alloc_info.pSetLayouts = &ds_layout;
18454 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18455 ASSERT_VK_SUCCESS(err);
18456
18457 VkDescriptorBufferInfo buffer_info = {};
18458 buffer_info.buffer = buffer;
18459 buffer_info.offset = 0;
18460 buffer_info.range = 1024;
18461
18462 VkWriteDescriptorSet descriptor_write;
18463 memset(&descriptor_write, 0, sizeof(descriptor_write));
18464 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18465 descriptor_write.dstSet = descriptor_set;
18466 descriptor_write.dstBinding = 0;
18467 descriptor_write.descriptorCount = 1;
18468 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18469 descriptor_write.pBufferInfo = &buffer_info;
18470
18471 // Set pImageInfo and pTexelBufferView to invalid values, which should
18472 // be
18473 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18474 // This will most likely produce a crash if the parameter_validation
18475 // layer
18476 // does not correctly ignore pImageInfo.
18477 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18478 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18479
18480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18481
18482 m_errorMonitor->VerifyNotFound();
18483
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18486 vkDestroyBuffer(m_device->device(), buffer, NULL);
18487 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18488 }
18489
18490 // Texel Buffer Case
18491 {
18492 m_errorMonitor->ExpectSuccess();
18493
18494 VkBuffer buffer;
18495 uint32_t queue_family_index = 0;
18496 VkBufferCreateInfo buffer_create_info = {};
18497 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18498 buffer_create_info.size = 1024;
18499 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18500 buffer_create_info.queueFamilyIndexCount = 1;
18501 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18502
18503 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18504 ASSERT_VK_SUCCESS(err);
18505
18506 VkMemoryRequirements memory_reqs;
18507 VkDeviceMemory buffer_memory;
18508 bool pass;
18509 VkMemoryAllocateInfo memory_info = {};
18510 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18511 memory_info.pNext = NULL;
18512 memory_info.allocationSize = 0;
18513 memory_info.memoryTypeIndex = 0;
18514
18515 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18516 memory_info.allocationSize = memory_reqs.size;
18517 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18518 ASSERT_TRUE(pass);
18519
18520 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18521 ASSERT_VK_SUCCESS(err);
18522 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18523 ASSERT_VK_SUCCESS(err);
18524
18525 VkBufferViewCreateInfo buff_view_ci = {};
18526 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18527 buff_view_ci.buffer = buffer;
18528 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18529 buff_view_ci.range = VK_WHOLE_SIZE;
18530 VkBufferView buffer_view;
18531 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18532
18533 VkDescriptorPoolSize ds_type_count = {};
18534 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18535 ds_type_count.descriptorCount = 1;
18536
18537 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18538 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18539 ds_pool_ci.pNext = NULL;
18540 ds_pool_ci.maxSets = 1;
18541 ds_pool_ci.poolSizeCount = 1;
18542 ds_pool_ci.pPoolSizes = &ds_type_count;
18543
18544 VkDescriptorPool ds_pool;
18545 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18546 ASSERT_VK_SUCCESS(err);
18547
18548 VkDescriptorSetLayoutBinding dsl_binding = {};
18549 dsl_binding.binding = 0;
18550 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18551 dsl_binding.descriptorCount = 1;
18552 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18553 dsl_binding.pImmutableSamplers = NULL;
18554
18555 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18556 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18557 ds_layout_ci.pNext = NULL;
18558 ds_layout_ci.bindingCount = 1;
18559 ds_layout_ci.pBindings = &dsl_binding;
18560 VkDescriptorSetLayout ds_layout;
18561 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18562 ASSERT_VK_SUCCESS(err);
18563
18564 VkDescriptorSet descriptor_set;
18565 VkDescriptorSetAllocateInfo alloc_info = {};
18566 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18567 alloc_info.descriptorSetCount = 1;
18568 alloc_info.descriptorPool = ds_pool;
18569 alloc_info.pSetLayouts = &ds_layout;
18570 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18571 ASSERT_VK_SUCCESS(err);
18572
18573 VkWriteDescriptorSet descriptor_write;
18574 memset(&descriptor_write, 0, sizeof(descriptor_write));
18575 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18576 descriptor_write.dstSet = descriptor_set;
18577 descriptor_write.dstBinding = 0;
18578 descriptor_write.descriptorCount = 1;
18579 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18580 descriptor_write.pTexelBufferView = &buffer_view;
18581
18582 // Set pImageInfo and pBufferInfo to invalid values, which should be
18583 // ignored for descriptorType ==
18584 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18585 // This will most likely produce a crash if the parameter_validation
18586 // layer
18587 // does not correctly ignore pImageInfo and pBufferInfo.
18588 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18589 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18590
18591 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18592
18593 m_errorMonitor->VerifyNotFound();
18594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018595 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18596 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18597 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18598 vkDestroyBuffer(m_device->device(), buffer, NULL);
18599 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18600 }
18601}
18602
Tobin Ehlisf7428442016-10-25 07:58:24 -060018603TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18604 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18605
18606 ASSERT_NO_FATAL_FAILURE(InitState());
18607 // Create layout where two binding #s are "1"
18608 static const uint32_t NUM_BINDINGS = 3;
18609 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18610 dsl_binding[0].binding = 1;
18611 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18612 dsl_binding[0].descriptorCount = 1;
18613 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18614 dsl_binding[0].pImmutableSamplers = NULL;
18615 dsl_binding[1].binding = 0;
18616 dsl_binding[1].descriptorCount = 1;
18617 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18618 dsl_binding[1].descriptorCount = 1;
18619 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18620 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018621 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018622 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18623 dsl_binding[2].descriptorCount = 1;
18624 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18625 dsl_binding[2].pImmutableSamplers = NULL;
18626
18627 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18628 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18629 ds_layout_ci.pNext = NULL;
18630 ds_layout_ci.bindingCount = NUM_BINDINGS;
18631 ds_layout_ci.pBindings = dsl_binding;
18632 VkDescriptorSetLayout ds_layout;
18633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18634 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18635 m_errorMonitor->VerifyFound();
18636}
18637
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018638TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018639 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18640
18641 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018642
Tony Barbour552f6c02016-12-21 14:34:07 -070018643 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018644
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018645 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18646
18647 {
18648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18649 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18650 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18651 m_errorMonitor->VerifyFound();
18652 }
18653
18654 {
18655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18656 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18657 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18658 m_errorMonitor->VerifyFound();
18659 }
18660
18661 {
18662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18663 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18664 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18665 m_errorMonitor->VerifyFound();
18666 }
18667
18668 {
18669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18670 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18671 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18672 m_errorMonitor->VerifyFound();
18673 }
18674
18675 {
18676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18677 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18678 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18679 m_errorMonitor->VerifyFound();
18680 }
18681
18682 {
18683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18684 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18685 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18686 m_errorMonitor->VerifyFound();
18687 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018688
18689 {
18690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18691 VkRect2D scissor = {{-1, 0}, {16, 16}};
18692 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18693 m_errorMonitor->VerifyFound();
18694 }
18695
18696 {
18697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18698 VkRect2D scissor = {{0, -2}, {16, 16}};
18699 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18700 m_errorMonitor->VerifyFound();
18701 }
18702
18703 {
18704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18705 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18706 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18707 m_errorMonitor->VerifyFound();
18708 }
18709
18710 {
18711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18712 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18713 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18714 m_errorMonitor->VerifyFound();
18715 }
18716
Tony Barbour552f6c02016-12-21 14:34:07 -070018717 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018718}
18719
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018720// This is a positive test. No failures are expected.
18721TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18722 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18723 VkResult err;
18724
18725 ASSERT_NO_FATAL_FAILURE(InitState());
18726 m_errorMonitor->ExpectSuccess();
18727 VkDescriptorPoolSize ds_type_count = {};
18728 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18729 ds_type_count.descriptorCount = 2;
18730
18731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18733 ds_pool_ci.pNext = NULL;
18734 ds_pool_ci.maxSets = 1;
18735 ds_pool_ci.poolSizeCount = 1;
18736 ds_pool_ci.pPoolSizes = &ds_type_count;
18737
18738 VkDescriptorPool ds_pool;
18739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18740 ASSERT_VK_SUCCESS(err);
18741
18742 // Create layout with two uniform buffer descriptors w/ empty binding between them
18743 static const uint32_t NUM_BINDINGS = 3;
18744 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18745 dsl_binding[0].binding = 0;
18746 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18747 dsl_binding[0].descriptorCount = 1;
18748 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18749 dsl_binding[0].pImmutableSamplers = NULL;
18750 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018751 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018752 dsl_binding[2].binding = 2;
18753 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18754 dsl_binding[2].descriptorCount = 1;
18755 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18756 dsl_binding[2].pImmutableSamplers = NULL;
18757
18758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18760 ds_layout_ci.pNext = NULL;
18761 ds_layout_ci.bindingCount = NUM_BINDINGS;
18762 ds_layout_ci.pBindings = dsl_binding;
18763 VkDescriptorSetLayout ds_layout;
18764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18765 ASSERT_VK_SUCCESS(err);
18766
18767 VkDescriptorSet descriptor_set = {};
18768 VkDescriptorSetAllocateInfo alloc_info = {};
18769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18770 alloc_info.descriptorSetCount = 1;
18771 alloc_info.descriptorPool = ds_pool;
18772 alloc_info.pSetLayouts = &ds_layout;
18773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18774 ASSERT_VK_SUCCESS(err);
18775
18776 // Create a buffer to be used for update
18777 VkBufferCreateInfo buff_ci = {};
18778 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18779 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18780 buff_ci.size = 256;
18781 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18782 VkBuffer buffer;
18783 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18784 ASSERT_VK_SUCCESS(err);
18785 // Have to bind memory to buffer before descriptor update
18786 VkMemoryAllocateInfo mem_alloc = {};
18787 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18788 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018789 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018790 mem_alloc.memoryTypeIndex = 0;
18791
18792 VkMemoryRequirements mem_reqs;
18793 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18794 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18795 if (!pass) {
18796 vkDestroyBuffer(m_device->device(), buffer, NULL);
18797 return;
18798 }
18799
18800 VkDeviceMemory mem;
18801 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18802 ASSERT_VK_SUCCESS(err);
18803 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18804 ASSERT_VK_SUCCESS(err);
18805
18806 // Only update the descriptor at binding 2
18807 VkDescriptorBufferInfo buff_info = {};
18808 buff_info.buffer = buffer;
18809 buff_info.offset = 0;
18810 buff_info.range = VK_WHOLE_SIZE;
18811 VkWriteDescriptorSet descriptor_write = {};
18812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18813 descriptor_write.dstBinding = 2;
18814 descriptor_write.descriptorCount = 1;
18815 descriptor_write.pTexelBufferView = nullptr;
18816 descriptor_write.pBufferInfo = &buff_info;
18817 descriptor_write.pImageInfo = nullptr;
18818 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18819 descriptor_write.dstSet = descriptor_set;
18820
18821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18822
18823 m_errorMonitor->VerifyNotFound();
18824 // Cleanup
18825 vkFreeMemory(m_device->device(), mem, NULL);
18826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18827 vkDestroyBuffer(m_device->device(), buffer, NULL);
18828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18829}
18830
18831// This is a positive test. No failures are expected.
18832TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18833 VkResult err;
18834 bool pass;
18835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018836 TEST_DESCRIPTION(
18837 "Create a buffer, allocate memory, bind memory, destroy "
18838 "the buffer, create an image, and bind the same memory to "
18839 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018840
18841 m_errorMonitor->ExpectSuccess();
18842
18843 ASSERT_NO_FATAL_FAILURE(InitState());
18844
18845 VkBuffer buffer;
18846 VkImage image;
18847 VkDeviceMemory mem;
18848 VkMemoryRequirements mem_reqs;
18849
18850 VkBufferCreateInfo buf_info = {};
18851 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18852 buf_info.pNext = NULL;
18853 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18854 buf_info.size = 256;
18855 buf_info.queueFamilyIndexCount = 0;
18856 buf_info.pQueueFamilyIndices = NULL;
18857 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18858 buf_info.flags = 0;
18859 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18860 ASSERT_VK_SUCCESS(err);
18861
18862 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18863
18864 VkMemoryAllocateInfo alloc_info = {};
18865 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18866 alloc_info.pNext = NULL;
18867 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018868
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018869 // Ensure memory is big enough for both bindings
18870 alloc_info.allocationSize = 0x10000;
18871
18872 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18873 if (!pass) {
18874 vkDestroyBuffer(m_device->device(), buffer, NULL);
18875 return;
18876 }
18877
18878 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18879 ASSERT_VK_SUCCESS(err);
18880
18881 uint8_t *pData;
18882 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18883 ASSERT_VK_SUCCESS(err);
18884
18885 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18886
18887 vkUnmapMemory(m_device->device(), mem);
18888
18889 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18890 ASSERT_VK_SUCCESS(err);
18891
18892 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18893 // memory. In fact, it was never used by the GPU.
18894 // Just be be sure, wait for idle.
18895 vkDestroyBuffer(m_device->device(), buffer, NULL);
18896 vkDeviceWaitIdle(m_device->device());
18897
Tobin Ehlis6a005702016-12-28 15:25:56 -070018898 // Use optimal as some platforms report linear support but then fail image creation
18899 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18900 VkImageFormatProperties image_format_properties;
18901 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18902 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18903 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018904 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018905 vkFreeMemory(m_device->device(), mem, NULL);
18906 return;
18907 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018908 VkImageCreateInfo image_create_info = {};
18909 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18910 image_create_info.pNext = NULL;
18911 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18912 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18913 image_create_info.extent.width = 64;
18914 image_create_info.extent.height = 64;
18915 image_create_info.extent.depth = 1;
18916 image_create_info.mipLevels = 1;
18917 image_create_info.arrayLayers = 1;
18918 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018919 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018920 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18921 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18922 image_create_info.queueFamilyIndexCount = 0;
18923 image_create_info.pQueueFamilyIndices = NULL;
18924 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18925 image_create_info.flags = 0;
18926
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018927 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018928 * to be textures or it will be the staging image if they are not.
18929 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018930 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18931 ASSERT_VK_SUCCESS(err);
18932
18933 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18934
Tobin Ehlis6a005702016-12-28 15:25:56 -070018935 VkMemoryAllocateInfo mem_alloc = {};
18936 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18937 mem_alloc.pNext = NULL;
18938 mem_alloc.allocationSize = 0;
18939 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018940 mem_alloc.allocationSize = mem_reqs.size;
18941
18942 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18943 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018944 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018945 vkDestroyImage(m_device->device(), image, NULL);
18946 return;
18947 }
18948
18949 // VALIDATION FAILURE:
18950 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18951 ASSERT_VK_SUCCESS(err);
18952
18953 m_errorMonitor->VerifyNotFound();
18954
18955 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018956 vkDestroyImage(m_device->device(), image, NULL);
18957}
18958
Tony Barbourab713912017-02-02 14:17:35 -070018959// This is a positive test. No failures are expected.
18960TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18961 VkResult err;
18962
18963 TEST_DESCRIPTION(
18964 "Call all applicable destroy and free routines with NULL"
18965 "handles, expecting no validation errors");
18966
18967 m_errorMonitor->ExpectSuccess();
18968
18969 ASSERT_NO_FATAL_FAILURE(InitState());
18970 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18971 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18972 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18973 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18974 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18975 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18976 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18977 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18978 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18979 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18980 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18981 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18982 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18983 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18984 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18985 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18986 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18987 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18988 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18989 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18990
18991 VkCommandPool command_pool;
18992 VkCommandPoolCreateInfo pool_create_info{};
18993 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18994 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18995 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18996 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18997 VkCommandBuffer command_buffers[3] = {};
18998 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18999 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19000 command_buffer_allocate_info.commandPool = command_pool;
19001 command_buffer_allocate_info.commandBufferCount = 1;
19002 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19003 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
19004 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
19005 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19006
19007 VkDescriptorPoolSize ds_type_count = {};
19008 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19009 ds_type_count.descriptorCount = 1;
19010
19011 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19012 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19013 ds_pool_ci.pNext = NULL;
19014 ds_pool_ci.maxSets = 1;
19015 ds_pool_ci.poolSizeCount = 1;
19016 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
19017 ds_pool_ci.pPoolSizes = &ds_type_count;
19018
19019 VkDescriptorPool ds_pool;
19020 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19021 ASSERT_VK_SUCCESS(err);
19022
19023 VkDescriptorSetLayoutBinding dsl_binding = {};
19024 dsl_binding.binding = 2;
19025 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19026 dsl_binding.descriptorCount = 1;
19027 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19028 dsl_binding.pImmutableSamplers = NULL;
19029 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19030 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19031 ds_layout_ci.pNext = NULL;
19032 ds_layout_ci.bindingCount = 1;
19033 ds_layout_ci.pBindings = &dsl_binding;
19034 VkDescriptorSetLayout ds_layout;
19035 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19036 ASSERT_VK_SUCCESS(err);
19037
19038 VkDescriptorSet descriptor_sets[3] = {};
19039 VkDescriptorSetAllocateInfo alloc_info = {};
19040 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19041 alloc_info.descriptorSetCount = 1;
19042 alloc_info.descriptorPool = ds_pool;
19043 alloc_info.pSetLayouts = &ds_layout;
19044 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
19045 ASSERT_VK_SUCCESS(err);
19046 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
19047 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19049
19050 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
19051
19052 m_errorMonitor->VerifyNotFound();
19053}
19054
Tony Barbour626994c2017-02-08 15:29:37 -070019055TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070019056 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070019057
19058 m_errorMonitor->ExpectSuccess();
19059
19060 ASSERT_NO_FATAL_FAILURE(InitState());
19061 VkCommandBuffer cmd_bufs[4];
19062 VkCommandBufferAllocateInfo alloc_info;
19063 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19064 alloc_info.pNext = NULL;
19065 alloc_info.commandBufferCount = 4;
19066 alloc_info.commandPool = m_commandPool;
19067 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19068 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
19069 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -070019070 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
19071 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
19072 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070019073 ASSERT_TRUE(image.initialized());
19074 VkCommandBufferBeginInfo cb_binfo;
19075 cb_binfo.pNext = NULL;
19076 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19077 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
19078 cb_binfo.flags = 0;
19079 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
19080 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
19081 VkImageMemoryBarrier img_barrier = {};
19082 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19083 img_barrier.pNext = NULL;
19084 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19085 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19086 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19087 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
19088 img_barrier.image = image.handle();
19089 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19090 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19091 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19092 img_barrier.subresourceRange.baseArrayLayer = 0;
19093 img_barrier.subresourceRange.baseMipLevel = 0;
19094 img_barrier.subresourceRange.layerCount = 1;
19095 img_barrier.subresourceRange.levelCount = 1;
19096 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19097 &img_barrier);
19098 vkEndCommandBuffer(cmd_bufs[0]);
19099 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
19100 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
19101 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19102 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19103 &img_barrier);
19104 vkEndCommandBuffer(cmd_bufs[1]);
19105 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19106 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19107 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19108 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19109 &img_barrier);
19110 vkEndCommandBuffer(cmd_bufs[2]);
19111 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19112 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19113 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19114 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19115 &img_barrier);
19116 vkEndCommandBuffer(cmd_bufs[3]);
19117
19118 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19119 VkSemaphore semaphore1, semaphore2;
19120 VkSemaphoreCreateInfo semaphore_create_info{};
19121 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19122 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19123 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19124 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19125 VkSubmitInfo submit_info[3];
19126 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19127 submit_info[0].pNext = nullptr;
19128 submit_info[0].commandBufferCount = 1;
19129 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19130 submit_info[0].signalSemaphoreCount = 1;
19131 submit_info[0].pSignalSemaphores = &semaphore1;
19132 submit_info[0].waitSemaphoreCount = 0;
19133 submit_info[0].pWaitDstStageMask = nullptr;
19134 submit_info[0].pWaitDstStageMask = flags;
19135 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19136 submit_info[1].pNext = nullptr;
19137 submit_info[1].commandBufferCount = 1;
19138 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19139 submit_info[1].waitSemaphoreCount = 1;
19140 submit_info[1].pWaitSemaphores = &semaphore1;
19141 submit_info[1].signalSemaphoreCount = 1;
19142 submit_info[1].pSignalSemaphores = &semaphore2;
19143 submit_info[1].pWaitDstStageMask = flags;
19144 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19145 submit_info[2].pNext = nullptr;
19146 submit_info[2].commandBufferCount = 2;
19147 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19148 submit_info[2].waitSemaphoreCount = 1;
19149 submit_info[2].pWaitSemaphores = &semaphore2;
19150 submit_info[2].signalSemaphoreCount = 0;
19151 submit_info[2].pSignalSemaphores = nullptr;
19152 submit_info[2].pWaitDstStageMask = flags;
19153 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19154 vkQueueWaitIdle(m_device->m_queue);
19155
19156 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19157 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19158 m_errorMonitor->VerifyNotFound();
19159}
19160
Tobin Ehlis953e8392016-11-17 10:54:13 -070019161TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19162 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19163 // We previously had a bug where dynamic offset of inactive bindings was still being used
19164 VkResult err;
19165 m_errorMonitor->ExpectSuccess();
19166
19167 ASSERT_NO_FATAL_FAILURE(InitState());
19168 ASSERT_NO_FATAL_FAILURE(InitViewport());
19169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19170
19171 VkDescriptorPoolSize ds_type_count = {};
19172 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19173 ds_type_count.descriptorCount = 3;
19174
19175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19177 ds_pool_ci.pNext = NULL;
19178 ds_pool_ci.maxSets = 1;
19179 ds_pool_ci.poolSizeCount = 1;
19180 ds_pool_ci.pPoolSizes = &ds_type_count;
19181
19182 VkDescriptorPool ds_pool;
19183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19184 ASSERT_VK_SUCCESS(err);
19185
19186 const uint32_t BINDING_COUNT = 3;
19187 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019188 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019189 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19190 dsl_binding[0].descriptorCount = 1;
19191 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19192 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019193 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019194 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19195 dsl_binding[1].descriptorCount = 1;
19196 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19197 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019198 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019199 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19200 dsl_binding[2].descriptorCount = 1;
19201 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19202 dsl_binding[2].pImmutableSamplers = NULL;
19203
19204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19206 ds_layout_ci.pNext = NULL;
19207 ds_layout_ci.bindingCount = BINDING_COUNT;
19208 ds_layout_ci.pBindings = dsl_binding;
19209 VkDescriptorSetLayout ds_layout;
19210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19211 ASSERT_VK_SUCCESS(err);
19212
19213 VkDescriptorSet descriptor_set;
19214 VkDescriptorSetAllocateInfo alloc_info = {};
19215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19216 alloc_info.descriptorSetCount = 1;
19217 alloc_info.descriptorPool = ds_pool;
19218 alloc_info.pSetLayouts = &ds_layout;
19219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19220 ASSERT_VK_SUCCESS(err);
19221
19222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19224 pipeline_layout_ci.pNext = NULL;
19225 pipeline_layout_ci.setLayoutCount = 1;
19226 pipeline_layout_ci.pSetLayouts = &ds_layout;
19227
19228 VkPipelineLayout pipeline_layout;
19229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19230 ASSERT_VK_SUCCESS(err);
19231
19232 // Create two buffers to update the descriptors with
19233 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19234 uint32_t qfi = 0;
19235 VkBufferCreateInfo buffCI = {};
19236 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19237 buffCI.size = 2048;
19238 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19239 buffCI.queueFamilyIndexCount = 1;
19240 buffCI.pQueueFamilyIndices = &qfi;
19241
19242 VkBuffer dyub1;
19243 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19244 ASSERT_VK_SUCCESS(err);
19245 // buffer2
19246 buffCI.size = 1024;
19247 VkBuffer dyub2;
19248 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19249 ASSERT_VK_SUCCESS(err);
19250 // Allocate memory and bind to buffers
19251 VkMemoryAllocateInfo mem_alloc[2] = {};
19252 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19253 mem_alloc[0].pNext = NULL;
19254 mem_alloc[0].memoryTypeIndex = 0;
19255 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19256 mem_alloc[1].pNext = NULL;
19257 mem_alloc[1].memoryTypeIndex = 0;
19258
19259 VkMemoryRequirements mem_reqs1;
19260 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19261 VkMemoryRequirements mem_reqs2;
19262 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19263 mem_alloc[0].allocationSize = mem_reqs1.size;
19264 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19265 mem_alloc[1].allocationSize = mem_reqs2.size;
19266 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19267 if (!pass) {
19268 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19269 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19270 return;
19271 }
19272
19273 VkDeviceMemory mem1;
19274 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19275 ASSERT_VK_SUCCESS(err);
19276 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19277 ASSERT_VK_SUCCESS(err);
19278 VkDeviceMemory mem2;
19279 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19280 ASSERT_VK_SUCCESS(err);
19281 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19282 ASSERT_VK_SUCCESS(err);
19283 // Update descriptors
19284 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19285 buff_info[0].buffer = dyub1;
19286 buff_info[0].offset = 0;
19287 buff_info[0].range = 256;
19288 buff_info[1].buffer = dyub1;
19289 buff_info[1].offset = 256;
19290 buff_info[1].range = 512;
19291 buff_info[2].buffer = dyub2;
19292 buff_info[2].offset = 0;
19293 buff_info[2].range = 512;
19294
19295 VkWriteDescriptorSet descriptor_write;
19296 memset(&descriptor_write, 0, sizeof(descriptor_write));
19297 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19298 descriptor_write.dstSet = descriptor_set;
19299 descriptor_write.dstBinding = 0;
19300 descriptor_write.descriptorCount = BINDING_COUNT;
19301 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19302 descriptor_write.pBufferInfo = buff_info;
19303
19304 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19305
Tony Barbour552f6c02016-12-21 14:34:07 -070019306 m_commandBuffer->BeginCommandBuffer();
19307 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019308
19309 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019310 char const *vsSource =
19311 "#version 450\n"
19312 "\n"
19313 "out gl_PerVertex { \n"
19314 " vec4 gl_Position;\n"
19315 "};\n"
19316 "void main(){\n"
19317 " gl_Position = vec4(1);\n"
19318 "}\n";
19319 char const *fsSource =
19320 "#version 450\n"
19321 "\n"
19322 "layout(location=0) out vec4 x;\n"
19323 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19324 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19325 "void main(){\n"
19326 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19327 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19330 VkPipelineObj pipe(m_device);
19331 pipe.SetViewport(m_viewports);
19332 pipe.SetScissor(m_scissors);
19333 pipe.AddShader(&vs);
19334 pipe.AddShader(&fs);
19335 pipe.AddColorAttachment();
19336 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19337
19338 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19339 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19340 // we used to have a bug in this case.
19341 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19342 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19343 &descriptor_set, BINDING_COUNT, dyn_off);
19344 Draw(1, 0, 0, 0);
19345 m_errorMonitor->VerifyNotFound();
19346
19347 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19348 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19349 vkFreeMemory(m_device->device(), mem1, NULL);
19350 vkFreeMemory(m_device->device(), mem2, NULL);
19351
19352 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19353 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19354 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19355}
19356
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019357TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019358 TEST_DESCRIPTION(
19359 "Ensure that validations handling of non-coherent memory "
19360 "mapping while using VK_WHOLE_SIZE does not cause access "
19361 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362 VkResult err;
19363 uint8_t *pData;
19364 ASSERT_NO_FATAL_FAILURE(InitState());
19365
19366 VkDeviceMemory mem;
19367 VkMemoryRequirements mem_reqs;
19368 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019369 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019370 VkMemoryAllocateInfo alloc_info = {};
19371 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19372 alloc_info.pNext = NULL;
19373 alloc_info.memoryTypeIndex = 0;
19374
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019375 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019376 alloc_info.allocationSize = allocation_size;
19377
19378 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19379 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 -070019380 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019381 if (!pass) {
19382 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019383 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19384 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019386 pass = m_device->phy().set_memory_type(
19387 mem_reqs.memoryTypeBits, &alloc_info,
19388 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19389 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019390 if (!pass) {
19391 return;
19392 }
19393 }
19394 }
19395
19396 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19397 ASSERT_VK_SUCCESS(err);
19398
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019399 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019400 m_errorMonitor->ExpectSuccess();
19401 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19402 ASSERT_VK_SUCCESS(err);
19403 VkMappedMemoryRange mmr = {};
19404 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19405 mmr.memory = mem;
19406 mmr.offset = 0;
19407 mmr.size = VK_WHOLE_SIZE;
19408 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19409 ASSERT_VK_SUCCESS(err);
19410 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19411 ASSERT_VK_SUCCESS(err);
19412 m_errorMonitor->VerifyNotFound();
19413 vkUnmapMemory(m_device->device(), mem);
19414
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019415 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019416 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019417 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019418 ASSERT_VK_SUCCESS(err);
19419 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19420 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019421 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019422 mmr.size = VK_WHOLE_SIZE;
19423 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19424 ASSERT_VK_SUCCESS(err);
19425 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19426 ASSERT_VK_SUCCESS(err);
19427 m_errorMonitor->VerifyNotFound();
19428 vkUnmapMemory(m_device->device(), mem);
19429
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019430 // Map with offset and size
19431 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019432 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019433 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019434 ASSERT_VK_SUCCESS(err);
19435 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19436 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019437 mmr.offset = 4 * atom_size;
19438 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019439 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19440 ASSERT_VK_SUCCESS(err);
19441 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19442 ASSERT_VK_SUCCESS(err);
19443 m_errorMonitor->VerifyNotFound();
19444 vkUnmapMemory(m_device->device(), mem);
19445
19446 // Map without offset and flush WHOLE_SIZE with two separate offsets
19447 m_errorMonitor->ExpectSuccess();
19448 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19449 ASSERT_VK_SUCCESS(err);
19450 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19451 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019452 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019453 mmr.size = VK_WHOLE_SIZE;
19454 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19455 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019456 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019457 mmr.size = VK_WHOLE_SIZE;
19458 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19459 ASSERT_VK_SUCCESS(err);
19460 m_errorMonitor->VerifyNotFound();
19461 vkUnmapMemory(m_device->device(), mem);
19462
19463 vkFreeMemory(m_device->device(), mem, NULL);
19464}
19465
19466// This is a positive test. We used to expect error in this case but spec now allows it
19467TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19468 m_errorMonitor->ExpectSuccess();
19469 vk_testing::Fence testFence;
19470 VkFenceCreateInfo fenceInfo = {};
19471 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19472 fenceInfo.pNext = NULL;
19473
19474 ASSERT_NO_FATAL_FAILURE(InitState());
19475 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019476 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019477 VkResult result = vkResetFences(m_device->device(), 1, fences);
19478 ASSERT_VK_SUCCESS(result);
19479
19480 m_errorMonitor->VerifyNotFound();
19481}
19482
19483TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19484 m_errorMonitor->ExpectSuccess();
19485
19486 ASSERT_NO_FATAL_FAILURE(InitState());
19487 VkResult err;
19488
19489 // Record (empty!) command buffer that can be submitted multiple times
19490 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019491 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19492 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019493 m_commandBuffer->BeginCommandBuffer(&cbbi);
19494 m_commandBuffer->EndCommandBuffer();
19495
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019496 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019497 VkFence fence;
19498 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19499 ASSERT_VK_SUCCESS(err);
19500
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019501 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019502 VkSemaphore s1, s2;
19503 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19504 ASSERT_VK_SUCCESS(err);
19505 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19506 ASSERT_VK_SUCCESS(err);
19507
19508 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019509 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019510 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19511 ASSERT_VK_SUCCESS(err);
19512
19513 // Submit CB again, signaling s2.
19514 si.pSignalSemaphores = &s2;
19515 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19516 ASSERT_VK_SUCCESS(err);
19517
19518 // Wait for fence.
19519 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19520 ASSERT_VK_SUCCESS(err);
19521
19522 // CB is still in flight from second submission, but semaphore s1 is no
19523 // longer in flight. delete it.
19524 vkDestroySemaphore(m_device->device(), s1, nullptr);
19525
19526 m_errorMonitor->VerifyNotFound();
19527
19528 // Force device idle and clean up remaining objects
19529 vkDeviceWaitIdle(m_device->device());
19530 vkDestroySemaphore(m_device->device(), s2, nullptr);
19531 vkDestroyFence(m_device->device(), fence, nullptr);
19532}
19533
19534TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19535 m_errorMonitor->ExpectSuccess();
19536
19537 ASSERT_NO_FATAL_FAILURE(InitState());
19538 VkResult err;
19539
19540 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019541 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019542 VkFence f1;
19543 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19544 ASSERT_VK_SUCCESS(err);
19545
19546 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019547 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019548 VkFence f2;
19549 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19550 ASSERT_VK_SUCCESS(err);
19551
19552 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019553 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019554 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19555
19556 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019557 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019558 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19559
19560 // Should have both retired!
19561 vkDestroyFence(m_device->device(), f1, nullptr);
19562 vkDestroyFence(m_device->device(), f2, nullptr);
19563
19564 m_errorMonitor->VerifyNotFound();
19565}
19566
19567TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019568 TEST_DESCRIPTION(
19569 "Verify that creating an image view from an image with valid usage "
19570 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019571
19572 ASSERT_NO_FATAL_FAILURE(InitState());
19573
19574 m_errorMonitor->ExpectSuccess();
19575 // Verify that we can create a view with usage INPUT_ATTACHMENT
19576 VkImageObj image(m_device);
19577 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19578 ASSERT_TRUE(image.initialized());
19579 VkImageView imageView;
19580 VkImageViewCreateInfo ivci = {};
19581 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19582 ivci.image = image.handle();
19583 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19584 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19585 ivci.subresourceRange.layerCount = 1;
19586 ivci.subresourceRange.baseMipLevel = 0;
19587 ivci.subresourceRange.levelCount = 1;
19588 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19589
19590 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19591 m_errorMonitor->VerifyNotFound();
19592 vkDestroyImageView(m_device->device(), imageView, NULL);
19593}
19594
19595// This is a positive test. No failures are expected.
19596TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019597 TEST_DESCRIPTION(
19598 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19599 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019600
19601 ASSERT_NO_FATAL_FAILURE(InitState());
19602
19603 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019604 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019605
19606 m_errorMonitor->ExpectSuccess();
19607
19608 VkImage image;
19609 VkImageCreateInfo image_create_info = {};
19610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19611 image_create_info.pNext = NULL;
19612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19613 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19614 image_create_info.extent.width = 64;
19615 image_create_info.extent.height = 64;
19616 image_create_info.extent.depth = 1;
19617 image_create_info.mipLevels = 1;
19618 image_create_info.arrayLayers = 1;
19619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19621 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19622 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19623 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19624 ASSERT_VK_SUCCESS(err);
19625
19626 VkMemoryRequirements memory_reqs;
19627 VkDeviceMemory memory_one, memory_two;
19628 bool pass;
19629 VkMemoryAllocateInfo memory_info = {};
19630 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19631 memory_info.pNext = NULL;
19632 memory_info.allocationSize = 0;
19633 memory_info.memoryTypeIndex = 0;
19634 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19635 // Find an image big enough to allow sparse mapping of 2 memory regions
19636 // Increase the image size until it is at least twice the
19637 // size of the required alignment, to ensure we can bind both
19638 // allocated memory blocks to the image on aligned offsets.
19639 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19640 vkDestroyImage(m_device->device(), image, nullptr);
19641 image_create_info.extent.width *= 2;
19642 image_create_info.extent.height *= 2;
19643 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19644 ASSERT_VK_SUCCESS(err);
19645 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19646 }
19647 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19648 // at the end of the first
19649 memory_info.allocationSize = memory_reqs.alignment;
19650 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19651 ASSERT_TRUE(pass);
19652 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19653 ASSERT_VK_SUCCESS(err);
19654 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19655 ASSERT_VK_SUCCESS(err);
19656 VkSparseMemoryBind binds[2];
19657 binds[0].flags = 0;
19658 binds[0].memory = memory_one;
19659 binds[0].memoryOffset = 0;
19660 binds[0].resourceOffset = 0;
19661 binds[0].size = memory_info.allocationSize;
19662 binds[1].flags = 0;
19663 binds[1].memory = memory_two;
19664 binds[1].memoryOffset = 0;
19665 binds[1].resourceOffset = memory_info.allocationSize;
19666 binds[1].size = memory_info.allocationSize;
19667
19668 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19669 opaqueBindInfo.image = image;
19670 opaqueBindInfo.bindCount = 2;
19671 opaqueBindInfo.pBinds = binds;
19672
19673 VkFence fence = VK_NULL_HANDLE;
19674 VkBindSparseInfo bindSparseInfo = {};
19675 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19676 bindSparseInfo.imageOpaqueBindCount = 1;
19677 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19678
19679 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19680 vkQueueWaitIdle(m_device->m_queue);
19681 vkDestroyImage(m_device->device(), image, NULL);
19682 vkFreeMemory(m_device->device(), memory_one, NULL);
19683 vkFreeMemory(m_device->device(), memory_two, NULL);
19684 m_errorMonitor->VerifyNotFound();
19685}
19686
19687TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019688 TEST_DESCRIPTION(
19689 "Ensure that CmdBeginRenderPass with an attachment's "
19690 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19691 "the command buffer has prior knowledge of that "
19692 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019693
19694 m_errorMonitor->ExpectSuccess();
19695
19696 ASSERT_NO_FATAL_FAILURE(InitState());
19697
19698 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019699 VkAttachmentDescription attachment = {0,
19700 VK_FORMAT_R8G8B8A8_UNORM,
19701 VK_SAMPLE_COUNT_1_BIT,
19702 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19703 VK_ATTACHMENT_STORE_OP_STORE,
19704 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19705 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19706 VK_IMAGE_LAYOUT_UNDEFINED,
19707 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019708
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019709 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019710
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019711 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019712
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019713 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019714
19715 VkRenderPass rp;
19716 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19717 ASSERT_VK_SUCCESS(err);
19718
19719 // A compatible framebuffer.
19720 VkImageObj image(m_device);
19721 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19722 ASSERT_TRUE(image.initialized());
19723
19724 VkImageViewCreateInfo ivci = {
19725 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19726 nullptr,
19727 0,
19728 image.handle(),
19729 VK_IMAGE_VIEW_TYPE_2D,
19730 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019731 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19732 VK_COMPONENT_SWIZZLE_IDENTITY},
19733 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019734 };
19735 VkImageView view;
19736 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19737 ASSERT_VK_SUCCESS(err);
19738
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019739 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019740 VkFramebuffer fb;
19741 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19742 ASSERT_VK_SUCCESS(err);
19743
19744 // Record a single command buffer which uses this renderpass twice. The
19745 // bug is triggered at the beginning of the second renderpass, when the
19746 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019747 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 -070019748 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019749 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19750 vkCmdEndRenderPass(m_commandBuffer->handle());
19751 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19752
19753 m_errorMonitor->VerifyNotFound();
19754
19755 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019756 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019757
19758 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19759 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19760 vkDestroyImageView(m_device->device(), view, nullptr);
19761}
19762
19763TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019764 TEST_DESCRIPTION(
19765 "This test should pass. Create a Framebuffer and "
19766 "command buffer, bind them together, then destroy "
19767 "command pool and framebuffer and verify there are no "
19768 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
19770 m_errorMonitor->ExpectSuccess();
19771
19772 ASSERT_NO_FATAL_FAILURE(InitState());
19773
19774 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019775 VkAttachmentDescription attachment = {0,
19776 VK_FORMAT_R8G8B8A8_UNORM,
19777 VK_SAMPLE_COUNT_1_BIT,
19778 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19779 VK_ATTACHMENT_STORE_OP_STORE,
19780 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19781 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19782 VK_IMAGE_LAYOUT_UNDEFINED,
19783 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019784
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019785 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019786
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019787 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019788
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019789 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019790
19791 VkRenderPass rp;
19792 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19793 ASSERT_VK_SUCCESS(err);
19794
19795 // A compatible framebuffer.
19796 VkImageObj image(m_device);
19797 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19798 ASSERT_TRUE(image.initialized());
19799
19800 VkImageViewCreateInfo ivci = {
19801 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19802 nullptr,
19803 0,
19804 image.handle(),
19805 VK_IMAGE_VIEW_TYPE_2D,
19806 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019807 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19808 VK_COMPONENT_SWIZZLE_IDENTITY},
19809 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019810 };
19811 VkImageView view;
19812 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19813 ASSERT_VK_SUCCESS(err);
19814
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019815 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019816 VkFramebuffer fb;
19817 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19818 ASSERT_VK_SUCCESS(err);
19819
19820 // Explicitly create a command buffer to bind the FB to so that we can then
19821 // destroy the command pool in order to implicitly free command buffer
19822 VkCommandPool command_pool;
19823 VkCommandPoolCreateInfo pool_create_info{};
19824 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19825 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19826 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19827 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19828
19829 VkCommandBuffer command_buffer;
19830 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19831 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19832 command_buffer_allocate_info.commandPool = command_pool;
19833 command_buffer_allocate_info.commandBufferCount = 1;
19834 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19835 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19836
19837 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019838 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 -060019839 VkCommandBufferBeginInfo begin_info{};
19840 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19841 vkBeginCommandBuffer(command_buffer, &begin_info);
19842
19843 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19844 vkCmdEndRenderPass(command_buffer);
19845 vkEndCommandBuffer(command_buffer);
19846 vkDestroyImageView(m_device->device(), view, nullptr);
19847 // Destroy command pool to implicitly free command buffer
19848 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19849 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19850 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19851 m_errorMonitor->VerifyNotFound();
19852}
19853
19854TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019855 TEST_DESCRIPTION(
19856 "Ensure that CmdBeginRenderPass applies the layout "
19857 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019858
19859 m_errorMonitor->ExpectSuccess();
19860
19861 ASSERT_NO_FATAL_FAILURE(InitState());
19862
19863 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019864 VkAttachmentDescription attachment = {0,
19865 VK_FORMAT_R8G8B8A8_UNORM,
19866 VK_SAMPLE_COUNT_1_BIT,
19867 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19868 VK_ATTACHMENT_STORE_OP_STORE,
19869 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19870 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19871 VK_IMAGE_LAYOUT_UNDEFINED,
19872 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019874 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019875
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019876 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019877
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019878 VkSubpassDependency dep = {0,
19879 0,
19880 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19881 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19882 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19883 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19884 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019885
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019886 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019887
19888 VkResult err;
19889 VkRenderPass rp;
19890 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19891 ASSERT_VK_SUCCESS(err);
19892
19893 // A compatible framebuffer.
19894 VkImageObj image(m_device);
19895 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19896 ASSERT_TRUE(image.initialized());
19897
19898 VkImageViewCreateInfo ivci = {
19899 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19900 nullptr,
19901 0,
19902 image.handle(),
19903 VK_IMAGE_VIEW_TYPE_2D,
19904 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019905 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19906 VK_COMPONENT_SWIZZLE_IDENTITY},
19907 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019908 };
19909 VkImageView view;
19910 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19911 ASSERT_VK_SUCCESS(err);
19912
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019913 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019914 VkFramebuffer fb;
19915 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19916 ASSERT_VK_SUCCESS(err);
19917
19918 // Record a single command buffer which issues a pipeline barrier w/
19919 // image memory barrier for the attachment. This detects the previously
19920 // missing tracking of the subpass layout by throwing a validation error
19921 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019922 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 -070019923 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019924 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19925
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019926 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19927 nullptr,
19928 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19929 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19930 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19931 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19932 VK_QUEUE_FAMILY_IGNORED,
19933 VK_QUEUE_FAMILY_IGNORED,
19934 image.handle(),
19935 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019936 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019937 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19938 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019939
19940 vkCmdEndRenderPass(m_commandBuffer->handle());
19941 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019942 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019943
19944 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19945 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19946 vkDestroyImageView(m_device->device(), view, nullptr);
19947}
19948
19949TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019950 TEST_DESCRIPTION(
19951 "Validate that when an imageView of a depth/stencil image "
19952 "is used as a depth/stencil framebuffer attachment, the "
19953 "aspectMask is ignored and both depth and stencil image "
19954 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019955
19956 VkFormatProperties format_properties;
19957 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19958 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19959 return;
19960 }
19961
19962 m_errorMonitor->ExpectSuccess();
19963
19964 ASSERT_NO_FATAL_FAILURE(InitState());
19965
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019966 VkAttachmentDescription attachment = {0,
19967 VK_FORMAT_D32_SFLOAT_S8_UINT,
19968 VK_SAMPLE_COUNT_1_BIT,
19969 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19970 VK_ATTACHMENT_STORE_OP_STORE,
19971 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19972 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19973 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19974 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019975
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019976 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019977
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019978 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019979
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019980 VkSubpassDependency dep = {0,
19981 0,
19982 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19983 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19984 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19985 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19986 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019987
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019988 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019989
19990 VkResult err;
19991 VkRenderPass rp;
19992 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19993 ASSERT_VK_SUCCESS(err);
19994
19995 VkImageObj image(m_device);
19996 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019997 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019998 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019999 ASSERT_TRUE(image.initialized());
20000 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
20001
20002 VkImageViewCreateInfo ivci = {
20003 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
20004 nullptr,
20005 0,
20006 image.handle(),
20007 VK_IMAGE_VIEW_TYPE_2D,
20008 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020009 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
20010 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020011 };
20012 VkImageView view;
20013 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
20014 ASSERT_VK_SUCCESS(err);
20015
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020016 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020017 VkFramebuffer fb;
20018 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20019 ASSERT_VK_SUCCESS(err);
20020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020021 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 -070020022 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020023 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20024
20025 VkImageMemoryBarrier imb = {};
20026 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20027 imb.pNext = nullptr;
20028 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20029 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20030 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20031 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
20032 imb.srcQueueFamilyIndex = 0;
20033 imb.dstQueueFamilyIndex = 0;
20034 imb.image = image.handle();
20035 imb.subresourceRange.aspectMask = 0x6;
20036 imb.subresourceRange.baseMipLevel = 0;
20037 imb.subresourceRange.levelCount = 0x1;
20038 imb.subresourceRange.baseArrayLayer = 0;
20039 imb.subresourceRange.layerCount = 0x1;
20040
20041 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020042 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
20043 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020044
20045 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070020046 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020047 QueueCommandBuffer(false);
20048 m_errorMonitor->VerifyNotFound();
20049
20050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20051 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20052 vkDestroyImageView(m_device->device(), view, nullptr);
20053}
20054
20055TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020056 TEST_DESCRIPTION(
20057 "Ensure that layout transitions work correctly without "
20058 "errors, when an attachment reference is "
20059 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020060
20061 m_errorMonitor->ExpectSuccess();
20062
20063 ASSERT_NO_FATAL_FAILURE(InitState());
20064
20065 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020066 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020067
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020068 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020070 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020071
20072 VkRenderPass rp;
20073 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20074 ASSERT_VK_SUCCESS(err);
20075
20076 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020077 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020078 VkFramebuffer fb;
20079 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20080 ASSERT_VK_SUCCESS(err);
20081
20082 // Record a command buffer which just begins and ends the renderpass. The
20083 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020084 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 -070020085 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020086 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20087 vkCmdEndRenderPass(m_commandBuffer->handle());
20088 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070020089 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020090
20091 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20092 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20093}
20094
20095// This is a positive test. No errors are expected.
20096TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020097 TEST_DESCRIPTION(
20098 "Create a stencil-only attachment with a LOAD_OP set to "
20099 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020100 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070020101 ASSERT_NO_FATAL_FAILURE(InitState());
20102 auto depth_format = find_depth_stencil_format(m_device);
20103 if (!depth_format) {
20104 printf(" No Depth + Stencil format found. Skipped.\n");
20105 return;
20106 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020107 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020108 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020109 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20110 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020111 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20112 return;
20113 }
20114
Tony Barbourf887b162017-03-09 10:06:46 -070020115 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020116 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020117 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020118 VkAttachmentDescription att = {};
20119 VkAttachmentReference ref = {};
20120 att.format = depth_stencil_fmt;
20121 att.samples = VK_SAMPLE_COUNT_1_BIT;
20122 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20123 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20124 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20125 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20126 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20127 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20128
20129 VkClearValue clear;
20130 clear.depthStencil.depth = 1.0;
20131 clear.depthStencil.stencil = 0;
20132 ref.attachment = 0;
20133 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20134
20135 VkSubpassDescription subpass = {};
20136 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20137 subpass.flags = 0;
20138 subpass.inputAttachmentCount = 0;
20139 subpass.pInputAttachments = NULL;
20140 subpass.colorAttachmentCount = 0;
20141 subpass.pColorAttachments = NULL;
20142 subpass.pResolveAttachments = NULL;
20143 subpass.pDepthStencilAttachment = &ref;
20144 subpass.preserveAttachmentCount = 0;
20145 subpass.pPreserveAttachments = NULL;
20146
20147 VkRenderPass rp;
20148 VkRenderPassCreateInfo rp_info = {};
20149 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20150 rp_info.attachmentCount = 1;
20151 rp_info.pAttachments = &att;
20152 rp_info.subpassCount = 1;
20153 rp_info.pSubpasses = &subpass;
20154 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20155 ASSERT_VK_SUCCESS(result);
20156
20157 VkImageView *depthView = m_depthStencil->BindInfo();
20158 VkFramebufferCreateInfo fb_info = {};
20159 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20160 fb_info.pNext = NULL;
20161 fb_info.renderPass = rp;
20162 fb_info.attachmentCount = 1;
20163 fb_info.pAttachments = depthView;
20164 fb_info.width = 100;
20165 fb_info.height = 100;
20166 fb_info.layers = 1;
20167 VkFramebuffer fb;
20168 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20169 ASSERT_VK_SUCCESS(result);
20170
20171 VkRenderPassBeginInfo rpbinfo = {};
20172 rpbinfo.clearValueCount = 1;
20173 rpbinfo.pClearValues = &clear;
20174 rpbinfo.pNext = NULL;
20175 rpbinfo.renderPass = rp;
20176 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20177 rpbinfo.renderArea.extent.width = 100;
20178 rpbinfo.renderArea.extent.height = 100;
20179 rpbinfo.renderArea.offset.x = 0;
20180 rpbinfo.renderArea.offset.y = 0;
20181 rpbinfo.framebuffer = fb;
20182
20183 VkFence fence = {};
20184 VkFenceCreateInfo fence_ci = {};
20185 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20186 fence_ci.pNext = nullptr;
20187 fence_ci.flags = 0;
20188 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20189 ASSERT_VK_SUCCESS(result);
20190
20191 m_commandBuffer->BeginCommandBuffer();
20192 m_commandBuffer->BeginRenderPass(rpbinfo);
20193 m_commandBuffer->EndRenderPass();
20194 m_commandBuffer->EndCommandBuffer();
20195 m_commandBuffer->QueueCommandBuffer(fence);
20196
20197 VkImageObj destImage(m_device);
20198 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 -070020199 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020200 VkImageMemoryBarrier barrier = {};
20201 VkImageSubresourceRange range;
20202 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20203 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20204 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20205 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20206 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20207 barrier.image = m_depthStencil->handle();
20208 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20209 range.baseMipLevel = 0;
20210 range.levelCount = 1;
20211 range.baseArrayLayer = 0;
20212 range.layerCount = 1;
20213 barrier.subresourceRange = range;
20214 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20215 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20216 cmdbuf.BeginCommandBuffer();
20217 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 -070020218 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020219 barrier.srcAccessMask = 0;
20220 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20221 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20222 barrier.image = destImage.handle();
20223 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20224 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 -070020225 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020226 VkImageCopy cregion;
20227 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20228 cregion.srcSubresource.mipLevel = 0;
20229 cregion.srcSubresource.baseArrayLayer = 0;
20230 cregion.srcSubresource.layerCount = 1;
20231 cregion.srcOffset.x = 0;
20232 cregion.srcOffset.y = 0;
20233 cregion.srcOffset.z = 0;
20234 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20235 cregion.dstSubresource.mipLevel = 0;
20236 cregion.dstSubresource.baseArrayLayer = 0;
20237 cregion.dstSubresource.layerCount = 1;
20238 cregion.dstOffset.x = 0;
20239 cregion.dstOffset.y = 0;
20240 cregion.dstOffset.z = 0;
20241 cregion.extent.width = 100;
20242 cregion.extent.height = 100;
20243 cregion.extent.depth = 1;
20244 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020245 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020246 cmdbuf.EndCommandBuffer();
20247
20248 VkSubmitInfo submit_info;
20249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20250 submit_info.pNext = NULL;
20251 submit_info.waitSemaphoreCount = 0;
20252 submit_info.pWaitSemaphores = NULL;
20253 submit_info.pWaitDstStageMask = NULL;
20254 submit_info.commandBufferCount = 1;
20255 submit_info.pCommandBuffers = &cmdbuf.handle();
20256 submit_info.signalSemaphoreCount = 0;
20257 submit_info.pSignalSemaphores = NULL;
20258
20259 m_errorMonitor->ExpectSuccess();
20260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20261 m_errorMonitor->VerifyNotFound();
20262
20263 vkQueueWaitIdle(m_device->m_queue);
20264 vkDestroyFence(m_device->device(), fence, nullptr);
20265 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20266 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20267}
20268
20269// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070020270TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
20271 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
20272
20273 m_errorMonitor->ExpectSuccess();
20274
20275 ASSERT_NO_FATAL_FAILURE(InitState());
20276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20277
20278 VkImageMemoryBarrier img_barrier = {};
20279 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20280 img_barrier.pNext = NULL;
20281 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20282 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20283 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20284 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20285 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20286 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20287 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20288 img_barrier.subresourceRange.baseArrayLayer = 0;
20289 img_barrier.subresourceRange.baseMipLevel = 0;
20290 img_barrier.subresourceRange.layerCount = 1;
20291 img_barrier.subresourceRange.levelCount = 1;
20292
20293 {
20294 VkImageObj img_color(m_device);
20295 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20296 ASSERT_TRUE(img_color.initialized());
20297
20298 VkImageObj img_ds1(m_device);
20299 img_ds1.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20300 ASSERT_TRUE(img_ds1.initialized());
20301
20302 VkImageObj img_ds2(m_device);
20303 img_ds2.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20304 ASSERT_TRUE(img_ds2.initialized());
20305
20306 VkImageObj img_xfer_src(m_device);
20307 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
20308 ASSERT_TRUE(img_xfer_src.initialized());
20309
20310 VkImageObj img_xfer_dst(m_device);
20311 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
20312 ASSERT_TRUE(img_xfer_dst.initialized());
20313
20314 VkImageObj img_sampled(m_device);
20315 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
20316 ASSERT_TRUE(img_sampled.initialized());
20317
20318 VkImageObj img_input(m_device);
20319 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20320 ASSERT_TRUE(img_input.initialized());
20321
20322 const struct {
20323 VkImageObj &image_obj;
20324 VkImageLayout old_layout;
20325 VkImageLayout new_layout;
20326 } buffer_layouts[] = {
20327 // clang-format off
20328 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20329 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20330 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20331 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20332 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20333 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20334 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20335 // clang-format on
20336 };
20337 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
20338
20339 m_commandBuffer->BeginCommandBuffer();
20340 for (uint32_t i = 0; i < layout_count; ++i) {
20341 img_barrier.image = buffer_layouts[i].image_obj.handle();
20342 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
20343 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
20344 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
20345 : VK_IMAGE_ASPECT_COLOR_BIT;
20346
20347 img_barrier.oldLayout = buffer_layouts[i].old_layout;
20348 img_barrier.newLayout = buffer_layouts[i].new_layout;
20349 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20350 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20351
20352 img_barrier.oldLayout = buffer_layouts[i].new_layout;
20353 img_barrier.newLayout = buffer_layouts[i].old_layout;
20354 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20355 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20356 }
20357 m_commandBuffer->EndCommandBuffer();
20358
20359 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20360 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20361 }
20362 m_errorMonitor->VerifyNotFound();
20363}
20364
20365// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020366TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20367 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20368
20369 m_errorMonitor->ExpectSuccess();
20370 ASSERT_NO_FATAL_FAILURE(InitState());
20371
20372 VkEvent event;
20373 VkEventCreateInfo event_create_info{};
20374 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20375 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20376
20377 VkCommandPool command_pool;
20378 VkCommandPoolCreateInfo pool_create_info{};
20379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20382 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20383
20384 VkCommandBuffer command_buffer;
20385 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20386 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20387 command_buffer_allocate_info.commandPool = command_pool;
20388 command_buffer_allocate_info.commandBufferCount = 1;
20389 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20390 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20391
20392 VkQueue queue = VK_NULL_HANDLE;
20393 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20394
20395 {
20396 VkCommandBufferBeginInfo begin_info{};
20397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20398 vkBeginCommandBuffer(command_buffer, &begin_info);
20399
20400 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 -070020401 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020402 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20403 vkEndCommandBuffer(command_buffer);
20404 }
20405 {
20406 VkSubmitInfo submit_info{};
20407 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20408 submit_info.commandBufferCount = 1;
20409 submit_info.pCommandBuffers = &command_buffer;
20410 submit_info.signalSemaphoreCount = 0;
20411 submit_info.pSignalSemaphores = nullptr;
20412 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20413 }
20414 { vkSetEvent(m_device->device(), event); }
20415
20416 vkQueueWaitIdle(queue);
20417
20418 vkDestroyEvent(m_device->device(), event, nullptr);
20419 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20420 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20421
20422 m_errorMonitor->VerifyNotFound();
20423}
20424// This is a positive test. No errors should be generated.
20425TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20426 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20427
20428 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020429 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020430
20431 m_errorMonitor->ExpectSuccess();
20432
20433 VkQueryPool query_pool;
20434 VkQueryPoolCreateInfo query_pool_create_info{};
20435 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20436 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20437 query_pool_create_info.queryCount = 1;
20438 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20439
20440 VkCommandPool command_pool;
20441 VkCommandPoolCreateInfo pool_create_info{};
20442 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20443 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20444 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20445 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20446
20447 VkCommandBuffer command_buffer;
20448 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20449 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20450 command_buffer_allocate_info.commandPool = command_pool;
20451 command_buffer_allocate_info.commandBufferCount = 1;
20452 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20453 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20454
20455 VkCommandBuffer secondary_command_buffer;
20456 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20457 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20458
20459 VkQueue queue = VK_NULL_HANDLE;
20460 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20461
20462 uint32_t qfi = 0;
20463 VkBufferCreateInfo buff_create_info = {};
20464 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20465 buff_create_info.size = 1024;
20466 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20467 buff_create_info.queueFamilyIndexCount = 1;
20468 buff_create_info.pQueueFamilyIndices = &qfi;
20469
20470 VkResult err;
20471 VkBuffer buffer;
20472 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20473 ASSERT_VK_SUCCESS(err);
20474 VkMemoryAllocateInfo mem_alloc = {};
20475 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20476 mem_alloc.pNext = NULL;
20477 mem_alloc.allocationSize = 1024;
20478 mem_alloc.memoryTypeIndex = 0;
20479
20480 VkMemoryRequirements memReqs;
20481 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20482 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20483 if (!pass) {
20484 vkDestroyBuffer(m_device->device(), buffer, NULL);
20485 return;
20486 }
20487
20488 VkDeviceMemory mem;
20489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20490 ASSERT_VK_SUCCESS(err);
20491 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20492 ASSERT_VK_SUCCESS(err);
20493
20494 VkCommandBufferInheritanceInfo hinfo = {};
20495 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20496 hinfo.renderPass = VK_NULL_HANDLE;
20497 hinfo.subpass = 0;
20498 hinfo.framebuffer = VK_NULL_HANDLE;
20499 hinfo.occlusionQueryEnable = VK_FALSE;
20500 hinfo.queryFlags = 0;
20501 hinfo.pipelineStatistics = 0;
20502
20503 {
20504 VkCommandBufferBeginInfo begin_info{};
20505 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20506 begin_info.pInheritanceInfo = &hinfo;
20507 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20508
20509 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20510 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20511
20512 vkEndCommandBuffer(secondary_command_buffer);
20513
20514 begin_info.pInheritanceInfo = nullptr;
20515 vkBeginCommandBuffer(command_buffer, &begin_info);
20516
20517 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20518 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20519
20520 vkEndCommandBuffer(command_buffer);
20521 }
20522 {
20523 VkSubmitInfo submit_info{};
20524 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20525 submit_info.commandBufferCount = 1;
20526 submit_info.pCommandBuffers = &command_buffer;
20527 submit_info.signalSemaphoreCount = 0;
20528 submit_info.pSignalSemaphores = nullptr;
20529 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20530 }
20531
20532 vkQueueWaitIdle(queue);
20533
20534 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20535 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20536 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20537 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20538 vkDestroyBuffer(m_device->device(), buffer, NULL);
20539 vkFreeMemory(m_device->device(), mem, NULL);
20540
20541 m_errorMonitor->VerifyNotFound();
20542}
20543
20544// This is a positive test. No errors should be generated.
20545TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20546 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20547
20548 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020549 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020550
20551 m_errorMonitor->ExpectSuccess();
20552
20553 VkQueryPool query_pool;
20554 VkQueryPoolCreateInfo query_pool_create_info{};
20555 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20556 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20557 query_pool_create_info.queryCount = 1;
20558 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20559
20560 VkCommandPool command_pool;
20561 VkCommandPoolCreateInfo pool_create_info{};
20562 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20563 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20564 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20565 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20566
20567 VkCommandBuffer command_buffer[2];
20568 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20569 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20570 command_buffer_allocate_info.commandPool = command_pool;
20571 command_buffer_allocate_info.commandBufferCount = 2;
20572 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20573 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20574
20575 VkQueue queue = VK_NULL_HANDLE;
20576 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20577
20578 uint32_t qfi = 0;
20579 VkBufferCreateInfo buff_create_info = {};
20580 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20581 buff_create_info.size = 1024;
20582 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20583 buff_create_info.queueFamilyIndexCount = 1;
20584 buff_create_info.pQueueFamilyIndices = &qfi;
20585
20586 VkResult err;
20587 VkBuffer buffer;
20588 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20589 ASSERT_VK_SUCCESS(err);
20590 VkMemoryAllocateInfo mem_alloc = {};
20591 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20592 mem_alloc.pNext = NULL;
20593 mem_alloc.allocationSize = 1024;
20594 mem_alloc.memoryTypeIndex = 0;
20595
20596 VkMemoryRequirements memReqs;
20597 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20598 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20599 if (!pass) {
20600 vkDestroyBuffer(m_device->device(), buffer, NULL);
20601 return;
20602 }
20603
20604 VkDeviceMemory mem;
20605 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20606 ASSERT_VK_SUCCESS(err);
20607 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20608 ASSERT_VK_SUCCESS(err);
20609
20610 {
20611 VkCommandBufferBeginInfo begin_info{};
20612 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20613 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20614
20615 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20616 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20617
20618 vkEndCommandBuffer(command_buffer[0]);
20619
20620 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20621
20622 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20623
20624 vkEndCommandBuffer(command_buffer[1]);
20625 }
20626 {
20627 VkSubmitInfo submit_info{};
20628 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20629 submit_info.commandBufferCount = 2;
20630 submit_info.pCommandBuffers = command_buffer;
20631 submit_info.signalSemaphoreCount = 0;
20632 submit_info.pSignalSemaphores = nullptr;
20633 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20634 }
20635
20636 vkQueueWaitIdle(queue);
20637
20638 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20639 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20640 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20641 vkDestroyBuffer(m_device->device(), buffer, NULL);
20642 vkFreeMemory(m_device->device(), mem, NULL);
20643
20644 m_errorMonitor->VerifyNotFound();
20645}
20646
Tony Barbourc46924f2016-11-04 11:49:52 -060020647TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020648 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20649
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020650 ASSERT_NO_FATAL_FAILURE(InitState());
20651 VkEvent event;
20652 VkEventCreateInfo event_create_info{};
20653 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20654 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20655
20656 VkCommandPool command_pool;
20657 VkCommandPoolCreateInfo pool_create_info{};
20658 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20659 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20660 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20661 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20662
20663 VkCommandBuffer command_buffer;
20664 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20665 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20666 command_buffer_allocate_info.commandPool = command_pool;
20667 command_buffer_allocate_info.commandBufferCount = 1;
20668 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20669 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20670
20671 VkQueue queue = VK_NULL_HANDLE;
20672 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20673
20674 {
20675 VkCommandBufferBeginInfo begin_info{};
20676 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20677 vkBeginCommandBuffer(command_buffer, &begin_info);
20678
20679 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020680 vkEndCommandBuffer(command_buffer);
20681 }
20682 {
20683 VkSubmitInfo submit_info{};
20684 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20685 submit_info.commandBufferCount = 1;
20686 submit_info.pCommandBuffers = &command_buffer;
20687 submit_info.signalSemaphoreCount = 0;
20688 submit_info.pSignalSemaphores = nullptr;
20689 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20690 }
20691 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20693 "that is already in use by a "
20694 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020695 vkSetEvent(m_device->device(), event);
20696 m_errorMonitor->VerifyFound();
20697 }
20698
20699 vkQueueWaitIdle(queue);
20700
20701 vkDestroyEvent(m_device->device(), event, nullptr);
20702 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20703 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20704}
20705
20706// This is a positive test. No errors should be generated.
20707TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020708 TEST_DESCRIPTION(
20709 "Two command buffers with two separate fences are each "
20710 "run through a Submit & WaitForFences cycle 3 times. This "
20711 "previously revealed a bug so running this positive test "
20712 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020713 m_errorMonitor->ExpectSuccess();
20714
20715 ASSERT_NO_FATAL_FAILURE(InitState());
20716 VkQueue queue = VK_NULL_HANDLE;
20717 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20718
20719 static const uint32_t NUM_OBJECTS = 2;
20720 static const uint32_t NUM_FRAMES = 3;
20721 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20722 VkFence fences[NUM_OBJECTS] = {};
20723
20724 VkCommandPool cmd_pool;
20725 VkCommandPoolCreateInfo cmd_pool_ci = {};
20726 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20727 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20728 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20729 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20730 ASSERT_VK_SUCCESS(err);
20731
20732 VkCommandBufferAllocateInfo cmd_buf_info = {};
20733 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20734 cmd_buf_info.commandPool = cmd_pool;
20735 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20736 cmd_buf_info.commandBufferCount = 1;
20737
20738 VkFenceCreateInfo fence_ci = {};
20739 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20740 fence_ci.pNext = nullptr;
20741 fence_ci.flags = 0;
20742
20743 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20744 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20745 ASSERT_VK_SUCCESS(err);
20746 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20747 ASSERT_VK_SUCCESS(err);
20748 }
20749
20750 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20751 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20752 // Create empty cmd buffer
20753 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20754 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20755
20756 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20757 ASSERT_VK_SUCCESS(err);
20758 err = vkEndCommandBuffer(cmd_buffers[obj]);
20759 ASSERT_VK_SUCCESS(err);
20760
20761 VkSubmitInfo submit_info = {};
20762 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20763 submit_info.commandBufferCount = 1;
20764 submit_info.pCommandBuffers = &cmd_buffers[obj];
20765 // Submit cmd buffer and wait for fence
20766 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20767 ASSERT_VK_SUCCESS(err);
20768 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20769 ASSERT_VK_SUCCESS(err);
20770 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20771 ASSERT_VK_SUCCESS(err);
20772 }
20773 }
20774 m_errorMonitor->VerifyNotFound();
20775 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20776 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20777 vkDestroyFence(m_device->device(), fences[i], nullptr);
20778 }
20779}
20780// This is a positive test. No errors should be generated.
20781TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020782 TEST_DESCRIPTION(
20783 "Two command buffers, each in a separate QueueSubmit call "
20784 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020785
20786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020787 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020788
20789 m_errorMonitor->ExpectSuccess();
20790
20791 VkSemaphore semaphore;
20792 VkSemaphoreCreateInfo semaphore_create_info{};
20793 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20794 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20795
20796 VkCommandPool command_pool;
20797 VkCommandPoolCreateInfo pool_create_info{};
20798 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20799 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20800 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20801 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20802
20803 VkCommandBuffer command_buffer[2];
20804 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20805 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20806 command_buffer_allocate_info.commandPool = command_pool;
20807 command_buffer_allocate_info.commandBufferCount = 2;
20808 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20809 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20810
20811 VkQueue queue = VK_NULL_HANDLE;
20812 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20813
20814 {
20815 VkCommandBufferBeginInfo begin_info{};
20816 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20817 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20818
20819 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 -070020820 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020821
20822 VkViewport viewport{};
20823 viewport.maxDepth = 1.0f;
20824 viewport.minDepth = 0.0f;
20825 viewport.width = 512;
20826 viewport.height = 512;
20827 viewport.x = 0;
20828 viewport.y = 0;
20829 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20830 vkEndCommandBuffer(command_buffer[0]);
20831 }
20832 {
20833 VkCommandBufferBeginInfo begin_info{};
20834 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20835 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20836
20837 VkViewport viewport{};
20838 viewport.maxDepth = 1.0f;
20839 viewport.minDepth = 0.0f;
20840 viewport.width = 512;
20841 viewport.height = 512;
20842 viewport.x = 0;
20843 viewport.y = 0;
20844 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20845 vkEndCommandBuffer(command_buffer[1]);
20846 }
20847 {
20848 VkSubmitInfo submit_info{};
20849 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20850 submit_info.commandBufferCount = 1;
20851 submit_info.pCommandBuffers = &command_buffer[0];
20852 submit_info.signalSemaphoreCount = 1;
20853 submit_info.pSignalSemaphores = &semaphore;
20854 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20855 }
20856 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020857 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020858 VkSubmitInfo submit_info{};
20859 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20860 submit_info.commandBufferCount = 1;
20861 submit_info.pCommandBuffers = &command_buffer[1];
20862 submit_info.waitSemaphoreCount = 1;
20863 submit_info.pWaitSemaphores = &semaphore;
20864 submit_info.pWaitDstStageMask = flags;
20865 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20866 }
20867
20868 vkQueueWaitIdle(m_device->m_queue);
20869
20870 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20871 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20872 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20873
20874 m_errorMonitor->VerifyNotFound();
20875}
20876
20877// This is a positive test. No errors should be generated.
20878TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020879 TEST_DESCRIPTION(
20880 "Two command buffers, each in a separate QueueSubmit call "
20881 "submitted on separate queues, the second having a fence"
20882 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020883
20884 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020885 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020886
20887 m_errorMonitor->ExpectSuccess();
20888
20889 VkFence fence;
20890 VkFenceCreateInfo fence_create_info{};
20891 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20892 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20893
20894 VkSemaphore semaphore;
20895 VkSemaphoreCreateInfo semaphore_create_info{};
20896 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20897 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20898
20899 VkCommandPool command_pool;
20900 VkCommandPoolCreateInfo pool_create_info{};
20901 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20902 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20903 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20904 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20905
20906 VkCommandBuffer command_buffer[2];
20907 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20908 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20909 command_buffer_allocate_info.commandPool = command_pool;
20910 command_buffer_allocate_info.commandBufferCount = 2;
20911 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20912 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20913
20914 VkQueue queue = VK_NULL_HANDLE;
20915 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20916
20917 {
20918 VkCommandBufferBeginInfo begin_info{};
20919 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20920 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20921
20922 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 -070020923 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020924
20925 VkViewport viewport{};
20926 viewport.maxDepth = 1.0f;
20927 viewport.minDepth = 0.0f;
20928 viewport.width = 512;
20929 viewport.height = 512;
20930 viewport.x = 0;
20931 viewport.y = 0;
20932 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20933 vkEndCommandBuffer(command_buffer[0]);
20934 }
20935 {
20936 VkCommandBufferBeginInfo begin_info{};
20937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20938 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20939
20940 VkViewport viewport{};
20941 viewport.maxDepth = 1.0f;
20942 viewport.minDepth = 0.0f;
20943 viewport.width = 512;
20944 viewport.height = 512;
20945 viewport.x = 0;
20946 viewport.y = 0;
20947 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20948 vkEndCommandBuffer(command_buffer[1]);
20949 }
20950 {
20951 VkSubmitInfo submit_info{};
20952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20953 submit_info.commandBufferCount = 1;
20954 submit_info.pCommandBuffers = &command_buffer[0];
20955 submit_info.signalSemaphoreCount = 1;
20956 submit_info.pSignalSemaphores = &semaphore;
20957 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20958 }
20959 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020960 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020961 VkSubmitInfo submit_info{};
20962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20963 submit_info.commandBufferCount = 1;
20964 submit_info.pCommandBuffers = &command_buffer[1];
20965 submit_info.waitSemaphoreCount = 1;
20966 submit_info.pWaitSemaphores = &semaphore;
20967 submit_info.pWaitDstStageMask = flags;
20968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20969 }
20970
20971 vkQueueWaitIdle(m_device->m_queue);
20972
20973 vkDestroyFence(m_device->device(), fence, nullptr);
20974 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20975 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20976 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20977
20978 m_errorMonitor->VerifyNotFound();
20979}
20980
20981// This is a positive test. No errors should be generated.
20982TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020983 TEST_DESCRIPTION(
20984 "Two command buffers, each in a separate QueueSubmit call "
20985 "submitted on separate queues, the second having a fence"
20986 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020987
20988 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020989 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020990
20991 m_errorMonitor->ExpectSuccess();
20992
20993 VkFence fence;
20994 VkFenceCreateInfo fence_create_info{};
20995 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20996 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20997
20998 VkSemaphore semaphore;
20999 VkSemaphoreCreateInfo semaphore_create_info{};
21000 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21001 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21002
21003 VkCommandPool command_pool;
21004 VkCommandPoolCreateInfo pool_create_info{};
21005 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21006 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21007 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21008 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21009
21010 VkCommandBuffer command_buffer[2];
21011 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21012 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21013 command_buffer_allocate_info.commandPool = command_pool;
21014 command_buffer_allocate_info.commandBufferCount = 2;
21015 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21016 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21017
21018 VkQueue queue = VK_NULL_HANDLE;
21019 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21020
21021 {
21022 VkCommandBufferBeginInfo begin_info{};
21023 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21024 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21025
21026 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 -070021027 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021028
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[0], 0, 1, &viewport);
21037 vkEndCommandBuffer(command_buffer[0]);
21038 }
21039 {
21040 VkCommandBufferBeginInfo begin_info{};
21041 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21042 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21043
21044 VkViewport viewport{};
21045 viewport.maxDepth = 1.0f;
21046 viewport.minDepth = 0.0f;
21047 viewport.width = 512;
21048 viewport.height = 512;
21049 viewport.x = 0;
21050 viewport.y = 0;
21051 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21052 vkEndCommandBuffer(command_buffer[1]);
21053 }
21054 {
21055 VkSubmitInfo submit_info{};
21056 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21057 submit_info.commandBufferCount = 1;
21058 submit_info.pCommandBuffers = &command_buffer[0];
21059 submit_info.signalSemaphoreCount = 1;
21060 submit_info.pSignalSemaphores = &semaphore;
21061 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21062 }
21063 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021064 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021065 VkSubmitInfo submit_info{};
21066 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21067 submit_info.commandBufferCount = 1;
21068 submit_info.pCommandBuffers = &command_buffer[1];
21069 submit_info.waitSemaphoreCount = 1;
21070 submit_info.pWaitSemaphores = &semaphore;
21071 submit_info.pWaitDstStageMask = flags;
21072 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21073 }
21074
21075 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21076 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21077
21078 vkDestroyFence(m_device->device(), fence, nullptr);
21079 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21080 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21081 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21082
21083 m_errorMonitor->VerifyNotFound();
21084}
21085
21086TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021087 ASSERT_NO_FATAL_FAILURE(InitState());
21088 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021089 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021090 return;
21091 }
21092
21093 VkResult err;
21094
21095 m_errorMonitor->ExpectSuccess();
21096
21097 VkQueue q0 = m_device->m_queue;
21098 VkQueue q1 = nullptr;
21099 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
21100 ASSERT_NE(q1, nullptr);
21101
21102 // An (empty) command buffer. We must have work in the first submission --
21103 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021104 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021105 VkCommandPool pool;
21106 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
21107 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021108 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
21109 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021110 VkCommandBuffer cb;
21111 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
21112 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021113 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021114 err = vkBeginCommandBuffer(cb, &cbbi);
21115 ASSERT_VK_SUCCESS(err);
21116 err = vkEndCommandBuffer(cb);
21117 ASSERT_VK_SUCCESS(err);
21118
21119 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021120 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021121 VkSemaphore s;
21122 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
21123 ASSERT_VK_SUCCESS(err);
21124
21125 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021126 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021127
21128 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
21129 ASSERT_VK_SUCCESS(err);
21130
21131 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021132 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021133 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021134
21135 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
21136 ASSERT_VK_SUCCESS(err);
21137
21138 // Wait for q0 idle
21139 err = vkQueueWaitIdle(q0);
21140 ASSERT_VK_SUCCESS(err);
21141
21142 // Command buffer should have been completed (it was on q0); reset the pool.
21143 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
21144
21145 m_errorMonitor->VerifyNotFound();
21146
21147 // Force device completely idle and clean up resources
21148 vkDeviceWaitIdle(m_device->device());
21149 vkDestroyCommandPool(m_device->device(), pool, nullptr);
21150 vkDestroySemaphore(m_device->device(), s, nullptr);
21151}
21152
21153// This is a positive test. No errors should be generated.
21154TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021155 TEST_DESCRIPTION(
21156 "Two command buffers, each in a separate QueueSubmit call "
21157 "submitted on separate queues, the second having a fence, "
21158 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021159
21160 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021161 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021162
21163 m_errorMonitor->ExpectSuccess();
21164
21165 ASSERT_NO_FATAL_FAILURE(InitState());
21166 VkFence fence;
21167 VkFenceCreateInfo fence_create_info{};
21168 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21169 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21170
21171 VkSemaphore semaphore;
21172 VkSemaphoreCreateInfo semaphore_create_info{};
21173 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21174 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21175
21176 VkCommandPool command_pool;
21177 VkCommandPoolCreateInfo pool_create_info{};
21178 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21179 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21180 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21181 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21182
21183 VkCommandBuffer command_buffer[2];
21184 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21185 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21186 command_buffer_allocate_info.commandPool = command_pool;
21187 command_buffer_allocate_info.commandBufferCount = 2;
21188 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21189 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21190
21191 VkQueue queue = VK_NULL_HANDLE;
21192 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21193
21194 {
21195 VkCommandBufferBeginInfo begin_info{};
21196 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21197 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21198
21199 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 -070021200 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021201
21202 VkViewport viewport{};
21203 viewport.maxDepth = 1.0f;
21204 viewport.minDepth = 0.0f;
21205 viewport.width = 512;
21206 viewport.height = 512;
21207 viewport.x = 0;
21208 viewport.y = 0;
21209 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21210 vkEndCommandBuffer(command_buffer[0]);
21211 }
21212 {
21213 VkCommandBufferBeginInfo begin_info{};
21214 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21215 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21216
21217 VkViewport viewport{};
21218 viewport.maxDepth = 1.0f;
21219 viewport.minDepth = 0.0f;
21220 viewport.width = 512;
21221 viewport.height = 512;
21222 viewport.x = 0;
21223 viewport.y = 0;
21224 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21225 vkEndCommandBuffer(command_buffer[1]);
21226 }
21227 {
21228 VkSubmitInfo submit_info{};
21229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21230 submit_info.commandBufferCount = 1;
21231 submit_info.pCommandBuffers = &command_buffer[0];
21232 submit_info.signalSemaphoreCount = 1;
21233 submit_info.pSignalSemaphores = &semaphore;
21234 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21235 }
21236 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021237 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021238 VkSubmitInfo submit_info{};
21239 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21240 submit_info.commandBufferCount = 1;
21241 submit_info.pCommandBuffers = &command_buffer[1];
21242 submit_info.waitSemaphoreCount = 1;
21243 submit_info.pWaitSemaphores = &semaphore;
21244 submit_info.pWaitDstStageMask = flags;
21245 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21246 }
21247
21248 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21249
21250 vkDestroyFence(m_device->device(), fence, nullptr);
21251 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21252 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21253 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21254
21255 m_errorMonitor->VerifyNotFound();
21256}
21257
21258// This is a positive test. No errors should be generated.
21259TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021260 TEST_DESCRIPTION(
21261 "Two command buffers, each in a separate QueueSubmit call "
21262 "on the same queue, sharing a signal/wait semaphore, the "
21263 "second having a fence, "
21264 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021265
21266 m_errorMonitor->ExpectSuccess();
21267
21268 ASSERT_NO_FATAL_FAILURE(InitState());
21269 VkFence fence;
21270 VkFenceCreateInfo fence_create_info{};
21271 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21272 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21273
21274 VkSemaphore semaphore;
21275 VkSemaphoreCreateInfo semaphore_create_info{};
21276 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21277 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21278
21279 VkCommandPool command_pool;
21280 VkCommandPoolCreateInfo pool_create_info{};
21281 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21282 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21283 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21284 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21285
21286 VkCommandBuffer command_buffer[2];
21287 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21288 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21289 command_buffer_allocate_info.commandPool = command_pool;
21290 command_buffer_allocate_info.commandBufferCount = 2;
21291 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21292 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21293
21294 {
21295 VkCommandBufferBeginInfo begin_info{};
21296 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21297 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21298
21299 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 -070021300 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021301
21302 VkViewport viewport{};
21303 viewport.maxDepth = 1.0f;
21304 viewport.minDepth = 0.0f;
21305 viewport.width = 512;
21306 viewport.height = 512;
21307 viewport.x = 0;
21308 viewport.y = 0;
21309 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21310 vkEndCommandBuffer(command_buffer[0]);
21311 }
21312 {
21313 VkCommandBufferBeginInfo begin_info{};
21314 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21315 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21316
21317 VkViewport viewport{};
21318 viewport.maxDepth = 1.0f;
21319 viewport.minDepth = 0.0f;
21320 viewport.width = 512;
21321 viewport.height = 512;
21322 viewport.x = 0;
21323 viewport.y = 0;
21324 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21325 vkEndCommandBuffer(command_buffer[1]);
21326 }
21327 {
21328 VkSubmitInfo submit_info{};
21329 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21330 submit_info.commandBufferCount = 1;
21331 submit_info.pCommandBuffers = &command_buffer[0];
21332 submit_info.signalSemaphoreCount = 1;
21333 submit_info.pSignalSemaphores = &semaphore;
21334 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21335 }
21336 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021337 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021338 VkSubmitInfo submit_info{};
21339 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21340 submit_info.commandBufferCount = 1;
21341 submit_info.pCommandBuffers = &command_buffer[1];
21342 submit_info.waitSemaphoreCount = 1;
21343 submit_info.pWaitSemaphores = &semaphore;
21344 submit_info.pWaitDstStageMask = flags;
21345 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21346 }
21347
21348 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21349
21350 vkDestroyFence(m_device->device(), fence, nullptr);
21351 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21352 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21353 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21354
21355 m_errorMonitor->VerifyNotFound();
21356}
21357
21358// This is a positive test. No errors should be generated.
21359TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021360 TEST_DESCRIPTION(
21361 "Two command buffers, each in a separate QueueSubmit call "
21362 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21363 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021364
21365 m_errorMonitor->ExpectSuccess();
21366
21367 ASSERT_NO_FATAL_FAILURE(InitState());
21368 VkFence fence;
21369 VkFenceCreateInfo fence_create_info{};
21370 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21371 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21372
21373 VkCommandPool command_pool;
21374 VkCommandPoolCreateInfo pool_create_info{};
21375 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21376 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21377 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21378 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21379
21380 VkCommandBuffer command_buffer[2];
21381 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21382 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21383 command_buffer_allocate_info.commandPool = command_pool;
21384 command_buffer_allocate_info.commandBufferCount = 2;
21385 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21386 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21387
21388 {
21389 VkCommandBufferBeginInfo begin_info{};
21390 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21391 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21392
21393 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 -070021394 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021395
21396 VkViewport viewport{};
21397 viewport.maxDepth = 1.0f;
21398 viewport.minDepth = 0.0f;
21399 viewport.width = 512;
21400 viewport.height = 512;
21401 viewport.x = 0;
21402 viewport.y = 0;
21403 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21404 vkEndCommandBuffer(command_buffer[0]);
21405 }
21406 {
21407 VkCommandBufferBeginInfo begin_info{};
21408 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21409 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21410
21411 VkViewport viewport{};
21412 viewport.maxDepth = 1.0f;
21413 viewport.minDepth = 0.0f;
21414 viewport.width = 512;
21415 viewport.height = 512;
21416 viewport.x = 0;
21417 viewport.y = 0;
21418 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21419 vkEndCommandBuffer(command_buffer[1]);
21420 }
21421 {
21422 VkSubmitInfo submit_info{};
21423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21424 submit_info.commandBufferCount = 1;
21425 submit_info.pCommandBuffers = &command_buffer[0];
21426 submit_info.signalSemaphoreCount = 0;
21427 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21428 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21429 }
21430 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021431 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021432 VkSubmitInfo submit_info{};
21433 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21434 submit_info.commandBufferCount = 1;
21435 submit_info.pCommandBuffers = &command_buffer[1];
21436 submit_info.waitSemaphoreCount = 0;
21437 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21438 submit_info.pWaitDstStageMask = flags;
21439 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21440 }
21441
21442 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21443
21444 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21445 ASSERT_VK_SUCCESS(err);
21446
21447 vkDestroyFence(m_device->device(), fence, nullptr);
21448 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21449 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21450
21451 m_errorMonitor->VerifyNotFound();
21452}
21453
21454// This is a positive test. No errors should be generated.
21455TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021456 TEST_DESCRIPTION(
21457 "Two command buffers, each in a separate QueueSubmit call "
21458 "on the same queue, the second having a fence, followed "
21459 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021460
21461 m_errorMonitor->ExpectSuccess();
21462
21463 ASSERT_NO_FATAL_FAILURE(InitState());
21464 VkFence fence;
21465 VkFenceCreateInfo fence_create_info{};
21466 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21467 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21468
21469 VkCommandPool command_pool;
21470 VkCommandPoolCreateInfo pool_create_info{};
21471 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21472 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21473 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21474 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21475
21476 VkCommandBuffer command_buffer[2];
21477 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21478 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21479 command_buffer_allocate_info.commandPool = command_pool;
21480 command_buffer_allocate_info.commandBufferCount = 2;
21481 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21482 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21483
21484 {
21485 VkCommandBufferBeginInfo begin_info{};
21486 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21487 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21488
21489 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 -070021490 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021491
21492 VkViewport viewport{};
21493 viewport.maxDepth = 1.0f;
21494 viewport.minDepth = 0.0f;
21495 viewport.width = 512;
21496 viewport.height = 512;
21497 viewport.x = 0;
21498 viewport.y = 0;
21499 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21500 vkEndCommandBuffer(command_buffer[0]);
21501 }
21502 {
21503 VkCommandBufferBeginInfo begin_info{};
21504 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21505 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21506
21507 VkViewport viewport{};
21508 viewport.maxDepth = 1.0f;
21509 viewport.minDepth = 0.0f;
21510 viewport.width = 512;
21511 viewport.height = 512;
21512 viewport.x = 0;
21513 viewport.y = 0;
21514 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21515 vkEndCommandBuffer(command_buffer[1]);
21516 }
21517 {
21518 VkSubmitInfo submit_info{};
21519 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21520 submit_info.commandBufferCount = 1;
21521 submit_info.pCommandBuffers = &command_buffer[0];
21522 submit_info.signalSemaphoreCount = 0;
21523 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21524 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21525 }
21526 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021527 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021528 VkSubmitInfo submit_info{};
21529 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21530 submit_info.commandBufferCount = 1;
21531 submit_info.pCommandBuffers = &command_buffer[1];
21532 submit_info.waitSemaphoreCount = 0;
21533 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21534 submit_info.pWaitDstStageMask = flags;
21535 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21536 }
21537
21538 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21539
21540 vkDestroyFence(m_device->device(), fence, nullptr);
21541 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21542 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21543
21544 m_errorMonitor->VerifyNotFound();
21545}
21546
21547// This is a positive test. No errors should be generated.
21548TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021549 TEST_DESCRIPTION(
21550 "Two command buffers each in a separate SubmitInfo sent in a single "
21551 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021552 ASSERT_NO_FATAL_FAILURE(InitState());
21553
21554 m_errorMonitor->ExpectSuccess();
21555
21556 VkFence fence;
21557 VkFenceCreateInfo fence_create_info{};
21558 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21559 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21560
21561 VkSemaphore semaphore;
21562 VkSemaphoreCreateInfo semaphore_create_info{};
21563 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21564 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21565
21566 VkCommandPool command_pool;
21567 VkCommandPoolCreateInfo pool_create_info{};
21568 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21569 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21570 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21571 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21572
21573 VkCommandBuffer command_buffer[2];
21574 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21575 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21576 command_buffer_allocate_info.commandPool = command_pool;
21577 command_buffer_allocate_info.commandBufferCount = 2;
21578 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21579 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21580
21581 {
21582 VkCommandBufferBeginInfo begin_info{};
21583 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21584 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21585
21586 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 -070021587 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021588
21589 VkViewport viewport{};
21590 viewport.maxDepth = 1.0f;
21591 viewport.minDepth = 0.0f;
21592 viewport.width = 512;
21593 viewport.height = 512;
21594 viewport.x = 0;
21595 viewport.y = 0;
21596 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21597 vkEndCommandBuffer(command_buffer[0]);
21598 }
21599 {
21600 VkCommandBufferBeginInfo begin_info{};
21601 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21602 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21603
21604 VkViewport viewport{};
21605 viewport.maxDepth = 1.0f;
21606 viewport.minDepth = 0.0f;
21607 viewport.width = 512;
21608 viewport.height = 512;
21609 viewport.x = 0;
21610 viewport.y = 0;
21611 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21612 vkEndCommandBuffer(command_buffer[1]);
21613 }
21614 {
21615 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021616 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021617
21618 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21619 submit_info[0].pNext = NULL;
21620 submit_info[0].commandBufferCount = 1;
21621 submit_info[0].pCommandBuffers = &command_buffer[0];
21622 submit_info[0].signalSemaphoreCount = 1;
21623 submit_info[0].pSignalSemaphores = &semaphore;
21624 submit_info[0].waitSemaphoreCount = 0;
21625 submit_info[0].pWaitSemaphores = NULL;
21626 submit_info[0].pWaitDstStageMask = 0;
21627
21628 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21629 submit_info[1].pNext = NULL;
21630 submit_info[1].commandBufferCount = 1;
21631 submit_info[1].pCommandBuffers = &command_buffer[1];
21632 submit_info[1].waitSemaphoreCount = 1;
21633 submit_info[1].pWaitSemaphores = &semaphore;
21634 submit_info[1].pWaitDstStageMask = flags;
21635 submit_info[1].signalSemaphoreCount = 0;
21636 submit_info[1].pSignalSemaphores = NULL;
21637 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21638 }
21639
21640 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21641
21642 vkDestroyFence(m_device->device(), fence, nullptr);
21643 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21644 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21645 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21646
21647 m_errorMonitor->VerifyNotFound();
21648}
21649
21650TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21651 m_errorMonitor->ExpectSuccess();
21652
21653 ASSERT_NO_FATAL_FAILURE(InitState());
21654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21655
Tony Barbour552f6c02016-12-21 14:34:07 -070021656 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021657
21658 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21659 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21660 m_errorMonitor->VerifyNotFound();
21661 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21662 m_errorMonitor->VerifyNotFound();
21663 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21664 m_errorMonitor->VerifyNotFound();
21665
21666 m_commandBuffer->EndCommandBuffer();
21667 m_errorMonitor->VerifyNotFound();
21668}
21669
21670TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021671 TEST_DESCRIPTION(
21672 "Positive test where we create a renderpass with an "
21673 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21674 "has a valid layout, and a second subpass then uses a "
21675 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021676 m_errorMonitor->ExpectSuccess();
21677 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021678 auto depth_format = find_depth_stencil_format(m_device);
21679 if (!depth_format) {
21680 printf(" No Depth + Stencil format found. Skipped.\n");
21681 return;
21682 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021683
21684 VkAttachmentReference attach[2] = {};
21685 attach[0].attachment = 0;
21686 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21687 attach[1].attachment = 0;
21688 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21689 VkSubpassDescription subpasses[2] = {};
21690 // First subpass clears DS attach on load
21691 subpasses[0].pDepthStencilAttachment = &attach[0];
21692 // 2nd subpass reads in DS as input attachment
21693 subpasses[1].inputAttachmentCount = 1;
21694 subpasses[1].pInputAttachments = &attach[1];
21695 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021696 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021697 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21698 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21699 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21700 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21701 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21702 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21703 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21704 VkRenderPassCreateInfo rpci = {};
21705 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21706 rpci.attachmentCount = 1;
21707 rpci.pAttachments = &attach_desc;
21708 rpci.subpassCount = 2;
21709 rpci.pSubpasses = subpasses;
21710
21711 // Now create RenderPass and verify no errors
21712 VkRenderPass rp;
21713 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21714 m_errorMonitor->VerifyNotFound();
21715
21716 vkDestroyRenderPass(m_device->device(), rp, NULL);
21717}
21718
Tobin Ehlis01103de2017-02-16 13:22:47 -070021719TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21720 TEST_DESCRIPTION(
21721 "Create a render pass with depth-stencil attachment where layout transition "
21722 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21723 "transition has correctly occurred at queue submit time with no validation errors.");
21724
Tony Barbourf887b162017-03-09 10:06:46 -070021725 ASSERT_NO_FATAL_FAILURE(InitState());
21726 auto depth_format = find_depth_stencil_format(m_device);
21727 if (!depth_format) {
21728 printf(" No Depth + Stencil format found. Skipped.\n");
21729 return;
21730 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021731 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021732 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021733 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21734 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021735 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021736 return;
21737 }
21738
21739 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21741
21742 // A renderpass with one depth/stencil attachment.
21743 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021744 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021745 VK_SAMPLE_COUNT_1_BIT,
21746 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21747 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21748 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21749 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21750 VK_IMAGE_LAYOUT_UNDEFINED,
21751 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21752
21753 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21754
21755 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21756
21757 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21758
21759 VkRenderPass rp;
21760 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21761 ASSERT_VK_SUCCESS(err);
21762 // A compatible ds image.
21763 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021764 image.init(32, 32, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070021765 ASSERT_TRUE(image.initialized());
21766
21767 VkImageViewCreateInfo ivci = {
21768 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21769 nullptr,
21770 0,
21771 image.handle(),
21772 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021773 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021774 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21775 VK_COMPONENT_SWIZZLE_IDENTITY},
21776 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21777 };
21778 VkImageView view;
21779 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21780 ASSERT_VK_SUCCESS(err);
21781
21782 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21783 VkFramebuffer fb;
21784 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21785 ASSERT_VK_SUCCESS(err);
21786
21787 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21788 m_commandBuffer->BeginCommandBuffer();
21789 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21790 vkCmdEndRenderPass(m_commandBuffer->handle());
21791 m_commandBuffer->EndCommandBuffer();
21792 QueueCommandBuffer(false);
21793 m_errorMonitor->VerifyNotFound();
21794
21795 // Cleanup
21796 vkDestroyImageView(m_device->device(), view, NULL);
21797 vkDestroyRenderPass(m_device->device(), rp, NULL);
21798 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21799}
21800
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021801TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021802 TEST_DESCRIPTION(
21803 "Test that pipeline validation accepts matrices passed "
21804 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021805 m_errorMonitor->ExpectSuccess();
21806
21807 ASSERT_NO_FATAL_FAILURE(InitState());
21808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21809
21810 VkVertexInputBindingDescription input_binding;
21811 memset(&input_binding, 0, sizeof(input_binding));
21812
21813 VkVertexInputAttributeDescription input_attribs[2];
21814 memset(input_attribs, 0, sizeof(input_attribs));
21815
21816 for (int i = 0; i < 2; i++) {
21817 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21818 input_attribs[i].location = i;
21819 }
21820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021821 char const *vsSource =
21822 "#version 450\n"
21823 "\n"
21824 "layout(location=0) in mat2x4 x;\n"
21825 "out gl_PerVertex {\n"
21826 " vec4 gl_Position;\n"
21827 "};\n"
21828 "void main(){\n"
21829 " gl_Position = x[0] + x[1];\n"
21830 "}\n";
21831 char const *fsSource =
21832 "#version 450\n"
21833 "\n"
21834 "layout(location=0) out vec4 color;\n"
21835 "void main(){\n"
21836 " color = vec4(1);\n"
21837 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021838
21839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21841
21842 VkPipelineObj pipe(m_device);
21843 pipe.AddColorAttachment();
21844 pipe.AddShader(&vs);
21845 pipe.AddShader(&fs);
21846
21847 pipe.AddVertexInputBindings(&input_binding, 1);
21848 pipe.AddVertexInputAttribs(input_attribs, 2);
21849
21850 VkDescriptorSetObj descriptorSet(m_device);
21851 descriptorSet.AppendDummy();
21852 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21853
21854 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21855
21856 /* expect success */
21857 m_errorMonitor->VerifyNotFound();
21858}
21859
21860TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21861 m_errorMonitor->ExpectSuccess();
21862
21863 ASSERT_NO_FATAL_FAILURE(InitState());
21864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21865
21866 VkVertexInputBindingDescription input_binding;
21867 memset(&input_binding, 0, sizeof(input_binding));
21868
21869 VkVertexInputAttributeDescription input_attribs[2];
21870 memset(input_attribs, 0, sizeof(input_attribs));
21871
21872 for (int i = 0; i < 2; i++) {
21873 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21874 input_attribs[i].location = i;
21875 }
21876
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021877 char const *vsSource =
21878 "#version 450\n"
21879 "\n"
21880 "layout(location=0) in vec4 x[2];\n"
21881 "out gl_PerVertex {\n"
21882 " vec4 gl_Position;\n"
21883 "};\n"
21884 "void main(){\n"
21885 " gl_Position = x[0] + x[1];\n"
21886 "}\n";
21887 char const *fsSource =
21888 "#version 450\n"
21889 "\n"
21890 "layout(location=0) out vec4 color;\n"
21891 "void main(){\n"
21892 " color = vec4(1);\n"
21893 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021894
21895 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21896 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21897
21898 VkPipelineObj pipe(m_device);
21899 pipe.AddColorAttachment();
21900 pipe.AddShader(&vs);
21901 pipe.AddShader(&fs);
21902
21903 pipe.AddVertexInputBindings(&input_binding, 1);
21904 pipe.AddVertexInputAttribs(input_attribs, 2);
21905
21906 VkDescriptorSetObj descriptorSet(m_device);
21907 descriptorSet.AppendDummy();
21908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21909
21910 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21911
21912 m_errorMonitor->VerifyNotFound();
21913}
21914
21915TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021916 TEST_DESCRIPTION(
21917 "Test that pipeline validation accepts consuming a vertex attribute "
21918 "through multiple vertex shader inputs, each consuming a different "
21919 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021920 m_errorMonitor->ExpectSuccess();
21921
21922 ASSERT_NO_FATAL_FAILURE(InitState());
21923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21924
21925 VkVertexInputBindingDescription input_binding;
21926 memset(&input_binding, 0, sizeof(input_binding));
21927
21928 VkVertexInputAttributeDescription input_attribs[3];
21929 memset(input_attribs, 0, sizeof(input_attribs));
21930
21931 for (int i = 0; i < 3; i++) {
21932 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21933 input_attribs[i].location = i;
21934 }
21935
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021936 char const *vsSource =
21937 "#version 450\n"
21938 "\n"
21939 "layout(location=0) in vec4 x;\n"
21940 "layout(location=1) in vec3 y1;\n"
21941 "layout(location=1, component=3) in float y2;\n"
21942 "layout(location=2) in vec4 z;\n"
21943 "out gl_PerVertex {\n"
21944 " vec4 gl_Position;\n"
21945 "};\n"
21946 "void main(){\n"
21947 " gl_Position = x + vec4(y1, y2) + z;\n"
21948 "}\n";
21949 char const *fsSource =
21950 "#version 450\n"
21951 "\n"
21952 "layout(location=0) out vec4 color;\n"
21953 "void main(){\n"
21954 " color = vec4(1);\n"
21955 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021956
21957 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21958 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21959
21960 VkPipelineObj pipe(m_device);
21961 pipe.AddColorAttachment();
21962 pipe.AddShader(&vs);
21963 pipe.AddShader(&fs);
21964
21965 pipe.AddVertexInputBindings(&input_binding, 1);
21966 pipe.AddVertexInputAttribs(input_attribs, 3);
21967
21968 VkDescriptorSetObj descriptorSet(m_device);
21969 descriptorSet.AppendDummy();
21970 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21971
21972 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21973
21974 m_errorMonitor->VerifyNotFound();
21975}
21976
21977TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21978 m_errorMonitor->ExpectSuccess();
21979
21980 ASSERT_NO_FATAL_FAILURE(InitState());
21981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021983 char const *vsSource =
21984 "#version 450\n"
21985 "out gl_PerVertex {\n"
21986 " vec4 gl_Position;\n"
21987 "};\n"
21988 "void main(){\n"
21989 " gl_Position = vec4(0);\n"
21990 "}\n";
21991 char const *fsSource =
21992 "#version 450\n"
21993 "\n"
21994 "layout(location=0) out vec4 color;\n"
21995 "void main(){\n"
21996 " color = vec4(1);\n"
21997 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021998
21999 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22000 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22001
22002 VkPipelineObj pipe(m_device);
22003 pipe.AddColorAttachment();
22004 pipe.AddShader(&vs);
22005 pipe.AddShader(&fs);
22006
22007 VkDescriptorSetObj descriptorSet(m_device);
22008 descriptorSet.AppendDummy();
22009 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22010
22011 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22012
22013 m_errorMonitor->VerifyNotFound();
22014}
22015
22016TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022017 TEST_DESCRIPTION(
22018 "Test that pipeline validation accepts the relaxed type matching rules "
22019 "set out in 14.1.3: fundamental type must match, and producer side must "
22020 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022021 m_errorMonitor->ExpectSuccess();
22022
22023 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
22024
22025 ASSERT_NO_FATAL_FAILURE(InitState());
22026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22027
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022028 char const *vsSource =
22029 "#version 450\n"
22030 "out gl_PerVertex {\n"
22031 " vec4 gl_Position;\n"
22032 "};\n"
22033 "layout(location=0) out vec3 x;\n"
22034 "layout(location=1) out ivec3 y;\n"
22035 "layout(location=2) out vec3 z;\n"
22036 "void main(){\n"
22037 " gl_Position = vec4(0);\n"
22038 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
22039 "}\n";
22040 char const *fsSource =
22041 "#version 450\n"
22042 "\n"
22043 "layout(location=0) out vec4 color;\n"
22044 "layout(location=0) in float x;\n"
22045 "layout(location=1) flat in int y;\n"
22046 "layout(location=2) in vec2 z;\n"
22047 "void main(){\n"
22048 " color = vec4(1 + x + y + z.x);\n"
22049 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022050
22051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22053
22054 VkPipelineObj pipe(m_device);
22055 pipe.AddColorAttachment();
22056 pipe.AddShader(&vs);
22057 pipe.AddShader(&fs);
22058
22059 VkDescriptorSetObj descriptorSet(m_device);
22060 descriptorSet.AppendDummy();
22061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22062
22063 VkResult err = VK_SUCCESS;
22064 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22065 ASSERT_VK_SUCCESS(err);
22066
22067 m_errorMonitor->VerifyNotFound();
22068}
22069
22070TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022071 TEST_DESCRIPTION(
22072 "Test that pipeline validation accepts per-vertex variables "
22073 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022074 m_errorMonitor->ExpectSuccess();
22075
22076 ASSERT_NO_FATAL_FAILURE(InitState());
22077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22078
22079 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022080 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022081 return;
22082 }
22083
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022084 char const *vsSource =
22085 "#version 450\n"
22086 "void main(){}\n";
22087 char const *tcsSource =
22088 "#version 450\n"
22089 "layout(location=0) out int x[];\n"
22090 "layout(vertices=3) out;\n"
22091 "void main(){\n"
22092 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
22093 " gl_TessLevelInner[0] = 1;\n"
22094 " x[gl_InvocationID] = gl_InvocationID;\n"
22095 "}\n";
22096 char const *tesSource =
22097 "#version 450\n"
22098 "layout(triangles, equal_spacing, cw) in;\n"
22099 "layout(location=0) in int x[];\n"
22100 "out gl_PerVertex { vec4 gl_Position; };\n"
22101 "void main(){\n"
22102 " gl_Position.xyz = gl_TessCoord;\n"
22103 " gl_Position.w = x[0] + x[1] + x[2];\n"
22104 "}\n";
22105 char const *fsSource =
22106 "#version 450\n"
22107 "layout(location=0) out vec4 color;\n"
22108 "void main(){\n"
22109 " color = vec4(1);\n"
22110 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022111
22112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22113 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
22114 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
22115 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22116
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022117 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
22118 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022119
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022120 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022121
22122 VkPipelineObj pipe(m_device);
22123 pipe.SetInputAssembly(&iasci);
22124 pipe.SetTessellation(&tsci);
22125 pipe.AddColorAttachment();
22126 pipe.AddShader(&vs);
22127 pipe.AddShader(&tcs);
22128 pipe.AddShader(&tes);
22129 pipe.AddShader(&fs);
22130
22131 VkDescriptorSetObj descriptorSet(m_device);
22132 descriptorSet.AppendDummy();
22133 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22134
22135 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22136
22137 m_errorMonitor->VerifyNotFound();
22138}
22139
22140TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022141 TEST_DESCRIPTION(
22142 "Test that pipeline validation accepts a user-defined "
22143 "interface block passed into the geometry shader. This "
22144 "is interesting because the 'extra' array level is not "
22145 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022146 m_errorMonitor->ExpectSuccess();
22147
22148 ASSERT_NO_FATAL_FAILURE(InitState());
22149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22150
22151 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022152 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022153 return;
22154 }
22155
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022156 char const *vsSource =
22157 "#version 450\n"
22158 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
22159 "void main(){\n"
22160 " vs_out.x = vec4(1);\n"
22161 "}\n";
22162 char const *gsSource =
22163 "#version 450\n"
22164 "layout(triangles) in;\n"
22165 "layout(triangle_strip, max_vertices=3) out;\n"
22166 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
22167 "out gl_PerVertex { vec4 gl_Position; };\n"
22168 "void main() {\n"
22169 " gl_Position = gs_in[0].x;\n"
22170 " EmitVertex();\n"
22171 "}\n";
22172 char const *fsSource =
22173 "#version 450\n"
22174 "layout(location=0) out vec4 color;\n"
22175 "void main(){\n"
22176 " color = vec4(1);\n"
22177 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022178
22179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22180 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
22181 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22182
22183 VkPipelineObj pipe(m_device);
22184 pipe.AddColorAttachment();
22185 pipe.AddShader(&vs);
22186 pipe.AddShader(&gs);
22187 pipe.AddShader(&fs);
22188
22189 VkDescriptorSetObj descriptorSet(m_device);
22190 descriptorSet.AppendDummy();
22191 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22192
22193 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22194
22195 m_errorMonitor->VerifyNotFound();
22196}
22197
22198TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022199 TEST_DESCRIPTION(
22200 "Test that pipeline validation accepts basic use of 64bit vertex "
22201 "attributes. This is interesting because they consume multiple "
22202 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022203 m_errorMonitor->ExpectSuccess();
22204
22205 ASSERT_NO_FATAL_FAILURE(InitState());
22206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22207
22208 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022209 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022210 return;
22211 }
22212
22213 VkVertexInputBindingDescription input_bindings[1];
22214 memset(input_bindings, 0, sizeof(input_bindings));
22215
22216 VkVertexInputAttributeDescription input_attribs[4];
22217 memset(input_attribs, 0, sizeof(input_attribs));
22218 input_attribs[0].location = 0;
22219 input_attribs[0].offset = 0;
22220 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22221 input_attribs[1].location = 2;
22222 input_attribs[1].offset = 32;
22223 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22224 input_attribs[2].location = 4;
22225 input_attribs[2].offset = 64;
22226 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22227 input_attribs[3].location = 6;
22228 input_attribs[3].offset = 96;
22229 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22230
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022231 char const *vsSource =
22232 "#version 450\n"
22233 "\n"
22234 "layout(location=0) in dmat4 x;\n"
22235 "out gl_PerVertex {\n"
22236 " vec4 gl_Position;\n"
22237 "};\n"
22238 "void main(){\n"
22239 " gl_Position = vec4(x[0][0]);\n"
22240 "}\n";
22241 char const *fsSource =
22242 "#version 450\n"
22243 "\n"
22244 "layout(location=0) out vec4 color;\n"
22245 "void main(){\n"
22246 " color = vec4(1);\n"
22247 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022248
22249 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22250 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22251
22252 VkPipelineObj pipe(m_device);
22253 pipe.AddColorAttachment();
22254 pipe.AddShader(&vs);
22255 pipe.AddShader(&fs);
22256
22257 pipe.AddVertexInputBindings(input_bindings, 1);
22258 pipe.AddVertexInputAttribs(input_attribs, 4);
22259
22260 VkDescriptorSetObj descriptorSet(m_device);
22261 descriptorSet.AppendDummy();
22262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22263
22264 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22265
22266 m_errorMonitor->VerifyNotFound();
22267}
22268
22269TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22270 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22271 m_errorMonitor->ExpectSuccess();
22272
22273 ASSERT_NO_FATAL_FAILURE(InitState());
22274
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022275 char const *vsSource =
22276 "#version 450\n"
22277 "\n"
22278 "out gl_PerVertex {\n"
22279 " vec4 gl_Position;\n"
22280 "};\n"
22281 "void main(){\n"
22282 " gl_Position = vec4(1);\n"
22283 "}\n";
22284 char const *fsSource =
22285 "#version 450\n"
22286 "\n"
22287 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22288 "layout(location=0) out vec4 color;\n"
22289 "void main() {\n"
22290 " color = subpassLoad(x);\n"
22291 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022292
22293 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22294 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22295
22296 VkPipelineObj pipe(m_device);
22297 pipe.AddShader(&vs);
22298 pipe.AddShader(&fs);
22299 pipe.AddColorAttachment();
22300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22301
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022302 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22303 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022304 VkDescriptorSetLayout dsl;
22305 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22306 ASSERT_VK_SUCCESS(err);
22307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022308 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022309 VkPipelineLayout pl;
22310 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22311 ASSERT_VK_SUCCESS(err);
22312
22313 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022314 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22315 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22316 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22317 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22318 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 -060022319 };
22320 VkAttachmentReference color = {
22321 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22322 };
22323 VkAttachmentReference input = {
22324 1, VK_IMAGE_LAYOUT_GENERAL,
22325 };
22326
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022327 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022328
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022329 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022330 VkRenderPass rp;
22331 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22332 ASSERT_VK_SUCCESS(err);
22333
22334 // should be OK. would go wrong here if it's going to...
22335 pipe.CreateVKPipeline(pl, rp);
22336
22337 m_errorMonitor->VerifyNotFound();
22338
22339 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22340 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22341 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22342}
22343
22344TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022345 TEST_DESCRIPTION(
22346 "Test that pipeline validation accepts a compute pipeline which declares a "
22347 "descriptor-backed resource which is not provided, but the shader does not "
22348 "statically use it. This is interesting because it requires compute pipelines "
22349 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022350 m_errorMonitor->ExpectSuccess();
22351
22352 ASSERT_NO_FATAL_FAILURE(InitState());
22353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022354 char const *csSource =
22355 "#version 450\n"
22356 "\n"
22357 "layout(local_size_x=1) in;\n"
22358 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22359 "void main(){\n"
22360 " // x is not used.\n"
22361 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022362
22363 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22364
22365 VkDescriptorSetObj descriptorSet(m_device);
22366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22367
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022368 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22369 nullptr,
22370 0,
22371 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22372 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22373 descriptorSet.GetPipelineLayout(),
22374 VK_NULL_HANDLE,
22375 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022376
22377 VkPipeline pipe;
22378 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22379
22380 m_errorMonitor->VerifyNotFound();
22381
22382 if (err == VK_SUCCESS) {
22383 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22384 }
22385}
22386
22387TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022388 TEST_DESCRIPTION(
22389 "Test that pipeline validation accepts a shader consuming only the "
22390 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022391 m_errorMonitor->ExpectSuccess();
22392
22393 ASSERT_NO_FATAL_FAILURE(InitState());
22394
22395 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022396 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22397 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22398 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022399 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022400 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022401 VkDescriptorSetLayout dsl;
22402 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22403 ASSERT_VK_SUCCESS(err);
22404
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022405 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022406 VkPipelineLayout pl;
22407 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22408 ASSERT_VK_SUCCESS(err);
22409
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022410 char const *csSource =
22411 "#version 450\n"
22412 "\n"
22413 "layout(local_size_x=1) in;\n"
22414 "layout(set=0, binding=0) uniform sampler s;\n"
22415 "layout(set=0, binding=1) uniform texture2D t;\n"
22416 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22417 "void main() {\n"
22418 " x = texture(sampler2D(t, s), vec2(0));\n"
22419 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022420 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22421
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022422 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22423 nullptr,
22424 0,
22425 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22426 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22427 pl,
22428 VK_NULL_HANDLE,
22429 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022430
22431 VkPipeline pipe;
22432 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22433
22434 m_errorMonitor->VerifyNotFound();
22435
22436 if (err == VK_SUCCESS) {
22437 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22438 }
22439
22440 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22441 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22442}
22443
22444TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022445 TEST_DESCRIPTION(
22446 "Test that pipeline validation accepts a shader consuming only the "
22447 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022448 m_errorMonitor->ExpectSuccess();
22449
22450 ASSERT_NO_FATAL_FAILURE(InitState());
22451
22452 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022453 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22454 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22455 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022456 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022457 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022458 VkDescriptorSetLayout dsl;
22459 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22460 ASSERT_VK_SUCCESS(err);
22461
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022462 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022463 VkPipelineLayout pl;
22464 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22465 ASSERT_VK_SUCCESS(err);
22466
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022467 char const *csSource =
22468 "#version 450\n"
22469 "\n"
22470 "layout(local_size_x=1) in;\n"
22471 "layout(set=0, binding=0) uniform texture2D t;\n"
22472 "layout(set=0, binding=1) uniform sampler s;\n"
22473 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22474 "void main() {\n"
22475 " x = texture(sampler2D(t, s), vec2(0));\n"
22476 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022477 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22478
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022479 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22480 nullptr,
22481 0,
22482 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22483 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22484 pl,
22485 VK_NULL_HANDLE,
22486 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022487
22488 VkPipeline pipe;
22489 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22490
22491 m_errorMonitor->VerifyNotFound();
22492
22493 if (err == VK_SUCCESS) {
22494 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22495 }
22496
22497 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22498 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22499}
22500
22501TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022502 TEST_DESCRIPTION(
22503 "Test that pipeline validation accepts a shader consuming "
22504 "both the sampler and the image of a combined image+sampler "
22505 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022506 m_errorMonitor->ExpectSuccess();
22507
22508 ASSERT_NO_FATAL_FAILURE(InitState());
22509
22510 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022511 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22512 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022513 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022514 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022515 VkDescriptorSetLayout dsl;
22516 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22517 ASSERT_VK_SUCCESS(err);
22518
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022519 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022520 VkPipelineLayout pl;
22521 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22522 ASSERT_VK_SUCCESS(err);
22523
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022524 char const *csSource =
22525 "#version 450\n"
22526 "\n"
22527 "layout(local_size_x=1) in;\n"
22528 "layout(set=0, binding=0) uniform texture2D t;\n"
22529 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22530 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22531 "void main() {\n"
22532 " x = texture(sampler2D(t, s), vec2(0));\n"
22533 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022534 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22535
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022536 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22537 nullptr,
22538 0,
22539 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22540 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22541 pl,
22542 VK_NULL_HANDLE,
22543 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022544
22545 VkPipeline pipe;
22546 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22547
22548 m_errorMonitor->VerifyNotFound();
22549
22550 if (err == VK_SUCCESS) {
22551 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22552 }
22553
22554 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22555 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22556}
22557
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022558// This test class enables the Maintenance1 extension for related validation tests
22559TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22560 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22561
22562 // Ensure that extension is available and enabled.
22563 uint32_t extension_count = 0;
22564 bool supports_maintenance1_extension = false;
22565 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22566 ASSERT_VK_SUCCESS(err);
22567 if (extension_count > 0) {
22568 std::vector<VkExtensionProperties> available_extensions(extension_count);
22569
22570 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22571 ASSERT_VK_SUCCESS(err);
22572 for (const auto &extension_props : available_extensions) {
22573 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22574 supports_maintenance1_extension = true;
22575 }
22576 }
22577 }
22578
22579 // Proceed if extension is supported by hardware
22580 if (!supports_maintenance1_extension) {
22581 printf(" Maintenance1 Extension not supported, skipping tests\n");
22582 return;
22583 }
22584 ASSERT_NO_FATAL_FAILURE(InitState());
22585
22586 m_errorMonitor->ExpectSuccess();
22587
22588 VkCommandBuffer cmd_buf;
22589 VkCommandBufferAllocateInfo alloc_info;
22590 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22591 alloc_info.pNext = NULL;
22592 alloc_info.commandBufferCount = 1;
22593 alloc_info.commandPool = m_commandPool;
22594 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22595 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22596
22597 VkCommandBufferBeginInfo cb_binfo;
22598 cb_binfo.pNext = NULL;
22599 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22600 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22601 cb_binfo.flags = 0;
22602 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22603 // Set Negative height, should give error if Maintenance 1 is not enabled
22604 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22605 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22606 vkEndCommandBuffer(cmd_buf);
22607
22608 m_errorMonitor->VerifyNotFound();
22609}
22610
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022611TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22612 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22613
22614 ASSERT_NO_FATAL_FAILURE(InitState());
22615
22616 // Positive test to check parameter_validation and unique_objects support
22617 // for NV_dedicated_allocation
22618 uint32_t extension_count = 0;
22619 bool supports_nv_dedicated_allocation = false;
22620 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22621 ASSERT_VK_SUCCESS(err);
22622
22623 if (extension_count > 0) {
22624 std::vector<VkExtensionProperties> available_extensions(extension_count);
22625
22626 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22627 ASSERT_VK_SUCCESS(err);
22628
22629 for (const auto &extension_props : available_extensions) {
22630 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22631 supports_nv_dedicated_allocation = true;
22632 }
22633 }
22634 }
22635
22636 if (supports_nv_dedicated_allocation) {
22637 m_errorMonitor->ExpectSuccess();
22638
22639 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22640 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22641 dedicated_buffer_create_info.pNext = nullptr;
22642 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22643
22644 uint32_t queue_family_index = 0;
22645 VkBufferCreateInfo buffer_create_info = {};
22646 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22647 buffer_create_info.pNext = &dedicated_buffer_create_info;
22648 buffer_create_info.size = 1024;
22649 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22650 buffer_create_info.queueFamilyIndexCount = 1;
22651 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22652
22653 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022654 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022655 ASSERT_VK_SUCCESS(err);
22656
22657 VkMemoryRequirements memory_reqs;
22658 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22659
22660 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22661 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22662 dedicated_memory_info.pNext = nullptr;
22663 dedicated_memory_info.buffer = buffer;
22664 dedicated_memory_info.image = VK_NULL_HANDLE;
22665
22666 VkMemoryAllocateInfo memory_info = {};
22667 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22668 memory_info.pNext = &dedicated_memory_info;
22669 memory_info.allocationSize = memory_reqs.size;
22670
22671 bool pass;
22672 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22673 ASSERT_TRUE(pass);
22674
22675 VkDeviceMemory buffer_memory;
22676 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22677 ASSERT_VK_SUCCESS(err);
22678
22679 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22680 ASSERT_VK_SUCCESS(err);
22681
22682 vkDestroyBuffer(m_device->device(), buffer, NULL);
22683 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22684
22685 m_errorMonitor->VerifyNotFound();
22686 }
22687}
22688
22689TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22690 VkResult err;
22691
22692 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22693
22694 ASSERT_NO_FATAL_FAILURE(InitState());
22695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22696
22697 std::vector<const char *> device_extension_names;
22698 auto features = m_device->phy().features();
22699 // Artificially disable support for non-solid fill modes
22700 features.fillModeNonSolid = false;
22701 // The sacrificial device object
22702 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22703
22704 VkRenderpassObj render_pass(&test_device);
22705
22706 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22707 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22708 pipeline_layout_ci.setLayoutCount = 0;
22709 pipeline_layout_ci.pSetLayouts = NULL;
22710
22711 VkPipelineLayout pipeline_layout;
22712 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22713 ASSERT_VK_SUCCESS(err);
22714
22715 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22716 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22717 rs_ci.pNext = nullptr;
22718 rs_ci.lineWidth = 1.0f;
22719 rs_ci.rasterizerDiscardEnable = true;
22720
22721 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22722 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22723
22724 // Set polygonMode=FILL. No error is expected
22725 m_errorMonitor->ExpectSuccess();
22726 {
22727 VkPipelineObj pipe(&test_device);
22728 pipe.AddShader(&vs);
22729 pipe.AddShader(&fs);
22730 pipe.AddColorAttachment();
22731 // Set polygonMode to a good value
22732 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22733 pipe.SetRasterization(&rs_ci);
22734 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22735 }
22736 m_errorMonitor->VerifyNotFound();
22737
22738 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22739}
22740
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022741#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022742TEST_F(VkPositiveLayerTest, LongFenceChain)
22743{
22744 m_errorMonitor->ExpectSuccess();
22745
22746 ASSERT_NO_FATAL_FAILURE(InitState());
22747 VkResult err;
22748
22749 std::vector<VkFence> fences;
22750
22751 const int chainLength = 32768;
22752
22753 for (int i = 0; i < chainLength; i++) {
22754 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22755 VkFence fence;
22756 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22757 ASSERT_VK_SUCCESS(err);
22758
22759 fences.push_back(fence);
22760
22761 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22762 0, nullptr, 0, nullptr };
22763 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22764 ASSERT_VK_SUCCESS(err);
22765
22766 }
22767
22768 // BOOM, stack overflow.
22769 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22770
22771 for (auto fence : fences)
22772 vkDestroyFence(m_device->device(), fence, nullptr);
22773
22774 m_errorMonitor->VerifyNotFound();
22775}
22776#endif
22777
Cody Northrop1242dfd2016-07-13 17:24:59 -060022778#if defined(ANDROID) && defined(VALIDATION_APK)
22779static bool initialized = false;
22780static bool active = false;
22781
22782// Convert Intents to argv
22783// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022784std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022785 std::vector<std::string> args;
22786 JavaVM &vm = *app.activity->vm;
22787 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022788 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022789
22790 JNIEnv &env = *p_env;
22791 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022792 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022793 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022794 jmethodID get_string_extra_method =
22795 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022796 jvalue get_string_extra_args;
22797 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022798 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022799
22800 std::string args_str;
22801 if (extra_str) {
22802 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22803 args_str = extra_utf;
22804 env.ReleaseStringUTFChars(extra_str, extra_utf);
22805 env.DeleteLocalRef(extra_str);
22806 }
22807
22808 env.DeleteLocalRef(get_string_extra_args.l);
22809 env.DeleteLocalRef(intent);
22810 vm.DetachCurrentThread();
22811
22812 // split args_str
22813 std::stringstream ss(args_str);
22814 std::string arg;
22815 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022816 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022817 }
22818
22819 return args;
22820}
22821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022822static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022824static void processCommand(struct android_app *app, int32_t cmd) {
22825 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022826 case APP_CMD_INIT_WINDOW: {
22827 if (app->window) {
22828 initialized = true;
22829 }
22830 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022831 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022832 case APP_CMD_GAINED_FOCUS: {
22833 active = true;
22834 break;
22835 }
22836 case APP_CMD_LOST_FOCUS: {
22837 active = false;
22838 break;
22839 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022840 }
22841}
22842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022843void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022844 app_dummy();
22845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022846 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022847
22848 int vulkanSupport = InitVulkan();
22849 if (vulkanSupport == 0) {
22850 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22851 return;
22852 }
22853
22854 app->onAppCmd = processCommand;
22855 app->onInputEvent = processInput;
22856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022857 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022858 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022859 struct android_poll_source *source;
22860 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022861 if (source) {
22862 source->process(app, source);
22863 }
22864
22865 if (app->destroyRequested != 0) {
22866 VkTestFramework::Finish();
22867 return;
22868 }
22869 }
22870
22871 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022872 // Use the following key to send arguments to gtest, i.e.
22873 // --es args "--gtest_filter=-VkLayerTest.foo"
22874 const char key[] = "args";
22875 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022877 std::string filter = "";
22878 if (args.size() > 0) {
22879 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22880 filter += args[0];
22881 } else {
22882 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22883 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022885 int argc = 2;
22886 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22887 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022889 // Route output to files until we can override the gtest output
22890 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22891 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022893 ::testing::InitGoogleTest(&argc, argv);
22894 VkTestFramework::InitArgs(&argc, argv);
22895 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022897 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022899 if (result != 0) {
22900 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22901 } else {
22902 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22903 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022905 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022907 fclose(stdout);
22908 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022910 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022911 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022912 }
22913 }
22914}
22915#endif
22916
Tony Barbour300a6082015-04-07 13:44:53 -060022917int main(int argc, char **argv) {
22918 int result;
22919
Cody Northrop8e54a402016-03-08 22:25:52 -070022920#ifdef ANDROID
22921 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022922 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022923#endif
22924
Tony Barbour300a6082015-04-07 13:44:53 -060022925 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022926 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022927
22928 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22929
22930 result = RUN_ALL_TESTS();
22931
Tony Barbour6918cd52015-04-09 12:58:51 -060022932 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022933 return result;
22934}