blob: 0008c75e7b55b7b7d4cd8c94529ea5a8b0aafe27 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800661 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
Tony Barbourf887b162017-03-09 10:06:46 -07002166 auto format = find_depth_stencil_format(m_device);
2167 if (!format) {
2168 printf(" No Depth + Stencil format found. Skipped.\n");
2169 return;
2170 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002171
Tony Barbourf92621a2016-05-02 14:28:12 -06002172 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002173 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002174 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002175 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002176
Tony Barbourf92621a2016-05-02 14:28:12 -06002177 VkImageView dsv;
2178 VkImageViewCreateInfo dsvci = {};
2179 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2180 dsvci.image = image.handle();
2181 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002182 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002183 dsvci.subresourceRange.layerCount = 1;
2184 dsvci.subresourceRange.baseMipLevel = 0;
2185 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002186 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002187
Tony Barbourf92621a2016-05-02 14:28:12 -06002188 // Create a view with depth / stencil aspect for image with different usage
2189 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002190
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002191 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002192
2193 // Initialize buffer with TRANSFER_DST usage
2194 vk_testing::Buffer buffer;
2195 VkMemoryPropertyFlags reqs = 0;
2196 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2197 VkBufferImageCopy region = {};
2198 region.bufferRowLength = 128;
2199 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002200 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002201 region.imageSubresource.layerCount = 1;
2202 region.imageExtent.height = 16;
2203 region.imageExtent.width = 16;
2204 region.imageExtent.depth = 1;
2205
Mark Lobodzinski80871462017-02-16 10:37:27 -07002206 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002207 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002208
Chris Forbesda581202016-10-06 18:25:26 +13002209 // two separate errors from this call:
2210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002213 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2214 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002215 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002216}
Tony Barbour75d79f02016-08-30 09:39:07 -06002217
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218TEST_F(VkLayerTest, LeakAnObject) {
2219 VkResult err;
2220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002221 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002222
2223 // Note that we have to create a new device since destroying the
2224 // framework's device causes Teardown() to fail and just calling Teardown
2225 // will destroy the errorMonitor.
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228
2229 ASSERT_NO_FATAL_FAILURE(InitState());
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232 std::vector<VkDeviceQueueCreateInfo> queue_info;
2233 queue_info.reserve(queue_props.size());
2234 std::vector<std::vector<float>> queue_priorities;
2235 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2236 VkDeviceQueueCreateInfo qi = {};
2237 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2238 qi.pNext = NULL;
2239 qi.queueFamilyIndex = i;
2240 qi.queueCount = queue_props[i].queueCount;
2241 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2242 qi.pQueuePriorities = queue_priorities[i].data();
2243 queue_info.push_back(qi);
2244 }
2245
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002246 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002247
2248 // The sacrificial device object
2249 VkDevice testDevice;
2250 VkDeviceCreateInfo device_create_info = {};
2251 auto features = m_device->phy().features();
2252 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2253 device_create_info.pNext = NULL;
2254 device_create_info.queueCreateInfoCount = queue_info.size();
2255 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002256 device_create_info.enabledLayerCount = 0;
2257 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258 device_create_info.pEnabledFeatures = &features;
2259 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2260 ASSERT_VK_SUCCESS(err);
2261
2262 VkFence fence;
2263 VkFenceCreateInfo fence_create_info = {};
2264 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2265 fence_create_info.pNext = NULL;
2266 fence_create_info.flags = 0;
2267 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2268 ASSERT_VK_SUCCESS(err);
2269
2270 // Induce failure by not calling vkDestroyFence
2271 vkDestroyDevice(testDevice, NULL);
2272 m_errorMonitor->VerifyFound();
2273}
2274
2275TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002276 TEST_DESCRIPTION(
2277 "Allocate command buffers from one command pool and "
2278 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002281
Cody Northropc31a84f2016-08-22 10:41:47 -06002282 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002283 VkCommandPool command_pool_one;
2284 VkCommandPool command_pool_two;
2285
2286 VkCommandPoolCreateInfo pool_create_info{};
2287 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2288 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2289 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002291 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002297 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002301 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002303 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
2305 m_errorMonitor->VerifyFound();
2306
2307 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2308 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2309}
2310
2311TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2312 VkResult err;
2313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002314 TEST_DESCRIPTION(
2315 "Allocate descriptor sets from one DS pool and "
2316 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002317
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002319
2320 ASSERT_NO_FATAL_FAILURE(InitState());
2321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2322
2323 VkDescriptorPoolSize ds_type_count = {};
2324 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2325 ds_type_count.descriptorCount = 1;
2326
2327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2329 ds_pool_ci.pNext = NULL;
2330 ds_pool_ci.flags = 0;
2331 ds_pool_ci.maxSets = 1;
2332 ds_pool_ci.poolSizeCount = 1;
2333 ds_pool_ci.pPoolSizes = &ds_type_count;
2334
2335 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002337 ASSERT_VK_SUCCESS(err);
2338
2339 // Create a second descriptor pool
2340 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002341 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002342 ASSERT_VK_SUCCESS(err);
2343
2344 VkDescriptorSetLayoutBinding dsl_binding = {};
2345 dsl_binding.binding = 0;
2346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2347 dsl_binding.descriptorCount = 1;
2348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2349 dsl_binding.pImmutableSamplers = NULL;
2350
2351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2353 ds_layout_ci.pNext = NULL;
2354 ds_layout_ci.bindingCount = 1;
2355 ds_layout_ci.pBindings = &dsl_binding;
2356
2357 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002359 ASSERT_VK_SUCCESS(err);
2360
2361 VkDescriptorSet descriptorSet;
2362 VkDescriptorSetAllocateInfo alloc_info = {};
2363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2364 alloc_info.descriptorSetCount = 1;
2365 alloc_info.descriptorPool = ds_pool_one;
2366 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2371
2372 m_errorMonitor->VerifyFound();
2373
2374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2375 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2376 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2377}
2378
2379TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002383
2384 ASSERT_NO_FATAL_FAILURE(InitState());
2385
2386 // Pass bogus handle into GetImageMemoryRequirements
2387 VkMemoryRequirements mem_reqs;
2388 uint64_t fakeImageHandle = 0xCADECADE;
2389 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2390
2391 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2392
2393 m_errorMonitor->VerifyFound();
2394}
2395
Mike Schuchardt17838902017-02-21 09:48:06 -07002396TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2397 TEST_DESCRIPTION(
2398 "Try to destroy a render pass object using a device other than the one it was created on. "
2399 "This should generate a distinct error from the invalid handle error.");
2400 // Create first device and renderpass
2401 ASSERT_NO_FATAL_FAILURE(InitState());
2402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2403
2404 // Create second device
2405 float priorities[] = {1.0f};
2406 VkDeviceQueueCreateInfo queue_info{};
2407 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2408 queue_info.pNext = NULL;
2409 queue_info.flags = 0;
2410 queue_info.queueFamilyIndex = 0;
2411 queue_info.queueCount = 1;
2412 queue_info.pQueuePriorities = &priorities[0];
2413
2414 VkDeviceCreateInfo device_create_info = {};
2415 auto features = m_device->phy().features();
2416 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2417 device_create_info.pNext = NULL;
2418 device_create_info.queueCreateInfoCount = 1;
2419 device_create_info.pQueueCreateInfos = &queue_info;
2420 device_create_info.enabledLayerCount = 0;
2421 device_create_info.ppEnabledLayerNames = NULL;
2422 device_create_info.pEnabledFeatures = &features;
2423
2424 VkDevice second_device;
2425 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2426
2427 // Try to destroy the renderpass from the first device using the second device
2428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2429 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2430 m_errorMonitor->VerifyFound();
2431
2432 vkDestroyDevice(second_device, NULL);
2433}
2434
Karl Schultz6addd812016-02-02 17:17:23 -07002435TEST_F(VkLayerTest, PipelineNotBound) {
2436 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002437
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002438 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002439
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002441
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002442 ASSERT_NO_FATAL_FAILURE(InitState());
2443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002445 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2447 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002448
2449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2451 ds_pool_ci.pNext = NULL;
2452 ds_pool_ci.maxSets = 1;
2453 ds_pool_ci.poolSizeCount = 1;
2454 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002455
2456 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002457 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458 ASSERT_VK_SUCCESS(err);
2459
2460 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002461 dsl_binding.binding = 0;
2462 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2463 dsl_binding.descriptorCount = 1;
2464 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2465 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002466
2467 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002468 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2469 ds_layout_ci.pNext = NULL;
2470 ds_layout_ci.bindingCount = 1;
2471 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002472
2473 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002475 ASSERT_VK_SUCCESS(err);
2476
2477 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002478 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002479 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002480 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002481 alloc_info.descriptorPool = ds_pool;
2482 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002483 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2488 pipeline_layout_ci.pNext = NULL;
2489 pipeline_layout_ci.setLayoutCount = 1;
2490 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002491
2492 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
Mark Youngad779052016-01-06 14:26:04 -07002496 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002497
Tony Barbour552f6c02016-12-21 14:34:07 -07002498 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002501 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002502
Chia-I Wuf7458c52015-10-26 21:10:41 +08002503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002506}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002507
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002508TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2509 VkResult err;
2510
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002511 TEST_DESCRIPTION(
2512 "Test validation check for an invalid memory type index "
2513 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002514
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002515 ASSERT_NO_FATAL_FAILURE(InitState());
2516
2517 // Create an image, allocate memory, set a bad typeIndex and then try to
2518 // bind it
2519 VkImage image;
2520 VkDeviceMemory mem;
2521 VkMemoryRequirements mem_reqs;
2522 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2523 const int32_t tex_width = 32;
2524 const int32_t tex_height = 32;
2525
2526 VkImageCreateInfo image_create_info = {};
2527 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2528 image_create_info.pNext = NULL;
2529 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2530 image_create_info.format = tex_format;
2531 image_create_info.extent.width = tex_width;
2532 image_create_info.extent.height = tex_height;
2533 image_create_info.extent.depth = 1;
2534 image_create_info.mipLevels = 1;
2535 image_create_info.arrayLayers = 1;
2536 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2537 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2538 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2539 image_create_info.flags = 0;
2540
2541 VkMemoryAllocateInfo mem_alloc = {};
2542 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2543 mem_alloc.pNext = NULL;
2544 mem_alloc.allocationSize = 0;
2545 mem_alloc.memoryTypeIndex = 0;
2546
2547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2548 ASSERT_VK_SUCCESS(err);
2549
2550 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2551 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002552
2553 // Introduce Failure, select invalid TypeIndex
2554 VkPhysicalDeviceMemoryProperties memory_info;
2555
2556 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2557 unsigned int i;
2558 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2559 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2560 mem_alloc.memoryTypeIndex = i;
2561 break;
2562 }
2563 }
2564 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002565 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002566 vkDestroyImage(m_device->device(), image, NULL);
2567 return;
2568 }
2569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002571
2572 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2573 ASSERT_VK_SUCCESS(err);
2574
2575 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2576 (void)err;
2577
2578 m_errorMonitor->VerifyFound();
2579
2580 vkDestroyImage(m_device->device(), image, NULL);
2581 vkFreeMemory(m_device->device(), mem, NULL);
2582}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002583
Karl Schultz6addd812016-02-02 17:17:23 -07002584TEST_F(VkLayerTest, BindInvalidMemory) {
2585 VkResult err;
2586 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
Cortf801b982017-01-17 18:10:21 -08002590 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002591 const int32_t tex_width = 256;
2592 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002593
2594 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2596 image_create_info.pNext = NULL;
2597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2598 image_create_info.format = tex_format;
2599 image_create_info.extent.width = tex_width;
2600 image_create_info.extent.height = tex_height;
2601 image_create_info.extent.depth = 1;
2602 image_create_info.mipLevels = 1;
2603 image_create_info.arrayLayers = 1;
2604 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002605 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2607 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002608
Cortf801b982017-01-17 18:10:21 -08002609 VkBufferCreateInfo buffer_create_info = {};
2610 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2611 buffer_create_info.pNext = NULL;
2612 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002613 buffer_create_info.size = 4 * 1024 * 1024;
2614 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002615 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002616
Cortf801b982017-01-17 18:10:21 -08002617 // Create an image/buffer, allocate memory, free it, and then try to bind it
2618 {
2619 VkImage image = VK_NULL_HANDLE;
2620 VkBuffer buffer = VK_NULL_HANDLE;
2621 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2622 ASSERT_VK_SUCCESS(err);
2623 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2624 ASSERT_VK_SUCCESS(err);
2625 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2626 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2627 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
Cortf801b982017-01-17 18:10:21 -08002629 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2630 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 image_mem_alloc.allocationSize = image_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
2634 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2635 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2636 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2637 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2640 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2643 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644
Cortf801b982017-01-17 18:10:21 -08002645 vkFreeMemory(device(), image_mem, NULL);
2646 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002647
Cortf801b982017-01-17 18:10:21 -08002648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2649 err = vkBindImageMemory(device(), image, image_mem, 0);
2650 (void)err; // This may very well return an error.
2651 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002652
Cortf801b982017-01-17 18:10:21 -08002653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2654 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2655 (void)err; // This may very well return an error.
2656 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 vkDestroyImage(m_device->device(), image, NULL);
2659 vkDestroyBuffer(m_device->device(), buffer, NULL);
2660 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002661
2662 // Try to bind memory to an object that already has a memory binding
2663 {
2664 VkImage image = VK_NULL_HANDLE;
2665 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2666 ASSERT_VK_SUCCESS(err);
2667 VkBuffer buffer = VK_NULL_HANDLE;
2668 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2669 ASSERT_VK_SUCCESS(err);
2670 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2671 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2672 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2673 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2674 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2675 image_alloc_info.allocationSize = image_mem_reqs.size;
2676 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2677 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2678 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2679 ASSERT_TRUE(pass);
2680 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2681 ASSERT_TRUE(pass);
2682 VkDeviceMemory image_mem, buffer_mem;
2683 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2684 ASSERT_VK_SUCCESS(err);
2685 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2686 ASSERT_VK_SUCCESS(err);
2687
2688 err = vkBindImageMemory(device(), image, image_mem, 0);
2689 ASSERT_VK_SUCCESS(err);
2690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2691 err = vkBindImageMemory(device(), image, image_mem, 0);
2692 (void)err; // This may very well return an error.
2693 m_errorMonitor->VerifyFound();
2694
2695 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2696 ASSERT_VK_SUCCESS(err);
2697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2698 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2699 (void)err; // This may very well return an error.
2700 m_errorMonitor->VerifyFound();
2701
2702 vkFreeMemory(device(), image_mem, NULL);
2703 vkFreeMemory(device(), buffer_mem, NULL);
2704 vkDestroyImage(device(), image, NULL);
2705 vkDestroyBuffer(device(), buffer, NULL);
2706 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002707
Cort Strattonde748202017-02-17 12:50:01 -08002708 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002709 {
2710 VkImage image = VK_NULL_HANDLE;
2711 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2712 ASSERT_VK_SUCCESS(err);
2713 VkBuffer buffer = VK_NULL_HANDLE;
2714 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2715 ASSERT_VK_SUCCESS(err);
2716 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2717 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2718 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2719 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2720 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002721 // Leave some extra space for alignment wiggle room
2722 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002723 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002724 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002725 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2726 ASSERT_TRUE(pass);
2727 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2728 ASSERT_TRUE(pass);
2729 VkDeviceMemory image_mem, buffer_mem;
2730 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2731 ASSERT_VK_SUCCESS(err);
2732 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2733 ASSERT_VK_SUCCESS(err);
2734
Cort Strattonde748202017-02-17 12:50:01 -08002735 // Test unaligned memory offset
2736 {
2737 if (image_mem_reqs.alignment > 1) {
2738 VkDeviceSize image_offset = 1;
2739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2740 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2741 (void)err; // This may very well return an error.
2742 m_errorMonitor->VerifyFound();
2743 }
Cort6c7dff72017-01-27 18:34:50 -08002744
Cort Strattonde748202017-02-17 12:50:01 -08002745 if (buffer_mem_reqs.alignment > 1) {
2746 VkDeviceSize buffer_offset = 1;
2747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2748 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2749 (void)err; // This may very well return an error.
2750 m_errorMonitor->VerifyFound();
2751 }
2752 }
2753
2754 // Test memory offsets outside the memory allocation
2755 {
2756 VkDeviceSize image_offset =
2757 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2759 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2760 (void)err; // This may very well return an error.
2761 m_errorMonitor->VerifyFound();
2762
2763 VkDeviceSize buffer_offset =
2764 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2766 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2767 (void)err; // This may very well return an error.
2768 m_errorMonitor->VerifyFound();
2769 }
2770
2771 // Test memory offsets within the memory allocation, but which leave too little memory for
2772 // the resource.
2773 {
2774 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2775 if (image_offset > 0) {
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2777 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 }
2781
2782 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2783 if (buffer_offset > 0) {
2784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2785 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2786 (void)err; // This may very well return an error.
2787 m_errorMonitor->VerifyFound();
2788 }
2789 }
Cort6c7dff72017-01-27 18:34:50 -08002790
2791 vkFreeMemory(device(), image_mem, NULL);
2792 vkFreeMemory(device(), buffer_mem, NULL);
2793 vkDestroyImage(device(), image, NULL);
2794 vkDestroyBuffer(device(), buffer, NULL);
2795 }
2796
Cort Stratton4c38bb52017-01-28 13:33:10 -08002797 // Try to bind memory to an object with an invalid memory type
2798 {
2799 VkImage image = VK_NULL_HANDLE;
2800 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2801 ASSERT_VK_SUCCESS(err);
2802 VkBuffer buffer = VK_NULL_HANDLE;
2803 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2804 ASSERT_VK_SUCCESS(err);
2805 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2806 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2807 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2808 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2809 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2810 image_alloc_info.allocationSize = image_mem_reqs.size;
2811 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2812 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002813 // Create a mask of available memory types *not* supported by these resources,
2814 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002815 VkPhysicalDeviceMemoryProperties memory_properties = {};
2816 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002817 VkDeviceMemory image_mem, buffer_mem;
2818
Cort Stratton4c38bb52017-01-28 13:33:10 -08002819 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002820 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002821 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2822 ASSERT_TRUE(pass);
2823 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2824 ASSERT_VK_SUCCESS(err);
2825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2826 err = vkBindImageMemory(device(), image, image_mem, 0);
2827 (void)err; // This may very well return an error.
2828 m_errorMonitor->VerifyFound();
2829 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 }
2831
Cort Stratton4c38bb52017-01-28 13:33:10 -08002832 uint32_t buffer_unsupported_mem_type_bits =
2833 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002834 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002835 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2836 ASSERT_TRUE(pass);
2837 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2838 ASSERT_VK_SUCCESS(err);
2839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2840 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2841 (void)err; // This may very well return an error.
2842 m_errorMonitor->VerifyFound();
2843 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002845
Cort Stratton4c38bb52017-01-28 13:33:10 -08002846 vkDestroyImage(device(), image, NULL);
2847 vkDestroyBuffer(device(), buffer, NULL);
2848 }
2849
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002850 // Try to bind memory to an image created with sparse memory flags
2851 {
2852 VkImageCreateInfo sparse_image_create_info = image_create_info;
2853 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2854 VkImageFormatProperties image_format_properties = {};
2855 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2856 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2857 sparse_image_create_info.usage, sparse_image_create_info.flags,
2858 &image_format_properties);
2859 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2860 // most likely means sparse formats aren't supported here; skip this test.
2861 } else {
2862 ASSERT_VK_SUCCESS(err);
2863 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002864 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002865 return;
2866 } else {
2867 VkImage sparse_image = VK_NULL_HANDLE;
2868 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2869 ASSERT_VK_SUCCESS(err);
2870 VkMemoryRequirements sparse_mem_reqs = {};
2871 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2872 if (sparse_mem_reqs.memoryTypeBits != 0) {
2873 VkMemoryAllocateInfo sparse_mem_alloc = {};
2874 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2875 sparse_mem_alloc.pNext = NULL;
2876 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2877 sparse_mem_alloc.memoryTypeIndex = 0;
2878 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2879 ASSERT_TRUE(pass);
2880 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2881 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2882 ASSERT_VK_SUCCESS(err);
2883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2884 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2885 // This may very well return an error.
2886 (void)err;
2887 m_errorMonitor->VerifyFound();
2888 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2889 }
2890 vkDestroyImage(m_device->device(), sparse_image, NULL);
2891 }
2892 }
2893 }
2894
2895 // Try to bind memory to a buffer created with sparse memory flags
2896 {
2897 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2898 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2899 if (!m_device->phy().features().sparseResidencyBuffer) {
2900 // most likely means sparse formats aren't supported here; skip this test.
2901 } else {
2902 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2903 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2904 ASSERT_VK_SUCCESS(err);
2905 VkMemoryRequirements sparse_mem_reqs = {};
2906 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2907 if (sparse_mem_reqs.memoryTypeBits != 0) {
2908 VkMemoryAllocateInfo sparse_mem_alloc = {};
2909 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2910 sparse_mem_alloc.pNext = NULL;
2911 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2912 sparse_mem_alloc.memoryTypeIndex = 0;
2913 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2914 ASSERT_TRUE(pass);
2915 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2916 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2917 ASSERT_VK_SUCCESS(err);
2918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2919 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2920 // This may very well return an error.
2921 (void)err;
2922 m_errorMonitor->VerifyFound();
2923 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2924 }
2925 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2926 }
2927 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002928}
2929
Karl Schultz6addd812016-02-02 17:17:23 -07002930TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2931 VkResult err;
2932 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002933
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002935
Tobin Ehlisec598302015-09-15 15:02:17 -06002936 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002937
Karl Schultz6addd812016-02-02 17:17:23 -07002938 // Create an image object, allocate memory, destroy the object and then try
2939 // to bind it
2940 VkImage image;
2941 VkDeviceMemory mem;
2942 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultz6addd812016-02-02 17:17:23 -07002944 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2945 const int32_t tex_width = 32;
2946 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
2948 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002949 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2950 image_create_info.pNext = NULL;
2951 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2952 image_create_info.format = tex_format;
2953 image_create_info.extent.width = tex_width;
2954 image_create_info.extent.height = tex_height;
2955 image_create_info.extent.depth = 1;
2956 image_create_info.mipLevels = 1;
2957 image_create_info.arrayLayers = 1;
2958 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2959 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2960 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2961 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002962
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002963 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002964 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2965 mem_alloc.pNext = NULL;
2966 mem_alloc.allocationSize = 0;
2967 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002968
Chia-I Wuf7458c52015-10-26 21:10:41 +08002969 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002970 ASSERT_VK_SUCCESS(err);
2971
Karl Schultz6addd812016-02-02 17:17:23 -07002972 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002975 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002976 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002977
2978 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002979 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002983 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002984 ASSERT_VK_SUCCESS(err);
2985
2986 // Now Try to bind memory to this destroyed object
2987 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2988 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002989 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002991 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002992
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002994}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002995
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002996TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2997 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2998
2999 ASSERT_NO_FATAL_FAILURE(InitState());
3000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3001
3002 VkVertexInputBindingDescription input_binding;
3003 memset(&input_binding, 0, sizeof(input_binding));
3004
3005 VkVertexInputAttributeDescription input_attribs;
3006 memset(&input_attribs, 0, sizeof(input_attribs));
3007
3008 // Pick a really bad format for this purpose and make sure it should fail
3009 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3010 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3011 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003012 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003013 return;
3014 }
3015
3016 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003017 char const *vsSource =
3018 "#version 450\n"
3019 "\n"
3020 "out gl_PerVertex {\n"
3021 " vec4 gl_Position;\n"
3022 "};\n"
3023 "void main(){\n"
3024 " gl_Position = vec4(1);\n"
3025 "}\n";
3026 char const *fsSource =
3027 "#version 450\n"
3028 "\n"
3029 "layout(location=0) out vec4 color;\n"
3030 "void main(){\n"
3031 " color = vec4(1);\n"
3032 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003033
3034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3035 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3036 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3037
3038 VkPipelineObj pipe(m_device);
3039 pipe.AddColorAttachment();
3040 pipe.AddShader(&vs);
3041 pipe.AddShader(&fs);
3042
3043 pipe.AddVertexInputBindings(&input_binding, 1);
3044 pipe.AddVertexInputAttribs(&input_attribs, 1);
3045
3046 VkDescriptorSetObj descriptorSet(m_device);
3047 descriptorSet.AppendDummy();
3048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3049
3050 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3051
3052 m_errorMonitor->VerifyFound();
3053}
3054
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003055TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003056 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3057 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003058
3059 VkMemoryPropertyFlags reqs = 0;
3060 VkImageCreateInfo image_create_info = {};
3061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3062 image_create_info.pNext = NULL;
3063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3064 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3065 image_create_info.extent.width = 256;
3066 image_create_info.extent.height = 256;
3067 image_create_info.extent.depth = 1;
3068 image_create_info.mipLevels = 1;
3069 image_create_info.arrayLayers = 1;
3070 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3071 image_create_info.flags = 0;
3072
3073 VkImageBlit blit_region = {};
3074 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3075 blit_region.srcSubresource.baseArrayLayer = 0;
3076 blit_region.srcSubresource.layerCount = 1;
3077 blit_region.srcSubresource.mipLevel = 0;
3078 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3079 blit_region.dstSubresource.baseArrayLayer = 0;
3080 blit_region.dstSubresource.layerCount = 1;
3081 blit_region.dstSubresource.mipLevel = 0;
3082
3083 // Create two images, the source with sampleCount = 2, and attempt to blit
3084 // between them
3085 {
3086 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003088 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003090 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003094 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003095 m_errorMonitor->SetDesiredFailureMsg(
3096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3097 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003098 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3099 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 m_errorMonitor->VerifyFound();
3101 m_commandBuffer->EndCommandBuffer();
3102 }
3103
3104 // Create two images, the dest with sampleCount = 4, and attempt to blit
3105 // between them
3106 {
3107 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003113 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003115 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003116 m_errorMonitor->SetDesiredFailureMsg(
3117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3118 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003119 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3120 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 m_errorMonitor->VerifyFound();
3122 m_commandBuffer->EndCommandBuffer();
3123 }
3124
3125 VkBufferImageCopy copy_region = {};
3126 copy_region.bufferRowLength = 128;
3127 copy_region.bufferImageHeight = 128;
3128 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3129 copy_region.imageSubresource.layerCount = 1;
3130 copy_region.imageExtent.height = 64;
3131 copy_region.imageExtent.width = 64;
3132 copy_region.imageExtent.depth = 1;
3133
3134 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3135 // buffer to image
3136 {
3137 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003138 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3139 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003140 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003141 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003142 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003143 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003144 m_errorMonitor->SetDesiredFailureMsg(
3145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3146 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003147 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3148 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003149 m_errorMonitor->VerifyFound();
3150 m_commandBuffer->EndCommandBuffer();
3151 }
3152
3153 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3154 // image to buffer
3155 {
3156 vk_testing::Buffer dst_buffer;
3157 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3158 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003159 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003160 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003161 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003162 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003163 m_errorMonitor->SetDesiredFailureMsg(
3164 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3165 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003166 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 dst_buffer.handle(), 1, &copy_region);
3168 m_errorMonitor->VerifyFound();
3169 m_commandBuffer->EndCommandBuffer();
3170 }
3171}
3172
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003173TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003174 ASSERT_NO_FATAL_FAILURE(InitState());
3175
3176 VkImageObj src_image(m_device);
3177 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3178 VkImageObj dst_image(m_device);
3179 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3180 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003181 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003182
3183 VkImageBlit blitRegion = {};
3184 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3185 blitRegion.srcSubresource.baseArrayLayer = 0;
3186 blitRegion.srcSubresource.layerCount = 1;
3187 blitRegion.srcSubresource.mipLevel = 0;
3188 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3189 blitRegion.dstSubresource.baseArrayLayer = 0;
3190 blitRegion.dstSubresource.layerCount = 1;
3191 blitRegion.dstSubresource.mipLevel = 0;
3192
Dave Houlton34df4cb2016-12-01 16:43:06 -07003193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3194
3195 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3196 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003197
3198 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003199 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003200 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3201 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003202
3203 m_errorMonitor->VerifyFound();
3204
Dave Houlton34df4cb2016-12-01 16:43:06 -07003205 // Test should generate 2 VU failures
3206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
3209 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
Dave Houlton34df4cb2016-12-01 16:43:06 -07003213 // TODO: Note that this only verifies that at least one of the VU enums was found
3214 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003215 m_errorMonitor->VerifyFound();
3216
Tony Barbour552f6c02016-12-21 14:34:07 -07003217 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218}
3219
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003220TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3221 VkResult err;
3222 bool pass;
3223
3224 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3225 ASSERT_NO_FATAL_FAILURE(InitState());
3226
3227 // If w/d/h granularity is 1, test is not meaningful
3228 // TODO: When virtual device limits are available, create a set of limits for this test that
3229 // will always have a granularity of > 1 for w, h, and d
3230 auto index = m_device->graphics_queue_node_index_;
3231 auto queue_family_properties = m_device->phy().queue_properties();
3232
3233 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3234 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3235 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3236 return;
3237 }
3238
3239 // Create two images of different types and try to copy between them
3240 VkImage srcImage;
3241 VkImage dstImage;
3242 VkDeviceMemory srcMem;
3243 VkDeviceMemory destMem;
3244 VkMemoryRequirements memReqs;
3245
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003246 VkImageCreateInfo image_create_info = {};
3247 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3248 image_create_info.pNext = NULL;
3249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3250 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3251 image_create_info.extent.width = 32;
3252 image_create_info.extent.height = 32;
3253 image_create_info.extent.depth = 1;
3254 image_create_info.mipLevels = 1;
3255 image_create_info.arrayLayers = 4;
3256 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3257 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3258 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3259 image_create_info.flags = 0;
3260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003262 ASSERT_VK_SUCCESS(err);
3263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003264 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003265 ASSERT_VK_SUCCESS(err);
3266
3267 // Allocate memory
3268 VkMemoryAllocateInfo memAlloc = {};
3269 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3270 memAlloc.pNext = NULL;
3271 memAlloc.allocationSize = 0;
3272 memAlloc.memoryTypeIndex = 0;
3273
3274 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3275 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003276 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003277 ASSERT_TRUE(pass);
3278 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3279 ASSERT_VK_SUCCESS(err);
3280
3281 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3282 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003284 ASSERT_VK_SUCCESS(err);
3285 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3286 ASSERT_VK_SUCCESS(err);
3287
3288 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3289 ASSERT_VK_SUCCESS(err);
3290 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3291 ASSERT_VK_SUCCESS(err);
3292
Tony Barbour552f6c02016-12-21 14:34:07 -07003293 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 VkImageCopy copyRegion;
3295 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3296 copyRegion.srcSubresource.mipLevel = 0;
3297 copyRegion.srcSubresource.baseArrayLayer = 0;
3298 copyRegion.srcSubresource.layerCount = 1;
3299 copyRegion.srcOffset.x = 0;
3300 copyRegion.srcOffset.y = 0;
3301 copyRegion.srcOffset.z = 0;
3302 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3303 copyRegion.dstSubresource.mipLevel = 0;
3304 copyRegion.dstSubresource.baseArrayLayer = 0;
3305 copyRegion.dstSubresource.layerCount = 1;
3306 copyRegion.dstOffset.x = 0;
3307 copyRegion.dstOffset.y = 0;
3308 copyRegion.dstOffset.z = 0;
3309 copyRegion.extent.width = 1;
3310 copyRegion.extent.height = 1;
3311 copyRegion.extent.depth = 1;
3312
3313 // Introduce failure by setting srcOffset to a bad granularity value
3314 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3316 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003317 m_errorMonitor->VerifyFound();
3318
3319 // Introduce failure by setting extent to a bad granularity value
3320 copyRegion.srcOffset.y = 0;
3321 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3323 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003324 m_errorMonitor->VerifyFound();
3325
3326 // Now do some buffer/image copies
3327 vk_testing::Buffer buffer;
3328 VkMemoryPropertyFlags reqs = 0;
3329 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3330 VkBufferImageCopy region = {};
3331 region.bufferOffset = 0;
3332 region.bufferRowLength = 3;
3333 region.bufferImageHeight = 128;
3334 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3335 region.imageSubresource.layerCount = 1;
3336 region.imageExtent.height = 16;
3337 region.imageExtent.width = 16;
3338 region.imageExtent.depth = 1;
3339 region.imageOffset.x = 0;
3340 region.imageOffset.y = 0;
3341 region.imageOffset.z = 0;
3342
3343 // Introduce failure by setting bufferRowLength to a bad granularity value
3344 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3346 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3347 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003348 m_errorMonitor->VerifyFound();
3349 region.bufferRowLength = 128;
3350
3351 // Introduce failure by setting bufferOffset to a bad granularity value
3352 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3354 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3355 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003356 m_errorMonitor->VerifyFound();
3357 region.bufferOffset = 0;
3358
3359 // Introduce failure by setting bufferImageHeight to a bad granularity value
3360 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3363 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003364 m_errorMonitor->VerifyFound();
3365 region.bufferImageHeight = 128;
3366
3367 // Introduce failure by setting imageExtent to a bad granularity value
3368 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3370 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3371 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003372 m_errorMonitor->VerifyFound();
3373 region.imageExtent.width = 16;
3374
3375 // Introduce failure by setting imageOffset to a bad granularity value
3376 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3378 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3379 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003380 m_errorMonitor->VerifyFound();
3381
Tony Barbour552f6c02016-12-21 14:34:07 -07003382 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003383
3384 vkDestroyImage(m_device->device(), srcImage, NULL);
3385 vkDestroyImage(m_device->device(), dstImage, NULL);
3386 vkFreeMemory(m_device->device(), srcMem, NULL);
3387 vkFreeMemory(m_device->device(), destMem, NULL);
3388}
3389
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003390TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003391 TEST_DESCRIPTION(
3392 "Submit command buffer created using one queue family and "
3393 "attempt to submit them on a queue created in a different "
3394 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003395
Cody Northropc31a84f2016-08-22 10:41:47 -06003396 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003397
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003398 // This test is meaningless unless we have multiple queue families
3399 auto queue_family_properties = m_device->phy().queue_properties();
3400 if (queue_family_properties.size() < 2) {
3401 return;
3402 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003404 // Get safe index of another queue family
3405 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3406 ASSERT_NO_FATAL_FAILURE(InitState());
3407 // Create a second queue using a different queue family
3408 VkQueue other_queue;
3409 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3410
3411 // Record an empty cmd buffer
3412 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3413 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3414 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3415 vkEndCommandBuffer(m_commandBuffer->handle());
3416
3417 // And submit on the wrong queue
3418 VkSubmitInfo submit_info = {};
3419 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3420 submit_info.commandBufferCount = 1;
3421 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003422 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003423
3424 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003425}
3426
Chris Forbes4c24a922016-11-16 08:59:10 +13003427TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3428 ASSERT_NO_FATAL_FAILURE(InitState());
3429
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003430 // There are no attachments, but refer to attachment 0.
3431 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003432 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003433 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003434 };
3435
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003437 VkRenderPass rp;
3438
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003439 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003441 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3442 m_errorMonitor->VerifyFound();
3443}
3444
Chris Forbesa58c4522016-09-28 15:19:39 +13003445TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3446 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3447 ASSERT_NO_FATAL_FAILURE(InitState());
3448
3449 // A renderpass with two subpasses, both writing the same attachment.
3450 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3452 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3453 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003454 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003455 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003456 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003457 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3458 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003459 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003460 VkSubpassDependency dep = {0,
3461 1,
3462 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3463 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3464 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3465 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3466 VK_DEPENDENCY_BY_REGION_BIT};
3467 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003468 VkRenderPass rp;
3469 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3470 ASSERT_VK_SUCCESS(err);
3471
3472 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003473 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003474 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3475
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003476 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003477 VkFramebuffer fb;
3478 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3479 ASSERT_VK_SUCCESS(err);
3480
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003481 char const *vsSource =
3482 "#version 450\n"
3483 "void main() { gl_Position = vec4(1); }\n";
3484 char const *fsSource =
3485 "#version 450\n"
3486 "layout(location=0) out vec4 color;\n"
3487 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003488
3489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3491 VkPipelineObj pipe(m_device);
3492 pipe.AddColorAttachment();
3493 pipe.AddShader(&vs);
3494 pipe.AddShader(&fs);
3495 VkViewport view_port = {};
3496 m_viewports.push_back(view_port);
3497 pipe.SetViewport(m_viewports);
3498 VkRect2D rect = {};
3499 m_scissors.push_back(rect);
3500 pipe.SetScissor(m_scissors);
3501
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003502 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003503 VkPipelineLayout pl;
3504 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3505 ASSERT_VK_SUCCESS(err);
3506 pipe.CreateVKPipeline(pl, rp);
3507
Tony Barbour552f6c02016-12-21 14:34:07 -07003508 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003509
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003510 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3511 nullptr,
3512 rp,
3513 fb,
3514 {{
3515 0, 0,
3516 },
3517 {32, 32}},
3518 0,
3519 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003520
3521 // subtest 1: bind in the wrong subpass
3522 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3523 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003525 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3526 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3527 m_errorMonitor->VerifyFound();
3528
3529 vkCmdEndRenderPass(m_commandBuffer->handle());
3530
3531 // subtest 2: bind in correct subpass, then transition to next subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3534 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
Tony Barbour552f6c02016-12-21 14:34:07 -07003541 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003542
3543 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3544 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3545 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3546}
3547
Tony Barbour4e919972016-08-09 13:27:40 -06003548TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003549 TEST_DESCRIPTION(
3550 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3551 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003552 ASSERT_NO_FATAL_FAILURE(InitState());
3553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3554
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3556 "Cannot execute a render pass with renderArea "
3557 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003558
3559 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3560 m_renderPassBeginInfo.renderArea.extent.width = 257;
3561 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003562 m_commandBuffer->BeginCommandBuffer();
3563 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003564 m_errorMonitor->VerifyFound();
3565}
3566
3567TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003568 TEST_DESCRIPTION(
3569 "Generate INDEPENDENT_BLEND by disabling independent "
3570 "blend and then specifying different blend states for two "
3571 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003572 VkPhysicalDeviceFeatures features = {};
3573 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003574 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3577 "Invalid Pipeline CreateInfo: If independent blend feature not "
3578 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003579
Cody Northropc31a84f2016-08-22 10:41:47 -06003580 VkDescriptorSetObj descriptorSet(m_device);
3581 descriptorSet.AppendDummy();
3582 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003583
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003585 // Create a renderPass with two color attachments
3586 VkAttachmentReference attachments[2] = {};
3587 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003588 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003589 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3590
3591 VkSubpassDescription subpass = {};
3592 subpass.pColorAttachments = attachments;
3593 subpass.colorAttachmentCount = 2;
3594
3595 VkRenderPassCreateInfo rpci = {};
3596 rpci.subpassCount = 1;
3597 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599
Tony Barbourffd60bd2017-03-09 12:04:55 -07003600 VkAttachmentDescription attach_desc[2] = {};
3601 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3602 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3603 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3604 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3605 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3606 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3607 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3608 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003611 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3612
3613 VkRenderPass renderpass;
3614 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003616 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003617
Cody Northropc31a84f2016-08-22 10:41:47 -06003618 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3619 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3620 att_state1.blendEnable = VK_TRUE;
3621 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3622 att_state2.blendEnable = VK_FALSE;
3623 pipeline.AddColorAttachment(0, &att_state1);
3624 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003625 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003627 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003628}
3629
Mike Weiblen40b160e2017-02-06 19:21:52 -07003630// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3631TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3632 TEST_DESCRIPTION(
3633 "Create a graphics pipeline that is incompatible with the requirements "
3634 "of its contained Renderpass/subpasses.");
3635 ASSERT_NO_FATAL_FAILURE(InitState());
3636
3637 VkDescriptorSetObj ds_obj(m_device);
3638 ds_obj.AppendDummy();
3639 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3640
3641 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3642
3643 VkPipelineColorBlendAttachmentState att_state1 = {};
3644 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3645 att_state1.blendEnable = VK_TRUE;
3646
3647 VkRenderpassObj rp_obj(m_device);
3648
3649 {
3650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3651 VkPipelineObj pipeline(m_device);
3652 pipeline.AddShader(&vs_obj);
3653 pipeline.AddColorAttachment(0, &att_state1);
3654
3655 VkGraphicsPipelineCreateInfo info = {};
3656 pipeline.InitGraphicsPipelineCreateInfo(&info);
3657 info.pColorBlendState = nullptr;
3658
3659 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3660 m_errorMonitor->VerifyFound();
3661 }
3662}
3663
Chris Forbes26ec2122016-11-29 08:58:33 +13003664#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003665TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3666 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3667 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003668 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3671 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003672
3673 // Create a renderPass with a single color attachment
3674 VkAttachmentReference attach = {};
3675 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3676 VkSubpassDescription subpass = {};
3677 VkRenderPassCreateInfo rpci = {};
3678 rpci.subpassCount = 1;
3679 rpci.pSubpasses = &subpass;
3680 rpci.attachmentCount = 1;
3681 VkAttachmentDescription attach_desc = {};
3682 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3683 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3684 rpci.pAttachments = &attach_desc;
3685 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3686 VkRenderPass rp;
3687 subpass.pDepthStencilAttachment = &attach;
3688 subpass.pColorAttachments = NULL;
3689 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3690 m_errorMonitor->VerifyFound();
3691}
Chris Forbes26ec2122016-11-29 08:58:33 +13003692#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003693
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003695 TEST_DESCRIPTION(
3696 "Create a framebuffer where a subpass has a preserve "
3697 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003698
3699 ASSERT_NO_FATAL_FAILURE(InitState());
3700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003703
3704 VkAttachmentReference color_attach = {};
3705 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3706 color_attach.attachment = 0;
3707 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3708 VkSubpassDescription subpass = {};
3709 subpass.colorAttachmentCount = 1;
3710 subpass.pColorAttachments = &color_attach;
3711 subpass.preserveAttachmentCount = 1;
3712 subpass.pPreserveAttachments = &preserve_attachment;
3713
3714 VkRenderPassCreateInfo rpci = {};
3715 rpci.subpassCount = 1;
3716 rpci.pSubpasses = &subpass;
3717 rpci.attachmentCount = 1;
3718 VkAttachmentDescription attach_desc = {};
3719 attach_desc.format = VK_FORMAT_UNDEFINED;
3720 rpci.pAttachments = &attach_desc;
3721 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3722 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003723 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003724
3725 m_errorMonitor->VerifyFound();
3726
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003727 if (result == VK_SUCCESS) {
3728 vkDestroyRenderPass(m_device->device(), rp, NULL);
3729 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003730}
3731
Chris Forbesc5389742016-06-29 11:49:23 +12003732TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003733 TEST_DESCRIPTION(
3734 "Ensure that CreateRenderPass produces a validation error "
3735 "when the source of a subpass multisample resolve "
3736 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003737
Chris Forbesc5389742016-06-29 11:49:23 +12003738 ASSERT_NO_FATAL_FAILURE(InitState());
3739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3741 "Subpass 0 requests multisample resolve from attachment 0 which has "
3742 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003743
3744 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003745 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3746 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3747 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3748 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3749 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003751 };
3752
3753 VkAttachmentReference color = {
3754 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3755 };
3756
3757 VkAttachmentReference resolve = {
3758 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3759 };
3760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003764
3765 VkRenderPass rp;
3766 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3767
3768 m_errorMonitor->VerifyFound();
3769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003770 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003771}
3772
3773TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003774 TEST_DESCRIPTION(
3775 "Ensure CreateRenderPass produces a validation error "
3776 "when a subpass multisample resolve operation is "
3777 "requested, and the destination of that resolve has "
3778 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003779
Chris Forbesc5389742016-06-29 11:49:23 +12003780 ASSERT_NO_FATAL_FAILURE(InitState());
3781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3783 "Subpass 0 requests multisample resolve into attachment 1, which "
3784 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003785
3786 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003787 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3788 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3789 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3790 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3791 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3792 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003793 };
3794
3795 VkAttachmentReference color = {
3796 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3797 };
3798
3799 VkAttachmentReference resolve = {
3800 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3801 };
3802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003805 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003806
3807 VkRenderPass rp;
3808 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3809
3810 m_errorMonitor->VerifyFound();
3811
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003812 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003813}
3814
Chris Forbes3f128ef2016-06-29 14:58:53 +12003815TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003816 TEST_DESCRIPTION(
3817 "Ensure CreateRenderPass produces a validation error "
3818 "when the color and depth attachments used by a subpass "
3819 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003820
Chris Forbes3f128ef2016-06-29 14:58:53 +12003821 ASSERT_NO_FATAL_FAILURE(InitState());
3822
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3824 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825
3826 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003827 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3828 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3829 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3830 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3831 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3832 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003833 };
3834
3835 VkAttachmentReference color[] = {
3836 {
3837 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3838 },
3839 {
3840 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3841 },
3842 };
3843
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003846 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003847
3848 VkRenderPass rp;
3849 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3850
3851 m_errorMonitor->VerifyFound();
3852
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003853 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003854}
3855
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003856TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003857 TEST_DESCRIPTION(
3858 "Hit errors when attempting to create a framebuffer :\n"
3859 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3860 " 2. Use a color image as depthStencil attachment\n"
3861 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3862 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3863 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3864 " 6. Framebuffer attachment where dimensions don't match\n"
3865 " 7. Framebuffer attachment w/o identity swizzle\n"
3866 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003867
3868 ASSERT_NO_FATAL_FAILURE(InitState());
3869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3870
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003871 m_errorMonitor->SetDesiredFailureMsg(
3872 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3873 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003874
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003875 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003876 VkAttachmentReference attach = {};
3877 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3878 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003879 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003880 VkRenderPassCreateInfo rpci = {};
3881 rpci.subpassCount = 1;
3882 rpci.pSubpasses = &subpass;
3883 rpci.attachmentCount = 1;
3884 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003885 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003886 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003887 rpci.pAttachments = &attach_desc;
3888 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3889 VkRenderPass rp;
3890 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3891 ASSERT_VK_SUCCESS(err);
3892
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003893 VkImageView ivs[2];
3894 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3895 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003896 VkFramebufferCreateInfo fb_info = {};
3897 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3898 fb_info.pNext = NULL;
3899 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003900 // Set mis-matching attachmentCount
3901 fb_info.attachmentCount = 2;
3902 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003903 fb_info.width = 100;
3904 fb_info.height = 100;
3905 fb_info.layers = 1;
3906
3907 VkFramebuffer fb;
3908 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3909
3910 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003911 if (err == VK_SUCCESS) {
3912 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3913 }
3914 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003915
3916 // Create a renderPass with a depth-stencil attachment created with
3917 // IMAGE_USAGE_COLOR_ATTACHMENT
3918 // Add our color attachment to pDepthStencilAttachment
3919 subpass.pDepthStencilAttachment = &attach;
3920 subpass.pColorAttachments = NULL;
3921 VkRenderPass rp_ds;
3922 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3923 ASSERT_VK_SUCCESS(err);
3924 // Set correct attachment count, but attachment has COLOR usage bit set
3925 fb_info.attachmentCount = 1;
3926 fb_info.renderPass = rp_ds;
3927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003929 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3930
3931 m_errorMonitor->VerifyFound();
3932 if (err == VK_SUCCESS) {
3933 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3934 }
3935 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003936
3937 // Create new renderpass with alternate attachment format from fb
3938 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3939 subpass.pDepthStencilAttachment = NULL;
3940 subpass.pColorAttachments = &attach;
3941 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3942 ASSERT_VK_SUCCESS(err);
3943
3944 // Cause error due to mis-matched formats between rp & fb
3945 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3946 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3948 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003949 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3950
3951 m_errorMonitor->VerifyFound();
3952 if (err == VK_SUCCESS) {
3953 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3954 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003955 vkDestroyRenderPass(m_device->device(), rp, NULL);
3956
3957 // Create new renderpass with alternate sample count from fb
3958 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3959 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3960 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3961 ASSERT_VK_SUCCESS(err);
3962
3963 // Cause error due to mis-matched sample count between rp & fb
3964 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003966 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003967 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3968
3969 m_errorMonitor->VerifyFound();
3970 if (err == VK_SUCCESS) {
3971 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3972 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003973
3974 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003975
3976 // Create a custom imageView with non-1 mip levels
3977 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003978 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003979 ASSERT_TRUE(image.initialized());
3980
3981 VkImageView view;
3982 VkImageViewCreateInfo ivci = {};
3983 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3984 ivci.image = image.handle();
3985 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3986 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3987 ivci.subresourceRange.layerCount = 1;
3988 ivci.subresourceRange.baseMipLevel = 0;
3989 // Set level count 2 (only 1 is allowed for FB attachment)
3990 ivci.subresourceRange.levelCount = 2;
3991 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3992 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3993 ASSERT_VK_SUCCESS(err);
3994 // Re-create renderpass to have matching sample count
3995 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3996 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3997 ASSERT_VK_SUCCESS(err);
3998
3999 fb_info.renderPass = rp;
4000 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004002 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4003
4004 m_errorMonitor->VerifyFound();
4005 if (err == VK_SUCCESS) {
4006 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4007 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004008 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004009 // Update view to original color buffer and grow FB dimensions too big
4010 fb_info.pAttachments = ivs;
4011 fb_info.height = 1024;
4012 fb_info.width = 1024;
4013 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004015 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4016
4017 m_errorMonitor->VerifyFound();
4018 if (err == VK_SUCCESS) {
4019 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4020 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004021 // Create view attachment with non-identity swizzle
4022 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4023 ivci.image = image.handle();
4024 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4025 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4026 ivci.subresourceRange.layerCount = 1;
4027 ivci.subresourceRange.baseMipLevel = 0;
4028 ivci.subresourceRange.levelCount = 1;
4029 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4030 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4031 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4032 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4033 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4034 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4035 ASSERT_VK_SUCCESS(err);
4036
4037 fb_info.pAttachments = &view;
4038 fb_info.height = 100;
4039 fb_info.width = 100;
4040 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004041 m_errorMonitor->SetDesiredFailureMsg(
4042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4043 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004044 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4045
4046 m_errorMonitor->VerifyFound();
4047 if (err == VK_SUCCESS) {
4048 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4049 }
4050 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004051 // reset attachment to color attachment
4052 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004053
4054 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004055 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004056 fb_info.height = 100;
4057 fb_info.layers = 1;
4058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004059 m_errorMonitor->SetDesiredFailureMsg(
4060 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004061 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4062 "Here are the respective dimensions for attachment");
4063
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004064 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4065
4066 m_errorMonitor->VerifyFound();
4067 if (err == VK_SUCCESS) {
4068 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4069 }
4070
4071 // Request fb that exceeds max height
4072 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004073 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 fb_info.layers = 1;
4075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004076 m_errorMonitor->SetDesiredFailureMsg(
4077 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004078 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4079 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004080 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4081
4082 m_errorMonitor->VerifyFound();
4083 if (err == VK_SUCCESS) {
4084 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4085 }
4086
4087 // Request fb that exceeds max layers
4088 fb_info.width = 100;
4089 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004090 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004092 m_errorMonitor->SetDesiredFailureMsg(
4093 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004094 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4095 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004096 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4097
4098 m_errorMonitor->VerifyFound();
4099 if (err == VK_SUCCESS) {
4100 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4101 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004102
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004103 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004104}
4105
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004107 TEST_DESCRIPTION(
4108 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4109 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004110
Cody Northropc31a84f2016-08-22 10:41:47 -06004111 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004112 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4114 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004115 m_errorMonitor->VerifyFound();
4116}
4117
4118TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004119 TEST_DESCRIPTION(
4120 "Run a simple draw calls to validate failure when Line Width dynamic "
4121 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004122
Cody Northropc31a84f2016-08-22 10:41:47 -06004123 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004124 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4126 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004127 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004128}
4129
4130TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004131 TEST_DESCRIPTION(
4132 "Run a simple draw calls to validate failure when Viewport dynamic "
4133 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004134
Cody Northropc31a84f2016-08-22 10:41:47 -06004135 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004136 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4138 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004139 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004140 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004141}
4142
4143TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004144 TEST_DESCRIPTION(
4145 "Run a simple draw calls to validate failure when Scissor dynamic "
4146 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004147
Cody Northropc31a84f2016-08-22 10:41:47 -06004148 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004149 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4151 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004153 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004154}
4155
Cortd713fe82016-07-27 09:51:27 -07004156TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004157 TEST_DESCRIPTION(
4158 "Run a simple draw calls to validate failure when Blend Constants "
4159 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004160
4161 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004162 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4164 "Dynamic blend constants state not set for this command buffer");
4165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004166 m_errorMonitor->VerifyFound();
4167}
4168
4169TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004170 TEST_DESCRIPTION(
4171 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4172 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004173
4174 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004175 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004176 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004177 return;
4178 }
4179 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4181 "Dynamic depth bounds state not set for this command buffer");
4182 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004183 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004184}
4185
4186TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004187 TEST_DESCRIPTION(
4188 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4189 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004190
4191 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004192 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4194 "Dynamic stencil read mask state not set for this command buffer");
4195 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004196 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004197}
4198
4199TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004200 TEST_DESCRIPTION(
4201 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4202 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004203
4204 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004205 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4207 "Dynamic stencil write mask state not set for this command buffer");
4208 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004209 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004210}
4211
4212TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004213 TEST_DESCRIPTION(
4214 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4215 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004216
4217 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004218 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4220 "Dynamic stencil reference state not set for this command buffer");
4221 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004222 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004223}
4224
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004225TEST_F(VkLayerTest, IndexBufferNotBound) {
4226 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004227
4228 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Index buffer object not bound to this command buffer when Indexed ");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004232 m_errorMonitor->VerifyFound();
4233}
4234
Karl Schultz6addd812016-02-02 17:17:23 -07004235TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4237 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4238 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004239
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004240 ASSERT_NO_FATAL_FAILURE(InitState());
4241 ASSERT_NO_FATAL_FAILURE(InitViewport());
4242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4243
Karl Schultz6addd812016-02-02 17:17:23 -07004244 // We luck out b/c by default the framework creates CB w/ the
4245 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004246 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004247 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004248 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 // Bypass framework since it does the waits automatically
4251 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004252 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4254 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004255 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004256 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004257 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004258 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004259 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004260 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004261 submit_info.pSignalSemaphores = NULL;
4262
Chris Forbes40028e22016-06-13 09:59:34 +12004263 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004264 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004265 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004266
Karl Schultz6addd812016-02-02 17:17:23 -07004267 // Cause validation error by re-submitting cmd buffer that should only be
4268 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004269 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004270 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004271
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004272 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004273}
4274
Karl Schultz6addd812016-02-02 17:17:23 -07004275TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004276 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004277 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278
4279 ASSERT_NO_FATAL_FAILURE(InitState());
4280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004281
Karl Schultz6addd812016-02-02 17:17:23 -07004282 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4283 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004284 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004285 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004287
4288 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004289 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4290 ds_pool_ci.pNext = NULL;
4291 ds_pool_ci.flags = 0;
4292 ds_pool_ci.maxSets = 1;
4293 ds_pool_ci.poolSizeCount = 1;
4294 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004295
4296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004298 ASSERT_VK_SUCCESS(err);
4299
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004300 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4301 dsl_binding_samp.binding = 0;
4302 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4303 dsl_binding_samp.descriptorCount = 1;
4304 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4305 dsl_binding_samp.pImmutableSamplers = NULL;
4306
4307 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4308 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4309 ds_layout_ci.pNext = NULL;
4310 ds_layout_ci.bindingCount = 1;
4311 ds_layout_ci.pBindings = &dsl_binding_samp;
4312
4313 VkDescriptorSetLayout ds_layout_samp;
4314 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4315 ASSERT_VK_SUCCESS(err);
4316
4317 // Try to allocate 2 sets when pool only has 1 set
4318 VkDescriptorSet descriptor_sets[2];
4319 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4320 VkDescriptorSetAllocateInfo alloc_info = {};
4321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4322 alloc_info.descriptorSetCount = 2;
4323 alloc_info.descriptorPool = ds_pool;
4324 alloc_info.pSetLayouts = set_layouts;
4325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4327 m_errorMonitor->VerifyFound();
4328
4329 alloc_info.descriptorSetCount = 1;
4330 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004332 dsl_binding.binding = 0;
4333 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4334 dsl_binding.descriptorCount = 1;
4335 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4336 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004337
Karl Schultz6addd812016-02-02 17:17:23 -07004338 ds_layout_ci.bindingCount = 1;
4339 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004340
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004341 VkDescriptorSetLayout ds_layout_ub;
4342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343 ASSERT_VK_SUCCESS(err);
4344
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004345 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004346 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004347 alloc_info.pSetLayouts = &ds_layout_ub;
4348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004351 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004352
Karl Schultz2825ab92016-12-02 08:23:14 -07004353 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004354 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004355 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004356}
4357
Karl Schultz6addd812016-02-02 17:17:23 -07004358TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4359 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004360
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004362
Tobin Ehlise735c692015-10-08 13:13:50 -06004363 ASSERT_NO_FATAL_FAILURE(InitState());
4364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004365
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004366 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004367 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4368 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004369
4370 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004371 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4372 ds_pool_ci.pNext = NULL;
4373 ds_pool_ci.maxSets = 1;
4374 ds_pool_ci.poolSizeCount = 1;
4375 ds_pool_ci.flags = 0;
4376 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4377 // app can only call vkResetDescriptorPool on this pool.;
4378 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004381 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004382 ASSERT_VK_SUCCESS(err);
4383
4384 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004385 dsl_binding.binding = 0;
4386 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4387 dsl_binding.descriptorCount = 1;
4388 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4389 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004390
4391 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004392 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4393 ds_layout_ci.pNext = NULL;
4394 ds_layout_ci.bindingCount = 1;
4395 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004396
4397 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004399 ASSERT_VK_SUCCESS(err);
4400
4401 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004402 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004403 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004404 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004405 alloc_info.descriptorPool = ds_pool;
4406 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004407 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004408 ASSERT_VK_SUCCESS(err);
4409
4410 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004411 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004412
Chia-I Wuf7458c52015-10-26 21:10:41 +08004413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004415}
4416
Karl Schultz6addd812016-02-02 17:17:23 -07004417TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004418 // Attempt to clear Descriptor Pool with bad object.
4419 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004420
4421 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004423 uint64_t fake_pool_handle = 0xbaad6001;
4424 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4425 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004426 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004427}
4428
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004429TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004430 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4431 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004432 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004433 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004434
4435 uint64_t fake_set_handle = 0xbaad6001;
4436 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004437 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004439
4440 ASSERT_NO_FATAL_FAILURE(InitState());
4441
4442 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4443 layout_bindings[0].binding = 0;
4444 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4445 layout_bindings[0].descriptorCount = 1;
4446 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4447 layout_bindings[0].pImmutableSamplers = NULL;
4448
4449 VkDescriptorSetLayout descriptor_set_layout;
4450 VkDescriptorSetLayoutCreateInfo dslci = {};
4451 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4452 dslci.pNext = NULL;
4453 dslci.bindingCount = 1;
4454 dslci.pBindings = layout_bindings;
4455 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004456 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004457
4458 VkPipelineLayout pipeline_layout;
4459 VkPipelineLayoutCreateInfo plci = {};
4460 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4461 plci.pNext = NULL;
4462 plci.setLayoutCount = 1;
4463 plci.pSetLayouts = &descriptor_set_layout;
4464 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004465 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004466
Tony Barbour552f6c02016-12-21 14:34:07 -07004467 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004468 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4469 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004470 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004471 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004472 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4473 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004474}
4475
Karl Schultz6addd812016-02-02 17:17:23 -07004476TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004477 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4478 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004479 uint64_t fake_layout_handle = 0xbaad6001;
4480 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004482 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004483 VkPipelineLayout pipeline_layout;
4484 VkPipelineLayoutCreateInfo plci = {};
4485 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4486 plci.pNext = NULL;
4487 plci.setLayoutCount = 1;
4488 plci.pSetLayouts = &bad_layout;
4489 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4490
4491 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004492}
4493
Mark Muellerd4914412016-06-13 17:52:06 -06004494TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004495 TEST_DESCRIPTION(
4496 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4497 "1) A uniform buffer update must have a valid buffer index."
4498 "2) When using an array of descriptors in a single WriteDescriptor,"
4499 " the descriptor types and stageflags must all be the same."
4500 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004501
Mike Weiblena6666382017-01-05 15:16:11 -07004502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004503
4504 ASSERT_NO_FATAL_FAILURE(InitState());
4505 VkDescriptorPoolSize ds_type_count[4] = {};
4506 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4507 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004508 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004509 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004510 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004511 ds_type_count[2].descriptorCount = 1;
4512 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4513 ds_type_count[3].descriptorCount = 1;
4514
4515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4517 ds_pool_ci.maxSets = 1;
4518 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4519 ds_pool_ci.pPoolSizes = ds_type_count;
4520
4521 VkDescriptorPool ds_pool;
4522 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4523 ASSERT_VK_SUCCESS(err);
4524
Mark Muellerb9896722016-06-16 09:54:29 -06004525 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004526 layout_binding[0].binding = 0;
4527 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4528 layout_binding[0].descriptorCount = 1;
4529 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4530 layout_binding[0].pImmutableSamplers = NULL;
4531
4532 layout_binding[1].binding = 1;
4533 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4534 layout_binding[1].descriptorCount = 1;
4535 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4536 layout_binding[1].pImmutableSamplers = NULL;
4537
4538 VkSamplerCreateInfo sampler_ci = {};
4539 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4540 sampler_ci.pNext = NULL;
4541 sampler_ci.magFilter = VK_FILTER_NEAREST;
4542 sampler_ci.minFilter = VK_FILTER_NEAREST;
4543 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4544 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4545 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4546 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4547 sampler_ci.mipLodBias = 1.0;
4548 sampler_ci.anisotropyEnable = VK_FALSE;
4549 sampler_ci.maxAnisotropy = 1;
4550 sampler_ci.compareEnable = VK_FALSE;
4551 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4552 sampler_ci.minLod = 1.0;
4553 sampler_ci.maxLod = 1.0;
4554 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4555 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4556 VkSampler sampler;
4557
4558 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4559 ASSERT_VK_SUCCESS(err);
4560
4561 layout_binding[2].binding = 2;
4562 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4563 layout_binding[2].descriptorCount = 1;
4564 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4565 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4566
Mark Muellerd4914412016-06-13 17:52:06 -06004567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4568 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4569 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4570 ds_layout_ci.pBindings = layout_binding;
4571 VkDescriptorSetLayout ds_layout;
4572 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 VkDescriptorSetAllocateInfo alloc_info = {};
4576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4577 alloc_info.descriptorSetCount = 1;
4578 alloc_info.descriptorPool = ds_pool;
4579 alloc_info.pSetLayouts = &ds_layout;
4580 VkDescriptorSet descriptorSet;
4581 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4582 ASSERT_VK_SUCCESS(err);
4583
4584 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4585 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4586 pipeline_layout_ci.pNext = NULL;
4587 pipeline_layout_ci.setLayoutCount = 1;
4588 pipeline_layout_ci.pSetLayouts = &ds_layout;
4589
4590 VkPipelineLayout pipeline_layout;
4591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4592 ASSERT_VK_SUCCESS(err);
4593
Mark Mueller5c838ce2016-06-16 09:54:29 -06004594 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004595 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4596 descriptor_write.dstSet = descriptorSet;
4597 descriptor_write.dstBinding = 0;
4598 descriptor_write.descriptorCount = 1;
4599 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4600
Mark Mueller5c838ce2016-06-16 09:54:29 -06004601 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004602 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4603 m_errorMonitor->VerifyFound();
4604
4605 // Create a buffer to update the descriptor with
4606 uint32_t qfi = 0;
4607 VkBufferCreateInfo buffCI = {};
4608 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4609 buffCI.size = 1024;
4610 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4611 buffCI.queueFamilyIndexCount = 1;
4612 buffCI.pQueueFamilyIndices = &qfi;
4613
4614 VkBuffer dyub;
4615 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4616 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004617
Tony Barboure132c5f2016-12-12 11:50:20 -07004618 VkDeviceMemory mem;
4619 VkMemoryRequirements mem_reqs;
4620 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4621
4622 VkMemoryAllocateInfo mem_alloc_info = {};
4623 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4624 mem_alloc_info.allocationSize = mem_reqs.size;
4625 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4626 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4627 ASSERT_VK_SUCCESS(err);
4628
4629 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4630 ASSERT_VK_SUCCESS(err);
4631
4632 VkDescriptorBufferInfo buffInfo[2] = {};
4633 buffInfo[0].buffer = dyub;
4634 buffInfo[0].offset = 0;
4635 buffInfo[0].range = 1024;
4636 buffInfo[1].buffer = dyub;
4637 buffInfo[1].offset = 0;
4638 buffInfo[1].range = 1024;
4639 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004640 descriptor_write.descriptorCount = 2;
4641
Mark Mueller5c838ce2016-06-16 09:54:29 -06004642 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4645 m_errorMonitor->VerifyFound();
4646
Mark Mueller5c838ce2016-06-16 09:54:29 -06004647 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4648 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004649 descriptor_write.dstBinding = 1;
4650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // Make pImageInfo index non-null to avoid complaints of it missing
4653 VkDescriptorImageInfo imageInfo = {};
4654 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4655 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4658 m_errorMonitor->VerifyFound();
4659
Mark Muellerd4914412016-06-13 17:52:06 -06004660 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004661 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004662 vkDestroySampler(m_device->device(), sampler, NULL);
4663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4664 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4665 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4666}
4667
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004668TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004669 TEST_DESCRIPTION(
4670 "Attempt to draw with a command buffer that is invalid "
4671 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004672 ASSERT_NO_FATAL_FAILURE(InitState());
4673
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004674 VkBuffer buffer;
4675 VkDeviceMemory mem;
4676 VkMemoryRequirements mem_reqs;
4677
4678 VkBufferCreateInfo buf_info = {};
4679 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004680 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004681 buf_info.size = 256;
4682 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4683 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4684 ASSERT_VK_SUCCESS(err);
4685
4686 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4687
4688 VkMemoryAllocateInfo alloc_info = {};
4689 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4690 alloc_info.allocationSize = 256;
4691 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004692 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004693 if (!pass) {
4694 vkDestroyBuffer(m_device->device(), buffer, NULL);
4695 return;
4696 }
4697 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4698 ASSERT_VK_SUCCESS(err);
4699
4700 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004703 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004704 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004705 m_commandBuffer->EndCommandBuffer();
4706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004708 // Destroy buffer dependency prior to submit to cause ERROR
4709 vkDestroyBuffer(m_device->device(), buffer, NULL);
4710
4711 VkSubmitInfo submit_info = {};
4712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4713 submit_info.commandBufferCount = 1;
4714 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4715 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4716
4717 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004718 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004719 vkFreeMemory(m_device->handle(), mem, NULL);
4720}
4721
Tobin Ehlisea413442016-09-28 10:23:59 -06004722TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4723 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4724
4725 ASSERT_NO_FATAL_FAILURE(InitState());
4726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4727
4728 VkDescriptorPoolSize ds_type_count;
4729 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4730 ds_type_count.descriptorCount = 1;
4731
4732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4734 ds_pool_ci.maxSets = 1;
4735 ds_pool_ci.poolSizeCount = 1;
4736 ds_pool_ci.pPoolSizes = &ds_type_count;
4737
4738 VkDescriptorPool ds_pool;
4739 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4740 ASSERT_VK_SUCCESS(err);
4741
4742 VkDescriptorSetLayoutBinding layout_binding;
4743 layout_binding.binding = 0;
4744 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4745 layout_binding.descriptorCount = 1;
4746 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4747 layout_binding.pImmutableSamplers = NULL;
4748
4749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4751 ds_layout_ci.bindingCount = 1;
4752 ds_layout_ci.pBindings = &layout_binding;
4753 VkDescriptorSetLayout ds_layout;
4754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkDescriptorSetAllocateInfo alloc_info = {};
4758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4759 alloc_info.descriptorSetCount = 1;
4760 alloc_info.descriptorPool = ds_pool;
4761 alloc_info.pSetLayouts = &ds_layout;
4762 VkDescriptorSet descriptor_set;
4763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4764 ASSERT_VK_SUCCESS(err);
4765
4766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4768 pipeline_layout_ci.pNext = NULL;
4769 pipeline_layout_ci.setLayoutCount = 1;
4770 pipeline_layout_ci.pSetLayouts = &ds_layout;
4771
4772 VkPipelineLayout pipeline_layout;
4773 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkBuffer buffer;
4777 uint32_t queue_family_index = 0;
4778 VkBufferCreateInfo buffer_create_info = {};
4779 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4780 buffer_create_info.size = 1024;
4781 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4782 buffer_create_info.queueFamilyIndexCount = 1;
4783 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4784
4785 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4786 ASSERT_VK_SUCCESS(err);
4787
4788 VkMemoryRequirements memory_reqs;
4789 VkDeviceMemory buffer_memory;
4790
4791 VkMemoryAllocateInfo memory_info = {};
4792 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4793 memory_info.allocationSize = 0;
4794 memory_info.memoryTypeIndex = 0;
4795
4796 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4797 memory_info.allocationSize = memory_reqs.size;
4798 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4799 ASSERT_TRUE(pass);
4800
4801 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4802 ASSERT_VK_SUCCESS(err);
4803 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4804 ASSERT_VK_SUCCESS(err);
4805
4806 VkBufferView view;
4807 VkBufferViewCreateInfo bvci = {};
4808 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4809 bvci.buffer = buffer;
4810 bvci.format = VK_FORMAT_R8_UNORM;
4811 bvci.range = VK_WHOLE_SIZE;
4812
4813 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkWriteDescriptorSet descriptor_write = {};
4817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4818 descriptor_write.dstSet = descriptor_set;
4819 descriptor_write.dstBinding = 0;
4820 descriptor_write.descriptorCount = 1;
4821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4822 descriptor_write.pTexelBufferView = &view;
4823
4824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004826 char const *vsSource =
4827 "#version 450\n"
4828 "\n"
4829 "out gl_PerVertex { \n"
4830 " vec4 gl_Position;\n"
4831 "};\n"
4832 "void main(){\n"
4833 " gl_Position = vec4(1);\n"
4834 "}\n";
4835 char const *fsSource =
4836 "#version 450\n"
4837 "\n"
4838 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4839 "layout(location=0) out vec4 x;\n"
4840 "void main(){\n"
4841 " x = imageLoad(s, 0);\n"
4842 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004843 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4844 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4845 VkPipelineObj pipe(m_device);
4846 pipe.AddShader(&vs);
4847 pipe.AddShader(&fs);
4848 pipe.AddColorAttachment();
4849 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4850
Tobin Ehlisea413442016-09-28 10:23:59 -06004851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4852
Tony Barbour552f6c02016-12-21 14:34:07 -07004853 m_commandBuffer->BeginCommandBuffer();
4854 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4855
Tobin Ehlisea413442016-09-28 10:23:59 -06004856 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4857 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4858 VkRect2D scissor = {{0, 0}, {16, 16}};
4859 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4860 // Bind pipeline to cmd buffer
4861 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4862 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4863 &descriptor_set, 0, nullptr);
4864 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004865 m_commandBuffer->EndRenderPass();
4866 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004867
4868 // Delete BufferView in order to invalidate cmd buffer
4869 vkDestroyBufferView(m_device->device(), view, NULL);
4870 // Now attempt submit of cmd buffer
4871 VkSubmitInfo submit_info = {};
4872 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4873 submit_info.commandBufferCount = 1;
4874 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4876 m_errorMonitor->VerifyFound();
4877
4878 // Clean-up
4879 vkDestroyBuffer(m_device->device(), buffer, NULL);
4880 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4884}
4885
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004886TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004887 TEST_DESCRIPTION(
4888 "Attempt to draw with a command buffer that is invalid "
4889 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004890 ASSERT_NO_FATAL_FAILURE(InitState());
4891
4892 VkImage image;
4893 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4894 VkImageCreateInfo image_create_info = {};
4895 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4896 image_create_info.pNext = NULL;
4897 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4898 image_create_info.format = tex_format;
4899 image_create_info.extent.width = 32;
4900 image_create_info.extent.height = 32;
4901 image_create_info.extent.depth = 1;
4902 image_create_info.mipLevels = 1;
4903 image_create_info.arrayLayers = 1;
4904 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4905 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004906 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004907 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004909 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004910 // Have to bind memory to image before recording cmd in cmd buffer using it
4911 VkMemoryRequirements mem_reqs;
4912 VkDeviceMemory image_mem;
4913 bool pass;
4914 VkMemoryAllocateInfo mem_alloc = {};
4915 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4916 mem_alloc.pNext = NULL;
4917 mem_alloc.memoryTypeIndex = 0;
4918 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4919 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004920 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004921 ASSERT_TRUE(pass);
4922 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4923 ASSERT_VK_SUCCESS(err);
4924 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4925 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004926
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004927 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004928 VkClearColorValue ccv;
4929 ccv.float32[0] = 1.0f;
4930 ccv.float32[1] = 1.0f;
4931 ccv.float32[2] = 1.0f;
4932 ccv.float32[3] = 1.0f;
4933 VkImageSubresourceRange isr = {};
4934 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004935 isr.baseArrayLayer = 0;
4936 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004937 isr.layerCount = 1;
4938 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004939 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004940 m_commandBuffer->EndCommandBuffer();
4941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004943 // Destroy image dependency prior to submit to cause ERROR
4944 vkDestroyImage(m_device->device(), image, NULL);
4945
4946 VkSubmitInfo submit_info = {};
4947 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4948 submit_info.commandBufferCount = 1;
4949 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4951
4952 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004953 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004954}
4955
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004956TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004957 TEST_DESCRIPTION(
4958 "Attempt to draw with a command buffer that is invalid "
4959 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004960 VkFormatProperties format_properties;
4961 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4963 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004964 return;
4965 }
4966
4967 ASSERT_NO_FATAL_FAILURE(InitState());
4968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4969
4970 VkImageCreateInfo image_ci = {};
4971 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4972 image_ci.pNext = NULL;
4973 image_ci.imageType = VK_IMAGE_TYPE_2D;
4974 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4975 image_ci.extent.width = 32;
4976 image_ci.extent.height = 32;
4977 image_ci.extent.depth = 1;
4978 image_ci.mipLevels = 1;
4979 image_ci.arrayLayers = 1;
4980 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4981 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004983 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4984 image_ci.flags = 0;
4985 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004987
4988 VkMemoryRequirements memory_reqs;
4989 VkDeviceMemory image_memory;
4990 bool pass;
4991 VkMemoryAllocateInfo memory_info = {};
4992 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4993 memory_info.pNext = NULL;
4994 memory_info.allocationSize = 0;
4995 memory_info.memoryTypeIndex = 0;
4996 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4997 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004999 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005000 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005001 ASSERT_VK_SUCCESS(err);
5002 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5003 ASSERT_VK_SUCCESS(err);
5004
5005 VkImageViewCreateInfo ivci = {
5006 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5007 nullptr,
5008 0,
5009 image,
5010 VK_IMAGE_VIEW_TYPE_2D,
5011 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005012 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005013 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5014 };
5015 VkImageView view;
5016 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5017 ASSERT_VK_SUCCESS(err);
5018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005020 VkFramebuffer fb;
5021 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5022 ASSERT_VK_SUCCESS(err);
5023
5024 // Just use default renderpass with our framebuffer
5025 m_renderPassBeginInfo.framebuffer = fb;
5026 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005027 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005028 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07005029 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5030 m_commandBuffer->EndRenderPass();
5031 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005032 // Destroy image attached to framebuffer to invalidate cmd buffer
5033 vkDestroyImage(m_device->device(), image, NULL);
5034 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005036 QueueCommandBuffer(false);
5037 m_errorMonitor->VerifyFound();
5038
5039 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5040 vkDestroyImageView(m_device->device(), view, nullptr);
5041 vkFreeMemory(m_device->device(), image_memory, nullptr);
5042}
5043
Tobin Ehlisb329f992016-10-12 13:20:29 -06005044TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5045 TEST_DESCRIPTION("Delete in-use framebuffer.");
5046 VkFormatProperties format_properties;
5047 VkResult err = VK_SUCCESS;
5048 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5049
5050 ASSERT_NO_FATAL_FAILURE(InitState());
5051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5052
5053 VkImageObj image(m_device);
5054 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5055 ASSERT_TRUE(image.initialized());
5056 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5057
5058 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5059 VkFramebuffer fb;
5060 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5061 ASSERT_VK_SUCCESS(err);
5062
5063 // Just use default renderpass with our framebuffer
5064 m_renderPassBeginInfo.framebuffer = fb;
5065 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005066 m_commandBuffer->BeginCommandBuffer();
5067 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5068 m_commandBuffer->EndRenderPass();
5069 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005070 // Submit cmd buffer to put it in-flight
5071 VkSubmitInfo submit_info = {};
5072 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5073 submit_info.commandBufferCount = 1;
5074 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5075 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5076 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005078 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5079 m_errorMonitor->VerifyFound();
5080 // Wait for queue to complete so we can safely destroy everything
5081 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005082 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5083 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005084 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5085}
5086
Tobin Ehlis88becd72016-09-21 14:33:41 -06005087TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5088 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5089 VkFormatProperties format_properties;
5090 VkResult err = VK_SUCCESS;
5091 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005092
5093 ASSERT_NO_FATAL_FAILURE(InitState());
5094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5095
5096 VkImageCreateInfo image_ci = {};
5097 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5098 image_ci.pNext = NULL;
5099 image_ci.imageType = VK_IMAGE_TYPE_2D;
5100 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5101 image_ci.extent.width = 256;
5102 image_ci.extent.height = 256;
5103 image_ci.extent.depth = 1;
5104 image_ci.mipLevels = 1;
5105 image_ci.arrayLayers = 1;
5106 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5107 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005108 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005109 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5110 image_ci.flags = 0;
5111 VkImage image;
5112 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5113
5114 VkMemoryRequirements memory_reqs;
5115 VkDeviceMemory image_memory;
5116 bool pass;
5117 VkMemoryAllocateInfo memory_info = {};
5118 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5119 memory_info.pNext = NULL;
5120 memory_info.allocationSize = 0;
5121 memory_info.memoryTypeIndex = 0;
5122 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5123 memory_info.allocationSize = memory_reqs.size;
5124 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5125 ASSERT_TRUE(pass);
5126 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5127 ASSERT_VK_SUCCESS(err);
5128 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5129 ASSERT_VK_SUCCESS(err);
5130
5131 VkImageViewCreateInfo ivci = {
5132 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5133 nullptr,
5134 0,
5135 image,
5136 VK_IMAGE_VIEW_TYPE_2D,
5137 VK_FORMAT_B8G8R8A8_UNORM,
5138 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5139 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5140 };
5141 VkImageView view;
5142 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5143 ASSERT_VK_SUCCESS(err);
5144
5145 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5146 VkFramebuffer fb;
5147 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5148 ASSERT_VK_SUCCESS(err);
5149
5150 // Just use default renderpass with our framebuffer
5151 m_renderPassBeginInfo.framebuffer = fb;
5152 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005153 m_commandBuffer->BeginCommandBuffer();
5154 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5155 m_commandBuffer->EndRenderPass();
5156 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 // Submit cmd buffer to put it (and attached imageView) in-flight
5158 VkSubmitInfo submit_info = {};
5159 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5160 submit_info.commandBufferCount = 1;
5161 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5162 // Submit cmd buffer to put framebuffer and children in-flight
5163 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5164 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005166 vkDestroyImage(m_device->device(), image, NULL);
5167 m_errorMonitor->VerifyFound();
5168 // Wait for queue to complete so we can safely destroy image and other objects
5169 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005170 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5171 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005172 vkDestroyImage(m_device->device(), image, NULL);
5173 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5174 vkDestroyImageView(m_device->device(), view, nullptr);
5175 vkFreeMemory(m_device->device(), image_memory, nullptr);
5176}
5177
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005178TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5179 TEST_DESCRIPTION("Delete in-use renderPass.");
5180
5181 ASSERT_NO_FATAL_FAILURE(InitState());
5182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5183
5184 // Create simple renderpass
5185 VkAttachmentReference attach = {};
5186 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5187 VkSubpassDescription subpass = {};
5188 subpass.pColorAttachments = &attach;
5189 VkRenderPassCreateInfo rpci = {};
5190 rpci.subpassCount = 1;
5191 rpci.pSubpasses = &subpass;
5192 rpci.attachmentCount = 1;
5193 VkAttachmentDescription attach_desc = {};
5194 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5195 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5196 rpci.pAttachments = &attach_desc;
5197 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5198 VkRenderPass rp;
5199 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5200 ASSERT_VK_SUCCESS(err);
5201
5202 // Create a pipeline that uses the given renderpass
5203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5205
5206 VkPipelineLayout pipeline_layout;
5207 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5208 ASSERT_VK_SUCCESS(err);
5209
5210 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5211 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5212 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005213 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005214 vp_state_ci.pViewports = &vp;
5215 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005216 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005217 vp_state_ci.pScissors = &scissors;
5218
5219 VkPipelineShaderStageCreateInfo shaderStages[2];
5220 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5221
5222 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005223 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 -06005224 // but add it to be able to run on more devices
5225 shaderStages[0] = vs.GetStageCreateInfo();
5226 shaderStages[1] = fs.GetStageCreateInfo();
5227
5228 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5229 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5230
5231 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5232 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5233 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5234
5235 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5236 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5237 rs_ci.rasterizerDiscardEnable = true;
5238 rs_ci.lineWidth = 1.0f;
5239
5240 VkPipelineColorBlendAttachmentState att = {};
5241 att.blendEnable = VK_FALSE;
5242 att.colorWriteMask = 0xf;
5243
5244 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5245 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5246 cb_ci.attachmentCount = 1;
5247 cb_ci.pAttachments = &att;
5248
5249 VkGraphicsPipelineCreateInfo gp_ci = {};
5250 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5251 gp_ci.stageCount = 2;
5252 gp_ci.pStages = shaderStages;
5253 gp_ci.pVertexInputState = &vi_ci;
5254 gp_ci.pInputAssemblyState = &ia_ci;
5255 gp_ci.pViewportState = &vp_state_ci;
5256 gp_ci.pRasterizationState = &rs_ci;
5257 gp_ci.pColorBlendState = &cb_ci;
5258 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5259 gp_ci.layout = pipeline_layout;
5260 gp_ci.renderPass = rp;
5261
5262 VkPipelineCacheCreateInfo pc_ci = {};
5263 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5264
5265 VkPipeline pipeline;
5266 VkPipelineCache pipe_cache;
5267 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5268 ASSERT_VK_SUCCESS(err);
5269
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005270 m_errorMonitor->SetUnexpectedError(
5271 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5272 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005273 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5274 ASSERT_VK_SUCCESS(err);
5275 // Bind pipeline to cmd buffer, will also bind renderpass
5276 m_commandBuffer->BeginCommandBuffer();
5277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5278 m_commandBuffer->EndCommandBuffer();
5279
5280 VkSubmitInfo submit_info = {};
5281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5282 submit_info.commandBufferCount = 1;
5283 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5284 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5285
5286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5287 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5288 m_errorMonitor->VerifyFound();
5289
5290 // Wait for queue to complete so we can safely destroy everything
5291 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005292 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5293 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005294 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5295 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5296 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5298}
5299
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005300TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005301 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005302 ASSERT_NO_FATAL_FAILURE(InitState());
5303
5304 VkImage image;
5305 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5306 VkImageCreateInfo image_create_info = {};
5307 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5308 image_create_info.pNext = NULL;
5309 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5310 image_create_info.format = tex_format;
5311 image_create_info.extent.width = 32;
5312 image_create_info.extent.height = 32;
5313 image_create_info.extent.depth = 1;
5314 image_create_info.mipLevels = 1;
5315 image_create_info.arrayLayers = 1;
5316 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5317 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005318 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005319 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005321 ASSERT_VK_SUCCESS(err);
5322 // Have to bind memory to image before recording cmd in cmd buffer using it
5323 VkMemoryRequirements mem_reqs;
5324 VkDeviceMemory image_mem;
5325 bool pass;
5326 VkMemoryAllocateInfo mem_alloc = {};
5327 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5328 mem_alloc.pNext = NULL;
5329 mem_alloc.memoryTypeIndex = 0;
5330 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5331 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005332 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005333 ASSERT_TRUE(pass);
5334 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5335 ASSERT_VK_SUCCESS(err);
5336
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005337 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005339 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005340
5341 m_commandBuffer->BeginCommandBuffer();
5342 VkClearColorValue ccv;
5343 ccv.float32[0] = 1.0f;
5344 ccv.float32[1] = 1.0f;
5345 ccv.float32[2] = 1.0f;
5346 ccv.float32[3] = 1.0f;
5347 VkImageSubresourceRange isr = {};
5348 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5349 isr.baseArrayLayer = 0;
5350 isr.baseMipLevel = 0;
5351 isr.layerCount = 1;
5352 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005353 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005354 m_commandBuffer->EndCommandBuffer();
5355
5356 m_errorMonitor->VerifyFound();
5357 vkDestroyImage(m_device->device(), image, NULL);
5358 vkFreeMemory(m_device->device(), image_mem, nullptr);
5359}
5360
5361TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005362 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005363 ASSERT_NO_FATAL_FAILURE(InitState());
5364
5365 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005366 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 -06005367 VK_IMAGE_TILING_OPTIMAL, 0);
5368 ASSERT_TRUE(image.initialized());
5369
5370 VkBuffer buffer;
5371 VkDeviceMemory mem;
5372 VkMemoryRequirements mem_reqs;
5373
5374 VkBufferCreateInfo buf_info = {};
5375 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005376 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005377 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5379 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5380 ASSERT_VK_SUCCESS(err);
5381
5382 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5383
5384 VkMemoryAllocateInfo alloc_info = {};
5385 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005386 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005387 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005388 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 -06005389 if (!pass) {
5390 vkDestroyBuffer(m_device->device(), buffer, NULL);
5391 return;
5392 }
5393 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5394 ASSERT_VK_SUCCESS(err);
5395
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005396 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005398 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005399 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005400 region.bufferRowLength = 16;
5401 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005402 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5403
5404 region.imageSubresource.layerCount = 1;
5405 region.imageExtent.height = 4;
5406 region.imageExtent.width = 4;
5407 region.imageExtent.depth = 1;
5408 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005409 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5410 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005411 m_commandBuffer->EndCommandBuffer();
5412
5413 m_errorMonitor->VerifyFound();
5414
5415 vkDestroyBuffer(m_device->device(), buffer, NULL);
5416 vkFreeMemory(m_device->handle(), mem, NULL);
5417}
5418
Tobin Ehlis85940f52016-07-07 16:57:21 -06005419TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005420 TEST_DESCRIPTION(
5421 "Attempt to draw with a command buffer that is invalid "
5422 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005423 ASSERT_NO_FATAL_FAILURE(InitState());
5424
5425 VkEvent event;
5426 VkEventCreateInfo evci = {};
5427 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5428 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5429 ASSERT_VK_SUCCESS(result);
5430
5431 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005432 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005433 m_commandBuffer->EndCommandBuffer();
5434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005436 // Destroy event dependency prior to submit to cause ERROR
5437 vkDestroyEvent(m_device->device(), event, NULL);
5438
5439 VkSubmitInfo submit_info = {};
5440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5441 submit_info.commandBufferCount = 1;
5442 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5443 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5444
5445 m_errorMonitor->VerifyFound();
5446}
5447
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005448TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005449 TEST_DESCRIPTION(
5450 "Attempt to draw with a command buffer that is invalid "
5451 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005452 ASSERT_NO_FATAL_FAILURE(InitState());
5453
5454 VkQueryPool query_pool;
5455 VkQueryPoolCreateInfo qpci{};
5456 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5457 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5458 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005459 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005460 ASSERT_VK_SUCCESS(result);
5461
5462 m_commandBuffer->BeginCommandBuffer();
5463 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5464 m_commandBuffer->EndCommandBuffer();
5465
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005467 // Destroy query pool dependency prior to submit to cause ERROR
5468 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5469
5470 VkSubmitInfo submit_info = {};
5471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5472 submit_info.commandBufferCount = 1;
5473 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5474 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5475
5476 m_errorMonitor->VerifyFound();
5477}
5478
Tobin Ehlis24130d92016-07-08 15:50:53 -06005479TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005480 TEST_DESCRIPTION(
5481 "Attempt to draw with a command buffer that is invalid "
5482 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005483 ASSERT_NO_FATAL_FAILURE(InitState());
5484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5485
5486 VkResult err;
5487
5488 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5489 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5490
5491 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005492 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493 ASSERT_VK_SUCCESS(err);
5494
5495 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5496 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5497 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005498 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005499 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005500 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005501 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005502 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005503
5504 VkPipelineShaderStageCreateInfo shaderStages[2];
5505 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5506
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005508 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 -06005509 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005510 shaderStages[0] = vs.GetStageCreateInfo();
5511 shaderStages[1] = fs.GetStageCreateInfo();
5512
5513 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5514 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5515
5516 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5517 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5518 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5519
5520 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5521 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005522 rs_ci.rasterizerDiscardEnable = true;
5523 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005524
5525 VkPipelineColorBlendAttachmentState att = {};
5526 att.blendEnable = VK_FALSE;
5527 att.colorWriteMask = 0xf;
5528
5529 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5530 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5531 cb_ci.attachmentCount = 1;
5532 cb_ci.pAttachments = &att;
5533
5534 VkGraphicsPipelineCreateInfo gp_ci = {};
5535 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5536 gp_ci.stageCount = 2;
5537 gp_ci.pStages = shaderStages;
5538 gp_ci.pVertexInputState = &vi_ci;
5539 gp_ci.pInputAssemblyState = &ia_ci;
5540 gp_ci.pViewportState = &vp_state_ci;
5541 gp_ci.pRasterizationState = &rs_ci;
5542 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005543 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5544 gp_ci.layout = pipeline_layout;
5545 gp_ci.renderPass = renderPass();
5546
5547 VkPipelineCacheCreateInfo pc_ci = {};
5548 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5549
5550 VkPipeline pipeline;
5551 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005552 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005553 ASSERT_VK_SUCCESS(err);
5554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005556 ASSERT_VK_SUCCESS(err);
5557
5558 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005559 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005560 m_commandBuffer->EndCommandBuffer();
5561 // Now destroy pipeline in order to cause error when submitting
5562 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005565
5566 VkSubmitInfo submit_info = {};
5567 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5568 submit_info.commandBufferCount = 1;
5569 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5571
5572 m_errorMonitor->VerifyFound();
5573 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5575}
5576
Tobin Ehlis31289162016-08-17 14:57:58 -06005577TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005578 TEST_DESCRIPTION(
5579 "Attempt to draw with a command buffer that is invalid "
5580 "due to a bound descriptor set with a buffer dependency "
5581 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005582 ASSERT_NO_FATAL_FAILURE(InitState());
5583 ASSERT_NO_FATAL_FAILURE(InitViewport());
5584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5585
5586 VkDescriptorPoolSize ds_type_count = {};
5587 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5588 ds_type_count.descriptorCount = 1;
5589
5590 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5591 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5592 ds_pool_ci.pNext = NULL;
5593 ds_pool_ci.maxSets = 1;
5594 ds_pool_ci.poolSizeCount = 1;
5595 ds_pool_ci.pPoolSizes = &ds_type_count;
5596
5597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005598 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005599 ASSERT_VK_SUCCESS(err);
5600
5601 VkDescriptorSetLayoutBinding dsl_binding = {};
5602 dsl_binding.binding = 0;
5603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5604 dsl_binding.descriptorCount = 1;
5605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5606 dsl_binding.pImmutableSamplers = NULL;
5607
5608 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5609 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5610 ds_layout_ci.pNext = NULL;
5611 ds_layout_ci.bindingCount = 1;
5612 ds_layout_ci.pBindings = &dsl_binding;
5613 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 VkDescriptorSet descriptorSet;
5618 VkDescriptorSetAllocateInfo alloc_info = {};
5619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5620 alloc_info.descriptorSetCount = 1;
5621 alloc_info.descriptorPool = ds_pool;
5622 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005623 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005624 ASSERT_VK_SUCCESS(err);
5625
5626 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5627 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5628 pipeline_layout_ci.pNext = NULL;
5629 pipeline_layout_ci.setLayoutCount = 1;
5630 pipeline_layout_ci.pSetLayouts = &ds_layout;
5631
5632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005634 ASSERT_VK_SUCCESS(err);
5635
5636 // Create a buffer to update the descriptor with
5637 uint32_t qfi = 0;
5638 VkBufferCreateInfo buffCI = {};
5639 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5640 buffCI.size = 1024;
5641 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5642 buffCI.queueFamilyIndexCount = 1;
5643 buffCI.pQueueFamilyIndices = &qfi;
5644
5645 VkBuffer buffer;
5646 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5647 ASSERT_VK_SUCCESS(err);
5648 // Allocate memory and bind to buffer so we can make it to the appropriate
5649 // error
5650 VkMemoryAllocateInfo mem_alloc = {};
5651 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5652 mem_alloc.pNext = NULL;
5653 mem_alloc.allocationSize = 1024;
5654 mem_alloc.memoryTypeIndex = 0;
5655
5656 VkMemoryRequirements memReqs;
5657 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005658 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005659 if (!pass) {
5660 vkDestroyBuffer(m_device->device(), buffer, NULL);
5661 return;
5662 }
5663
5664 VkDeviceMemory mem;
5665 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5666 ASSERT_VK_SUCCESS(err);
5667 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5668 ASSERT_VK_SUCCESS(err);
5669 // Correctly update descriptor to avoid "NOT_UPDATED" error
5670 VkDescriptorBufferInfo buffInfo = {};
5671 buffInfo.buffer = buffer;
5672 buffInfo.offset = 0;
5673 buffInfo.range = 1024;
5674
5675 VkWriteDescriptorSet descriptor_write;
5676 memset(&descriptor_write, 0, sizeof(descriptor_write));
5677 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5678 descriptor_write.dstSet = descriptorSet;
5679 descriptor_write.dstBinding = 0;
5680 descriptor_write.descriptorCount = 1;
5681 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5682 descriptor_write.pBufferInfo = &buffInfo;
5683
5684 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5685
5686 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005687 char const *vsSource =
5688 "#version 450\n"
5689 "\n"
5690 "out gl_PerVertex { \n"
5691 " vec4 gl_Position;\n"
5692 "};\n"
5693 "void main(){\n"
5694 " gl_Position = vec4(1);\n"
5695 "}\n";
5696 char const *fsSource =
5697 "#version 450\n"
5698 "\n"
5699 "layout(location=0) out vec4 x;\n"
5700 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5701 "void main(){\n"
5702 " x = vec4(bar.y);\n"
5703 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5706 VkPipelineObj pipe(m_device);
5707 pipe.AddShader(&vs);
5708 pipe.AddShader(&fs);
5709 pipe.AddColorAttachment();
5710 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5711
Tony Barbour552f6c02016-12-21 14:34:07 -07005712 m_commandBuffer->BeginCommandBuffer();
5713 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5716 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005717
5718 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5719 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5720
Tobin Ehlis31289162016-08-17 14:57:58 -06005721 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005722 m_commandBuffer->EndRenderPass();
5723 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005725 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5726 vkDestroyBuffer(m_device->device(), buffer, NULL);
5727 // Attempt to submit cmd buffer
5728 VkSubmitInfo submit_info = {};
5729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5730 submit_info.commandBufferCount = 1;
5731 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5732 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5733 m_errorMonitor->VerifyFound();
5734 // Cleanup
5735 vkFreeMemory(m_device->device(), mem, NULL);
5736
5737 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5738 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5739 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5740}
5741
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005742TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005743 TEST_DESCRIPTION(
5744 "Attempt to draw with a command buffer that is invalid "
5745 "due to a bound descriptor sets with a combined image "
5746 "sampler having their image, sampler, and descriptor set "
5747 "each respectively destroyed and then attempting to "
5748 "submit associated cmd buffers. Attempt to destroy a "
5749 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005750 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005751 ASSERT_NO_FATAL_FAILURE(InitViewport());
5752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5753
5754 VkDescriptorPoolSize ds_type_count = {};
5755 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5756 ds_type_count.descriptorCount = 1;
5757
5758 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5759 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5760 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005761 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ds_pool_ci.maxSets = 1;
5763 ds_pool_ci.poolSizeCount = 1;
5764 ds_pool_ci.pPoolSizes = &ds_type_count;
5765
5766 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005767 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005768 ASSERT_VK_SUCCESS(err);
5769
5770 VkDescriptorSetLayoutBinding dsl_binding = {};
5771 dsl_binding.binding = 0;
5772 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5773 dsl_binding.descriptorCount = 1;
5774 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5775 dsl_binding.pImmutableSamplers = NULL;
5776
5777 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5778 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5779 ds_layout_ci.pNext = NULL;
5780 ds_layout_ci.bindingCount = 1;
5781 ds_layout_ci.pBindings = &dsl_binding;
5782 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkDescriptorSet descriptorSet;
5787 VkDescriptorSetAllocateInfo alloc_info = {};
5788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5789 alloc_info.descriptorSetCount = 1;
5790 alloc_info.descriptorPool = ds_pool;
5791 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005793 ASSERT_VK_SUCCESS(err);
5794
5795 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5796 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5797 pipeline_layout_ci.pNext = NULL;
5798 pipeline_layout_ci.setLayoutCount = 1;
5799 pipeline_layout_ci.pSetLayouts = &ds_layout;
5800
5801 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005802 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005803 ASSERT_VK_SUCCESS(err);
5804
5805 // Create images to update the descriptor with
5806 VkImage image;
5807 VkImage image2;
5808 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5809 const int32_t tex_width = 32;
5810 const int32_t tex_height = 32;
5811 VkImageCreateInfo image_create_info = {};
5812 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5813 image_create_info.pNext = NULL;
5814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5815 image_create_info.format = tex_format;
5816 image_create_info.extent.width = tex_width;
5817 image_create_info.extent.height = tex_height;
5818 image_create_info.extent.depth = 1;
5819 image_create_info.mipLevels = 1;
5820 image_create_info.arrayLayers = 1;
5821 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5822 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5823 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5824 image_create_info.flags = 0;
5825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5826 ASSERT_VK_SUCCESS(err);
5827 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5828 ASSERT_VK_SUCCESS(err);
5829
5830 VkMemoryRequirements memory_reqs;
5831 VkDeviceMemory image_memory;
5832 bool pass;
5833 VkMemoryAllocateInfo memory_info = {};
5834 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5835 memory_info.pNext = NULL;
5836 memory_info.allocationSize = 0;
5837 memory_info.memoryTypeIndex = 0;
5838 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5839 // Allocate enough memory for both images
5840 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005841 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005842 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005843 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005844 ASSERT_VK_SUCCESS(err);
5845 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5846 ASSERT_VK_SUCCESS(err);
5847 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005848 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005849 ASSERT_VK_SUCCESS(err);
5850
5851 VkImageViewCreateInfo image_view_create_info = {};
5852 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5853 image_view_create_info.image = image;
5854 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5855 image_view_create_info.format = tex_format;
5856 image_view_create_info.subresourceRange.layerCount = 1;
5857 image_view_create_info.subresourceRange.baseMipLevel = 0;
5858 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860
5861 VkImageView view;
5862 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005863 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005864 ASSERT_VK_SUCCESS(err);
5865 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005867 ASSERT_VK_SUCCESS(err);
5868 // Create Samplers
5869 VkSamplerCreateInfo sampler_ci = {};
5870 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5871 sampler_ci.pNext = NULL;
5872 sampler_ci.magFilter = VK_FILTER_NEAREST;
5873 sampler_ci.minFilter = VK_FILTER_NEAREST;
5874 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5875 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5876 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5877 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5878 sampler_ci.mipLodBias = 1.0;
5879 sampler_ci.anisotropyEnable = VK_FALSE;
5880 sampler_ci.maxAnisotropy = 1;
5881 sampler_ci.compareEnable = VK_FALSE;
5882 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5883 sampler_ci.minLod = 1.0;
5884 sampler_ci.maxLod = 1.0;
5885 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5886 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5887 VkSampler sampler;
5888 VkSampler sampler2;
5889 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5890 ASSERT_VK_SUCCESS(err);
5891 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5892 ASSERT_VK_SUCCESS(err);
5893 // Update descriptor with image and sampler
5894 VkDescriptorImageInfo img_info = {};
5895 img_info.sampler = sampler;
5896 img_info.imageView = view;
5897 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5898
5899 VkWriteDescriptorSet descriptor_write;
5900 memset(&descriptor_write, 0, sizeof(descriptor_write));
5901 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5902 descriptor_write.dstSet = descriptorSet;
5903 descriptor_write.dstBinding = 0;
5904 descriptor_write.descriptorCount = 1;
5905 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5906 descriptor_write.pImageInfo = &img_info;
5907
5908 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5909
5910 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005911 char const *vsSource =
5912 "#version 450\n"
5913 "\n"
5914 "out gl_PerVertex { \n"
5915 " vec4 gl_Position;\n"
5916 "};\n"
5917 "void main(){\n"
5918 " gl_Position = vec4(1);\n"
5919 "}\n";
5920 char const *fsSource =
5921 "#version 450\n"
5922 "\n"
5923 "layout(set=0, binding=0) uniform sampler2D s;\n"
5924 "layout(location=0) out vec4 x;\n"
5925 "void main(){\n"
5926 " x = texture(s, vec2(1));\n"
5927 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005928 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5929 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5930 VkPipelineObj pipe(m_device);
5931 pipe.AddShader(&vs);
5932 pipe.AddShader(&fs);
5933 pipe.AddColorAttachment();
5934 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5935
5936 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005938 m_commandBuffer->BeginCommandBuffer();
5939 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005940 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5941 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5942 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005943 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5944 VkRect2D scissor = {{0, 0}, {16, 16}};
5945 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5946 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005947 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005948 m_commandBuffer->EndRenderPass();
5949 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005950 // Destroy sampler invalidates the cmd buffer, causing error on submit
5951 vkDestroySampler(m_device->device(), sampler, NULL);
5952 // Attempt to submit cmd buffer
5953 VkSubmitInfo submit_info = {};
5954 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5955 submit_info.commandBufferCount = 1;
5956 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5958 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005959
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005960 // Now re-update descriptor with valid sampler and delete image
5961 img_info.sampler = sampler2;
5962 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005963
5964 VkCommandBufferBeginInfo info = {};
5965 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5966 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005969 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005970 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5972 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5973 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005974 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5975 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005976 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005977 m_commandBuffer->EndRenderPass();
5978 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005979 // Destroy image invalidates the cmd buffer, causing error on submit
5980 vkDestroyImage(m_device->device(), image, NULL);
5981 // Attempt to submit cmd buffer
5982 submit_info = {};
5983 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5984 submit_info.commandBufferCount = 1;
5985 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5986 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5987 m_errorMonitor->VerifyFound();
5988 // Now update descriptor to be valid, but then free descriptor
5989 img_info.imageView = view2;
5990 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005991 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005992 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005993 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5994 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5995 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005996 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5997 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005998 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005999 m_commandBuffer->EndRenderPass();
6000 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006001 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006002
6003 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006005 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006006 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006007
6008 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006009 // 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 -07006010 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006011 m_errorMonitor->SetUnexpectedError(
6012 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6013 "either be a valid handle or VK_NULL_HANDLE");
6014 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006015 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6016
6017 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006018 submit_info = {};
6019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6020 submit_info.commandBufferCount = 1;
6021 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006023 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6024 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006025
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006026 // Cleanup
6027 vkFreeMemory(m_device->device(), image_memory, NULL);
6028 vkDestroySampler(m_device->device(), sampler2, NULL);
6029 vkDestroyImage(m_device->device(), image2, NULL);
6030 vkDestroyImageView(m_device->device(), view, NULL);
6031 vkDestroyImageView(m_device->device(), view2, NULL);
6032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6035}
6036
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006037TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6038 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6039 ASSERT_NO_FATAL_FAILURE(InitState());
6040 ASSERT_NO_FATAL_FAILURE(InitViewport());
6041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6042
6043 VkDescriptorPoolSize ds_type_count = {};
6044 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6045 ds_type_count.descriptorCount = 1;
6046
6047 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6048 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6049 ds_pool_ci.pNext = NULL;
6050 ds_pool_ci.maxSets = 1;
6051 ds_pool_ci.poolSizeCount = 1;
6052 ds_pool_ci.pPoolSizes = &ds_type_count;
6053
6054 VkDescriptorPool ds_pool;
6055 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6056 ASSERT_VK_SUCCESS(err);
6057
6058 VkDescriptorSetLayoutBinding dsl_binding = {};
6059 dsl_binding.binding = 0;
6060 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6061 dsl_binding.descriptorCount = 1;
6062 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6063 dsl_binding.pImmutableSamplers = NULL;
6064
6065 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6066 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6067 ds_layout_ci.pNext = NULL;
6068 ds_layout_ci.bindingCount = 1;
6069 ds_layout_ci.pBindings = &dsl_binding;
6070 VkDescriptorSetLayout ds_layout;
6071 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6072 ASSERT_VK_SUCCESS(err);
6073
6074 VkDescriptorSet descriptor_set;
6075 VkDescriptorSetAllocateInfo alloc_info = {};
6076 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6077 alloc_info.descriptorSetCount = 1;
6078 alloc_info.descriptorPool = ds_pool;
6079 alloc_info.pSetLayouts = &ds_layout;
6080 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6081 ASSERT_VK_SUCCESS(err);
6082
6083 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6084 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6085 pipeline_layout_ci.pNext = NULL;
6086 pipeline_layout_ci.setLayoutCount = 1;
6087 pipeline_layout_ci.pSetLayouts = &ds_layout;
6088
6089 VkPipelineLayout pipeline_layout;
6090 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6091 ASSERT_VK_SUCCESS(err);
6092
6093 // Create image to update the descriptor with
6094 VkImageObj image(m_device);
6095 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6096 ASSERT_TRUE(image.initialized());
6097
6098 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6099 // Create Sampler
6100 VkSamplerCreateInfo sampler_ci = {};
6101 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6102 sampler_ci.pNext = NULL;
6103 sampler_ci.magFilter = VK_FILTER_NEAREST;
6104 sampler_ci.minFilter = VK_FILTER_NEAREST;
6105 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6106 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6107 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6108 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6109 sampler_ci.mipLodBias = 1.0;
6110 sampler_ci.anisotropyEnable = VK_FALSE;
6111 sampler_ci.maxAnisotropy = 1;
6112 sampler_ci.compareEnable = VK_FALSE;
6113 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6114 sampler_ci.minLod = 1.0;
6115 sampler_ci.maxLod = 1.0;
6116 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6117 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6118 VkSampler sampler;
6119 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6120 ASSERT_VK_SUCCESS(err);
6121 // Update descriptor with image and sampler
6122 VkDescriptorImageInfo img_info = {};
6123 img_info.sampler = sampler;
6124 img_info.imageView = view;
6125 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6126
6127 VkWriteDescriptorSet descriptor_write;
6128 memset(&descriptor_write, 0, sizeof(descriptor_write));
6129 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6130 descriptor_write.dstSet = descriptor_set;
6131 descriptor_write.dstBinding = 0;
6132 descriptor_write.descriptorCount = 1;
6133 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6134 descriptor_write.pImageInfo = &img_info;
6135
6136 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6137
6138 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006139 char const *vsSource =
6140 "#version 450\n"
6141 "\n"
6142 "out gl_PerVertex { \n"
6143 " vec4 gl_Position;\n"
6144 "};\n"
6145 "void main(){\n"
6146 " gl_Position = vec4(1);\n"
6147 "}\n";
6148 char const *fsSource =
6149 "#version 450\n"
6150 "\n"
6151 "layout(set=0, binding=0) uniform sampler2D s;\n"
6152 "layout(location=0) out vec4 x;\n"
6153 "void main(){\n"
6154 " x = texture(s, vec2(1));\n"
6155 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6158 VkPipelineObj pipe(m_device);
6159 pipe.AddShader(&vs);
6160 pipe.AddShader(&fs);
6161 pipe.AddColorAttachment();
6162 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6163
Tony Barbour552f6c02016-12-21 14:34:07 -07006164 m_commandBuffer->BeginCommandBuffer();
6165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006166 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6167 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6168 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006169
6170 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6171 VkRect2D scissor = {{0, 0}, {16, 16}};
6172 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6173 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6174
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006175 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006176 m_commandBuffer->EndRenderPass();
6177 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006178 // Submit cmd buffer to put pool in-flight
6179 VkSubmitInfo submit_info = {};
6180 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6181 submit_info.commandBufferCount = 1;
6182 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6183 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6184 // Destroy pool while in-flight, causing error
6185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6187 m_errorMonitor->VerifyFound();
6188 vkQueueWaitIdle(m_device->m_queue);
6189 // Cleanup
6190 vkDestroySampler(m_device->device(), sampler, NULL);
6191 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006193 m_errorMonitor->SetUnexpectedError(
6194 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6195 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006196 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006197 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006198}
6199
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006200TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6201 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6202 ASSERT_NO_FATAL_FAILURE(InitState());
6203 ASSERT_NO_FATAL_FAILURE(InitViewport());
6204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6205
6206 VkDescriptorPoolSize ds_type_count = {};
6207 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6208 ds_type_count.descriptorCount = 1;
6209
6210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6212 ds_pool_ci.pNext = NULL;
6213 ds_pool_ci.maxSets = 1;
6214 ds_pool_ci.poolSizeCount = 1;
6215 ds_pool_ci.pPoolSizes = &ds_type_count;
6216
6217 VkDescriptorPool ds_pool;
6218 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6219 ASSERT_VK_SUCCESS(err);
6220
6221 VkDescriptorSetLayoutBinding dsl_binding = {};
6222 dsl_binding.binding = 0;
6223 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6224 dsl_binding.descriptorCount = 1;
6225 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6226 dsl_binding.pImmutableSamplers = NULL;
6227
6228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6230 ds_layout_ci.pNext = NULL;
6231 ds_layout_ci.bindingCount = 1;
6232 ds_layout_ci.pBindings = &dsl_binding;
6233 VkDescriptorSetLayout ds_layout;
6234 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6235 ASSERT_VK_SUCCESS(err);
6236
6237 VkDescriptorSet descriptorSet;
6238 VkDescriptorSetAllocateInfo alloc_info = {};
6239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6240 alloc_info.descriptorSetCount = 1;
6241 alloc_info.descriptorPool = ds_pool;
6242 alloc_info.pSetLayouts = &ds_layout;
6243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6244 ASSERT_VK_SUCCESS(err);
6245
6246 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6247 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6248 pipeline_layout_ci.pNext = NULL;
6249 pipeline_layout_ci.setLayoutCount = 1;
6250 pipeline_layout_ci.pSetLayouts = &ds_layout;
6251
6252 VkPipelineLayout pipeline_layout;
6253 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6254 ASSERT_VK_SUCCESS(err);
6255
6256 // Create images to update the descriptor with
6257 VkImage image;
6258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6259 const int32_t tex_width = 32;
6260 const int32_t tex_height = 32;
6261 VkImageCreateInfo image_create_info = {};
6262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6263 image_create_info.pNext = NULL;
6264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6265 image_create_info.format = tex_format;
6266 image_create_info.extent.width = tex_width;
6267 image_create_info.extent.height = tex_height;
6268 image_create_info.extent.depth = 1;
6269 image_create_info.mipLevels = 1;
6270 image_create_info.arrayLayers = 1;
6271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6273 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6274 image_create_info.flags = 0;
6275 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6276 ASSERT_VK_SUCCESS(err);
6277 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6278 VkMemoryRequirements memory_reqs;
6279 VkDeviceMemory image_memory;
6280 bool pass;
6281 VkMemoryAllocateInfo memory_info = {};
6282 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6283 memory_info.pNext = NULL;
6284 memory_info.allocationSize = 0;
6285 memory_info.memoryTypeIndex = 0;
6286 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6287 // Allocate enough memory for image
6288 memory_info.allocationSize = memory_reqs.size;
6289 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6290 ASSERT_TRUE(pass);
6291 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6292 ASSERT_VK_SUCCESS(err);
6293 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6294 ASSERT_VK_SUCCESS(err);
6295
6296 VkImageViewCreateInfo image_view_create_info = {};
6297 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6298 image_view_create_info.image = image;
6299 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6300 image_view_create_info.format = tex_format;
6301 image_view_create_info.subresourceRange.layerCount = 1;
6302 image_view_create_info.subresourceRange.baseMipLevel = 0;
6303 image_view_create_info.subresourceRange.levelCount = 1;
6304 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6305
6306 VkImageView view;
6307 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6308 ASSERT_VK_SUCCESS(err);
6309 // Create Samplers
6310 VkSamplerCreateInfo sampler_ci = {};
6311 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6312 sampler_ci.pNext = NULL;
6313 sampler_ci.magFilter = VK_FILTER_NEAREST;
6314 sampler_ci.minFilter = VK_FILTER_NEAREST;
6315 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6316 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6317 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6318 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6319 sampler_ci.mipLodBias = 1.0;
6320 sampler_ci.anisotropyEnable = VK_FALSE;
6321 sampler_ci.maxAnisotropy = 1;
6322 sampler_ci.compareEnable = VK_FALSE;
6323 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6324 sampler_ci.minLod = 1.0;
6325 sampler_ci.maxLod = 1.0;
6326 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6327 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6328 VkSampler sampler;
6329 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6330 ASSERT_VK_SUCCESS(err);
6331 // Update descriptor with image and sampler
6332 VkDescriptorImageInfo img_info = {};
6333 img_info.sampler = sampler;
6334 img_info.imageView = view;
6335 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6336
6337 VkWriteDescriptorSet descriptor_write;
6338 memset(&descriptor_write, 0, sizeof(descriptor_write));
6339 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6340 descriptor_write.dstSet = descriptorSet;
6341 descriptor_write.dstBinding = 0;
6342 descriptor_write.descriptorCount = 1;
6343 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6344 descriptor_write.pImageInfo = &img_info;
6345 // Break memory binding and attempt update
6346 vkFreeMemory(m_device->device(), image_memory, nullptr);
6347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006348 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6350 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6351 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6352 m_errorMonitor->VerifyFound();
6353 // Cleanup
6354 vkDestroyImage(m_device->device(), image, NULL);
6355 vkDestroySampler(m_device->device(), sampler, NULL);
6356 vkDestroyImageView(m_device->device(), view, NULL);
6357 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6360}
6361
Karl Schultz6addd812016-02-02 17:17:23 -07006362TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006363 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6364 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006365 // Create a valid cmd buffer
6366 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006367 uint64_t fake_pipeline_handle = 0xbaad6001;
6368 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006369 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6371
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006373 m_commandBuffer->BeginCommandBuffer();
6374 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006376 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006377
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006378 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006379 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 -06006380 Draw(1, 0, 0, 0);
6381 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006382
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006383 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006384 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 -07006385 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006386 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6387 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006388}
6389
Karl Schultz6addd812016-02-02 17:17:23 -07006390TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006391 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006392 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006395
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006396 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006397 ASSERT_NO_FATAL_FAILURE(InitViewport());
6398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006399 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006400 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6401 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006402
6403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6405 ds_pool_ci.pNext = NULL;
6406 ds_pool_ci.maxSets = 1;
6407 ds_pool_ci.poolSizeCount = 1;
6408 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006409
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006410 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006411 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006412 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006413
Tony Barboureb254902015-07-15 12:50:33 -06006414 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 dsl_binding.binding = 0;
6416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6417 dsl_binding.descriptorCount = 1;
6418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6419 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006420
Tony Barboureb254902015-07-15 12:50:33 -06006421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6423 ds_layout_ci.pNext = NULL;
6424 ds_layout_ci.bindingCount = 1;
6425 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006426 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006428 ASSERT_VK_SUCCESS(err);
6429
6430 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006431 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006432 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006433 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006434 alloc_info.descriptorPool = ds_pool;
6435 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006437 ASSERT_VK_SUCCESS(err);
6438
Tony Barboureb254902015-07-15 12:50:33 -06006439 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006440 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6441 pipeline_layout_ci.pNext = NULL;
6442 pipeline_layout_ci.setLayoutCount = 1;
6443 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006444
6445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006447 ASSERT_VK_SUCCESS(err);
6448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006450 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006451 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006453
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006454 VkPipelineObj pipe(m_device);
6455 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006456 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006457 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006458 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006459
Tony Barbour552f6c02016-12-21 14:34:07 -07006460 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006461 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6462 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6463 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006464
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006465 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006466
Chia-I Wuf7458c52015-10-26 21:10:41 +08006467 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6468 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6469 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006470}
6471
Karl Schultz6addd812016-02-02 17:17:23 -07006472TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006473 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006474 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006475
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006477
6478 ASSERT_NO_FATAL_FAILURE(InitState());
6479 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006480 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6481 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006482
6483 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006484 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6485 ds_pool_ci.pNext = NULL;
6486 ds_pool_ci.maxSets = 1;
6487 ds_pool_ci.poolSizeCount = 1;
6488 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006489
6490 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006491 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006492 ASSERT_VK_SUCCESS(err);
6493
6494 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 dsl_binding.binding = 0;
6496 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6497 dsl_binding.descriptorCount = 1;
6498 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6499 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006500
6501 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6503 ds_layout_ci.pNext = NULL;
6504 ds_layout_ci.bindingCount = 1;
6505 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006506 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006508 ASSERT_VK_SUCCESS(err);
6509
6510 VkDescriptorSet descriptorSet;
6511 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006512 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006513 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006514 alloc_info.descriptorPool = ds_pool;
6515 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006516 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006517 ASSERT_VK_SUCCESS(err);
6518
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006519 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006520 VkWriteDescriptorSet descriptor_write;
6521 memset(&descriptor_write, 0, sizeof(descriptor_write));
6522 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6523 descriptor_write.dstSet = descriptorSet;
6524 descriptor_write.dstBinding = 0;
6525 descriptor_write.descriptorCount = 1;
6526 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6527 descriptor_write.pTexelBufferView = &view;
6528
6529 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6530
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006531 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006532
6533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6534 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6535}
6536
Mark Youngd339ba32016-05-30 13:28:35 -06006537TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006538 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 -06006539
6540 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006542 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006543
6544 ASSERT_NO_FATAL_FAILURE(InitState());
6545
6546 // Create a buffer with no bound memory and then attempt to create
6547 // a buffer view.
6548 VkBufferCreateInfo buff_ci = {};
6549 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006550 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006551 buff_ci.size = 256;
6552 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6553 VkBuffer buffer;
6554 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6555 ASSERT_VK_SUCCESS(err);
6556
6557 VkBufferViewCreateInfo buff_view_ci = {};
6558 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6559 buff_view_ci.buffer = buffer;
6560 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6561 buff_view_ci.range = VK_WHOLE_SIZE;
6562 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006563 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006564
6565 m_errorMonitor->VerifyFound();
6566 vkDestroyBuffer(m_device->device(), buffer, NULL);
6567 // If last error is success, it still created the view, so delete it.
6568 if (err == VK_SUCCESS) {
6569 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6570 }
6571}
6572
Karl Schultz6addd812016-02-02 17:17:23 -07006573TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6574 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6575 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006576 // 1. No dynamicOffset supplied
6577 // 2. Too many dynamicOffsets supplied
6578 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006579 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6581 " requires 1 dynamicOffsets, but only "
6582 "0 dynamicOffsets are left in "
6583 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006584
6585 ASSERT_NO_FATAL_FAILURE(InitState());
6586 ASSERT_NO_FATAL_FAILURE(InitViewport());
6587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6588
6589 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6591 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006592
6593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6595 ds_pool_ci.pNext = NULL;
6596 ds_pool_ci.maxSets = 1;
6597 ds_pool_ci.poolSizeCount = 1;
6598 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006599
6600 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006602 ASSERT_VK_SUCCESS(err);
6603
6604 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 dsl_binding.binding = 0;
6606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6607 dsl_binding.descriptorCount = 1;
6608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6609 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006612 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6613 ds_layout_ci.pNext = NULL;
6614 ds_layout_ci.bindingCount = 1;
6615 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006616 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkDescriptorSet descriptorSet;
6621 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006623 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006624 alloc_info.descriptorPool = ds_pool;
6625 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006627 ASSERT_VK_SUCCESS(err);
6628
6629 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006630 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6631 pipeline_layout_ci.pNext = NULL;
6632 pipeline_layout_ci.setLayoutCount = 1;
6633 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006634
6635 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006637 ASSERT_VK_SUCCESS(err);
6638
6639 // Create a buffer to update the descriptor with
6640 uint32_t qfi = 0;
6641 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006642 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6643 buffCI.size = 1024;
6644 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6645 buffCI.queueFamilyIndexCount = 1;
6646 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006647
6648 VkBuffer dyub;
6649 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6650 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006651 // Allocate memory and bind to buffer so we can make it to the appropriate
6652 // error
6653 VkMemoryAllocateInfo mem_alloc = {};
6654 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6655 mem_alloc.pNext = NULL;
6656 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006657 mem_alloc.memoryTypeIndex = 0;
6658
6659 VkMemoryRequirements memReqs;
6660 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006662 if (!pass) {
6663 vkDestroyBuffer(m_device->device(), dyub, NULL);
6664 return;
6665 }
6666
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006667 VkDeviceMemory mem;
6668 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6669 ASSERT_VK_SUCCESS(err);
6670 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6671 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006672 // Correctly update descriptor to avoid "NOT_UPDATED" error
6673 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006674 buffInfo.buffer = dyub;
6675 buffInfo.offset = 0;
6676 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006677
6678 VkWriteDescriptorSet descriptor_write;
6679 memset(&descriptor_write, 0, sizeof(descriptor_write));
6680 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6681 descriptor_write.dstSet = descriptorSet;
6682 descriptor_write.dstBinding = 0;
6683 descriptor_write.descriptorCount = 1;
6684 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6685 descriptor_write.pBufferInfo = &buffInfo;
6686
6687 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6688
Tony Barbour552f6c02016-12-21 14:34:07 -07006689 m_commandBuffer->BeginCommandBuffer();
6690 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6692 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006693 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006694 uint32_t pDynOff[2] = {512, 756};
6695 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6697 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6698 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6699 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006700 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006701 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6703 " dynamic offset 512 combined with "
6704 "offset 0 and range 1024 that "
6705 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006706 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006707 char const *vsSource =
6708 "#version 450\n"
6709 "\n"
6710 "out gl_PerVertex { \n"
6711 " vec4 gl_Position;\n"
6712 "};\n"
6713 "void main(){\n"
6714 " gl_Position = vec4(1);\n"
6715 "}\n";
6716 char const *fsSource =
6717 "#version 450\n"
6718 "\n"
6719 "layout(location=0) out vec4 x;\n"
6720 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6721 "void main(){\n"
6722 " x = vec4(bar.y);\n"
6723 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006724 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6725 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6726 VkPipelineObj pipe(m_device);
6727 pipe.AddShader(&vs);
6728 pipe.AddShader(&fs);
6729 pipe.AddColorAttachment();
6730 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6731
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006732 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6733 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6734 VkRect2D scissor = {{0, 0}, {16, 16}};
6735 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006738 // This update should succeed, but offset size of 512 will overstep buffer
6739 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6741 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006742 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006743 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006744
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006745 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006746 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006747
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6751}
6752
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006753TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006754 TEST_DESCRIPTION(
6755 "Attempt to update a descriptor with a non-sparse buffer "
6756 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006757 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006759 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6761 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006762
6763 ASSERT_NO_FATAL_FAILURE(InitState());
6764 ASSERT_NO_FATAL_FAILURE(InitViewport());
6765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6766
6767 VkDescriptorPoolSize ds_type_count = {};
6768 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6769 ds_type_count.descriptorCount = 1;
6770
6771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6773 ds_pool_ci.pNext = NULL;
6774 ds_pool_ci.maxSets = 1;
6775 ds_pool_ci.poolSizeCount = 1;
6776 ds_pool_ci.pPoolSizes = &ds_type_count;
6777
6778 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006779 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006780 ASSERT_VK_SUCCESS(err);
6781
6782 VkDescriptorSetLayoutBinding dsl_binding = {};
6783 dsl_binding.binding = 0;
6784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6785 dsl_binding.descriptorCount = 1;
6786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6787 dsl_binding.pImmutableSamplers = NULL;
6788
6789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6791 ds_layout_ci.pNext = NULL;
6792 ds_layout_ci.bindingCount = 1;
6793 ds_layout_ci.pBindings = &dsl_binding;
6794 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006795 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006796 ASSERT_VK_SUCCESS(err);
6797
6798 VkDescriptorSet descriptorSet;
6799 VkDescriptorSetAllocateInfo alloc_info = {};
6800 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6801 alloc_info.descriptorSetCount = 1;
6802 alloc_info.descriptorPool = ds_pool;
6803 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006805 ASSERT_VK_SUCCESS(err);
6806
6807 // Create a buffer to update the descriptor with
6808 uint32_t qfi = 0;
6809 VkBufferCreateInfo buffCI = {};
6810 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6811 buffCI.size = 1024;
6812 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6813 buffCI.queueFamilyIndexCount = 1;
6814 buffCI.pQueueFamilyIndices = &qfi;
6815
6816 VkBuffer dyub;
6817 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6818 ASSERT_VK_SUCCESS(err);
6819
6820 // Attempt to update descriptor without binding memory to it
6821 VkDescriptorBufferInfo buffInfo = {};
6822 buffInfo.buffer = dyub;
6823 buffInfo.offset = 0;
6824 buffInfo.range = 1024;
6825
6826 VkWriteDescriptorSet descriptor_write;
6827 memset(&descriptor_write, 0, sizeof(descriptor_write));
6828 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6829 descriptor_write.dstSet = descriptorSet;
6830 descriptor_write.dstBinding = 0;
6831 descriptor_write.descriptorCount = 1;
6832 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6833 descriptor_write.pBufferInfo = &buffInfo;
6834
6835 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6836 m_errorMonitor->VerifyFound();
6837
6838 vkDestroyBuffer(m_device->device(), dyub, NULL);
6839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6841}
6842
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006843TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006844 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006845 ASSERT_NO_FATAL_FAILURE(InitState());
6846 ASSERT_NO_FATAL_FAILURE(InitViewport());
6847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6848
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006849 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006850 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006851 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6852 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6853 pipeline_layout_ci.pushConstantRangeCount = 1;
6854 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6855
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006856 //
6857 // Check for invalid push constant ranges in pipeline layouts.
6858 //
6859 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006860 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006861 char const *msg;
6862 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006863
Karl Schultzc81037d2016-05-12 08:11:23 -06006864 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6865 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6866 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6867 "vkCreatePipelineLayout() call has push constants index 0 with "
6868 "size 0."},
6869 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6870 "vkCreatePipelineLayout() call has push constants index 0 with "
6871 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006872 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006873 "vkCreatePipelineLayout() call has push constants index 0 with "
6874 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006875 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006876 "vkCreatePipelineLayout() call has push constants index 0 with "
6877 "size 0."},
6878 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6879 "vkCreatePipelineLayout() call has push constants index 0 with "
6880 "offset 1. Offset must"},
6881 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6882 "vkCreatePipelineLayout() call has push constants index 0 "
6883 "with offset "},
6884 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6885 "vkCreatePipelineLayout() call has push constants "
6886 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006887 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006888 "vkCreatePipelineLayout() call has push constants index 0 "
6889 "with offset "},
6890 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6891 "vkCreatePipelineLayout() call has push "
6892 "constants index 0 with offset "},
6893 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6894 "vkCreatePipelineLayout() call has push "
6895 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006896 }};
6897
6898 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006899 for (const auto &iter : range_tests) {
6900 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6902 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006903 m_errorMonitor->VerifyFound();
6904 if (VK_SUCCESS == err) {
6905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6906 }
6907 }
6908
6909 // Check for invalid stage flag
6910 pc_range.offset = 0;
6911 pc_range.size = 16;
6912 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006913 m_errorMonitor->SetDesiredFailureMsg(
6914 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6915 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006916 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006917 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006918 if (VK_SUCCESS == err) {
6919 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6920 }
6921
Karl Schultzc59b72d2017-02-24 15:45:05 -07006922 // Check for duplicate stage flags in a list of push constant ranges.
6923 // A shader can only have one push constant block and that block is mapped
6924 // to the push constant range that has that shader's stage flag set.
6925 // The shader's stage flag can only appear once in all the ranges, so the
6926 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006927 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006928 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006929 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006930 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006931 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006932 // Overlapping ranges are OK, but a stage flag can appear only once.
6933 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6934 {
6935 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6936 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6937 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6938 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006939 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006940 {
6941 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6942 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6943 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6944 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6945 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6946 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6947 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6948 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6949 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6950 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6951 }},
6952 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6953 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6954 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6955 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6956 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6957 {
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6960 }},
6961 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6962 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6963 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6964 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6965 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6966 {
6967 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6968 }},
6969 },
6970 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006971
Karl Schultzc59b72d2017-02-24 15:45:05 -07006972 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006973 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006974 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006976 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006977 m_errorMonitor->VerifyFound();
6978 if (VK_SUCCESS == err) {
6979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6980 }
6981 }
6982
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006983 //
6984 // CmdPushConstants tests
6985 //
6986
Karl Schultzc59b72d2017-02-24 15:45:05 -07006987 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006988 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07006989 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006990 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006992 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006993 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006994 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07006995
6996 const uint8_t dummy_values[100] = {};
6997
6998 m_commandBuffer->BeginCommandBuffer();
6999 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007000
7001 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007002 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007005 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007006
Karl Schultzc59b72d2017-02-24 15:45:05 -07007007 m_errorMonitor->ExpectSuccess();
7008 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7009 m_errorMonitor->VerifyNotFound();
7010 m_errorMonitor->ExpectSuccess();
7011 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7012 m_errorMonitor->VerifyNotFound();
7013 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7014 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7015 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7016 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7017 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7018 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7019 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007020 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007021 for (const auto &iter : cmd_range_tests) {
7022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7023 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7024 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007025 m_errorMonitor->VerifyFound();
7026 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007027
Tony Barbour552f6c02016-12-21 14:34:07 -07007028 m_commandBuffer->EndRenderPass();
7029 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007030 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007031}
7032
Karl Schultz6addd812016-02-02 17:17:23 -07007033TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007034 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007035 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007036
7037 ASSERT_NO_FATAL_FAILURE(InitState());
7038 ASSERT_NO_FATAL_FAILURE(InitViewport());
7039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7040
7041 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7042 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007043 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7044 ds_type_count[0].descriptorCount = 10;
7045 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7046 ds_type_count[1].descriptorCount = 2;
7047 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7048 ds_type_count[2].descriptorCount = 2;
7049 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7050 ds_type_count[3].descriptorCount = 5;
7051 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7052 // type
7053 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7054 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7055 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007056
7057 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007058 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7059 ds_pool_ci.pNext = NULL;
7060 ds_pool_ci.maxSets = 5;
7061 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7062 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007063
7064 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007065 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007066 ASSERT_VK_SUCCESS(err);
7067
7068 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7069 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007070 dsl_binding[0].binding = 0;
7071 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7072 dsl_binding[0].descriptorCount = 5;
7073 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7074 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007075
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007076 // Create layout identical to set0 layout but w/ different stageFlags
7077 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007078 dsl_fs_stage_only.binding = 0;
7079 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7080 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007081 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7082 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007083 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7086 ds_layout_ci.pNext = NULL;
7087 ds_layout_ci.bindingCount = 1;
7088 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007089 static const uint32_t NUM_LAYOUTS = 4;
7090 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007091 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007092 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7093 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007095 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007096 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007098 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007099 dsl_binding[0].binding = 0;
7100 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007101 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007102 dsl_binding[1].binding = 1;
7103 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7104 dsl_binding[1].descriptorCount = 2;
7105 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7106 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007107 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007108 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 ASSERT_VK_SUCCESS(err);
7111 dsl_binding[0].binding = 0;
7112 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007113 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007114 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007115 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007116 ASSERT_VK_SUCCESS(err);
7117 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007118 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007119 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007120 ASSERT_VK_SUCCESS(err);
7121
7122 static const uint32_t NUM_SETS = 4;
7123 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7124 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007125 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007126 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 alloc_info.descriptorPool = ds_pool;
7128 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007130 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007131 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007132 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007133 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007135 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136
7137 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007138 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7139 pipeline_layout_ci.pNext = NULL;
7140 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7141 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007142
7143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007144 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007145 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 // Create pipelineLayout with only one setLayout
7147 pipeline_layout_ci.setLayoutCount = 1;
7148 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007150 ASSERT_VK_SUCCESS(err);
7151 // Create pipelineLayout with 2 descriptor setLayout at index 0
7152 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7153 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007154 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007155 ASSERT_VK_SUCCESS(err);
7156 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7157 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7158 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007159 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007160 ASSERT_VK_SUCCESS(err);
7161 // Create pipelineLayout with UB type, but stageFlags for FS only
7162 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7163 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007165 ASSERT_VK_SUCCESS(err);
7166 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7167 VkDescriptorSetLayout pl_bad_s0[2] = {};
7168 pl_bad_s0[0] = ds_layout_fs_only;
7169 pl_bad_s0[1] = ds_layout[1];
7170 pipeline_layout_ci.setLayoutCount = 2;
7171 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7172 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007174 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007175
Tobin Ehlis88452832015-12-03 09:40:56 -07007176 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007177 char const *vsSource =
7178 "#version 450\n"
7179 "\n"
7180 "out gl_PerVertex {\n"
7181 " vec4 gl_Position;\n"
7182 "};\n"
7183 "void main(){\n"
7184 " gl_Position = vec4(1);\n"
7185 "}\n";
7186 char const *fsSource =
7187 "#version 450\n"
7188 "\n"
7189 "layout(location=0) out vec4 x;\n"
7190 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7191 "void main(){\n"
7192 " x = vec4(bar.y);\n"
7193 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007194 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7195 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007196 VkPipelineObj pipe(m_device);
7197 pipe.AddShader(&vs);
7198 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007199 pipe.AddColorAttachment();
7200 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007201
Tony Barbour552f6c02016-12-21 14:34:07 -07007202 m_commandBuffer->BeginCommandBuffer();
7203 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007205 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007206 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7207 // of PSO
7208 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7209 // cmd_pipeline.c
7210 // due to the fact that cmd_alloc_dset_data() has not been called in
7211 // cmd_bind_graphics_pipeline()
7212 // TODO : Want to cause various binding incompatibility issues here to test
7213 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007214 // First cause various verify_layout_compatibility() fails
7215 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007216 // verify_set_layout_compatibility fail cases:
7217 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7220 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007221 m_errorMonitor->VerifyFound();
7222
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007223 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7225 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7226 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007227 m_errorMonitor->VerifyFound();
7228
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007229 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007230 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7231 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7233 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7234 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007235 m_errorMonitor->VerifyFound();
7236
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007237 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7238 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7240 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7241 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007242 m_errorMonitor->VerifyFound();
7243
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007244 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7245 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7247 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7248 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7249 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007250 m_errorMonitor->VerifyFound();
7251
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007252 // Cause INFO messages due to disturbing previously bound Sets
7253 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007254 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7255 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007256 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7258 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7259 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007260 m_errorMonitor->VerifyFound();
7261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007262 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7263 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007264 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7266 " newly bound as set #0 so set #1 and "
7267 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7269 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007270 m_errorMonitor->VerifyFound();
7271
Tobin Ehlis10fad692016-07-07 12:00:36 -06007272 // Now that we're done actively using the pipelineLayout that gfx pipeline
7273 // was created with, we should be able to delete it. Do that now to verify
7274 // that validation obeys pipelineLayout lifetime
7275 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7276
Tobin Ehlis88452832015-12-03 09:40:56 -07007277 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007278 // 1. Error due to not binding required set (we actually use same code as
7279 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007280 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7281 &descriptorSet[0], 0, NULL);
7282 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7283 &descriptorSet[1], 0, NULL);
7284 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 -07007285
7286 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7287 VkRect2D scissor = {{0, 0}, {16, 16}};
7288 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7289 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7290
Tobin Ehlis88452832015-12-03 09:40:56 -07007291 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007292 m_errorMonitor->VerifyFound();
7293
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007294 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007295 // 2. Error due to bound set not being compatible with PSO's
7296 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007297 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7298 &descriptorSet[0], 0, NULL);
7299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007300 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007301 m_errorMonitor->VerifyFound();
7302
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007303 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007304 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007305 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7306 }
7307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7310}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007311
Karl Schultz6addd812016-02-02 17:17:23 -07007312TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7314 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007315
7316 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007317 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007318 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007319 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007320
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007321 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007322}
7323
Karl Schultz6addd812016-02-02 17:17:23 -07007324TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7325 VkResult err;
7326 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007327
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007329
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007330 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007331
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007332 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007333 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007334 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007335 cmd.commandPool = m_commandPool;
7336 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007337 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007338
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007339 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007340 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341
7342 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007343 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007344 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7345
7346 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007347 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007348 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007349 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 -07007350 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007351
7352 // The error should be caught by validation of the BeginCommandBuffer call
7353 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7354
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007355 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007356 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007357}
7358
Karl Schultz6addd812016-02-02 17:17:23 -07007359TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007360 // Cause error due to Begin while recording CB
7361 // Then cause 2 errors for attempting to reset CB w/o having
7362 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7363 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007365
7366 ASSERT_NO_FATAL_FAILURE(InitState());
7367
7368 // Calls AllocateCommandBuffers
7369 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007371 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007372 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007373 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7374 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007375 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7376 cmd_buf_info.pNext = NULL;
7377 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007378 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007379
7380 // Begin CB to transition to recording state
7381 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7382 // Can't re-begin. This should trigger error
7383 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007384 m_errorMonitor->VerifyFound();
7385
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007387 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007388 // Reset attempt will trigger error due to incorrect CommandPool state
7389 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007390 m_errorMonitor->VerifyFound();
7391
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007393 // Transition CB to RECORDED state
7394 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7395 // Now attempting to Begin will implicitly reset, which triggers error
7396 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007397 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007398}
7399
Karl Schultz6addd812016-02-02 17:17:23 -07007400TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007401 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007402 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007403
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7405 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007406
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007407 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007409
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007410 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7412 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007413
7414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7416 ds_pool_ci.pNext = NULL;
7417 ds_pool_ci.maxSets = 1;
7418 ds_pool_ci.poolSizeCount = 1;
7419 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007420
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007421 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007423 ASSERT_VK_SUCCESS(err);
7424
Tony Barboureb254902015-07-15 12:50:33 -06007425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 dsl_binding.binding = 0;
7427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7428 dsl_binding.descriptorCount = 1;
7429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007431
Tony Barboureb254902015-07-15 12:50:33 -06007432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7434 ds_layout_ci.pNext = NULL;
7435 ds_layout_ci.bindingCount = 1;
7436 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007437
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007438 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007440 ASSERT_VK_SUCCESS(err);
7441
7442 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007443 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007444 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007445 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007446 alloc_info.descriptorPool = ds_pool;
7447 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 ASSERT_VK_SUCCESS(err);
7450
Tony Barboureb254902015-07-15 12:50:33 -06007451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7453 pipeline_layout_ci.setLayoutCount = 1;
7454 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007455
7456 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007458 ASSERT_VK_SUCCESS(err);
7459
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007460 VkViewport vp = {}; // Just need dummy vp to point to
7461 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007462
7463 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007464 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7465 vp_state_ci.scissorCount = 1;
7466 vp_state_ci.pScissors = &sc;
7467 vp_state_ci.viewportCount = 1;
7468 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007469
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007470 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7471 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7472 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7473 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7474 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7475 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007476 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007477 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007478 rs_state_ci.lineWidth = 1.0f;
7479
7480 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7481 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7482 vi_ci.pNext = nullptr;
7483 vi_ci.vertexBindingDescriptionCount = 0;
7484 vi_ci.pVertexBindingDescriptions = nullptr;
7485 vi_ci.vertexAttributeDescriptionCount = 0;
7486 vi_ci.pVertexAttributeDescriptions = nullptr;
7487
7488 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7489 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7490 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7491
7492 VkPipelineShaderStageCreateInfo shaderStages[2];
7493 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7494
7495 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7496 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007497 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007498 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007499
Tony Barboureb254902015-07-15 12:50:33 -06007500 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007501 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7502 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007503 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007504 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7505 gp_ci.layout = pipeline_layout;
7506 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007507 gp_ci.pVertexInputState = &vi_ci;
7508 gp_ci.pInputAssemblyState = &ia_ci;
7509
7510 gp_ci.stageCount = 1;
7511 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007512
7513 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007514 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7515 pc_ci.initialDataSize = 0;
7516 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007517
7518 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007519 VkPipelineCache pipelineCache;
7520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007521 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007522 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007523 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007524 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007525
Chia-I Wuf7458c52015-10-26 21:10:41 +08007526 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7527 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7528 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7529 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007530}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007531
Tobin Ehlis912df022015-09-17 08:46:18 -06007532/*// TODO : This test should be good, but needs Tess support in compiler to run
7533TEST_F(VkLayerTest, InvalidPatchControlPoints)
7534{
7535 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007536 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007537
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007539 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7540primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007541
Tobin Ehlis912df022015-09-17 08:46:18 -06007542 ASSERT_NO_FATAL_FAILURE(InitState());
7543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007544
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007545 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007546 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007547 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007548
7549 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7550 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7551 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007552 ds_pool_ci.poolSizeCount = 1;
7553 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007554
7555 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007556 err = vkCreateDescriptorPool(m_device->device(),
7557VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007558 ASSERT_VK_SUCCESS(err);
7559
7560 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007561 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007562 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007563 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7565 dsl_binding.pImmutableSamplers = NULL;
7566
7567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007568 ds_layout_ci.sType =
7569VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007570 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007571 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007572 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007573
7574 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7576&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007577 ASSERT_VK_SUCCESS(err);
7578
7579 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007580 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7581VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007582 ASSERT_VK_SUCCESS(err);
7583
7584 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007585 pipeline_layout_ci.sType =
7586VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007587 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007588 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007589 pipeline_layout_ci.pSetLayouts = &ds_layout;
7590
7591 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7593&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007594 ASSERT_VK_SUCCESS(err);
7595
7596 VkPipelineShaderStageCreateInfo shaderStages[3];
7597 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7598
Karl Schultz6addd812016-02-02 17:17:23 -07007599 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7600this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007601 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007602 VkShaderObj
7603tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7604this);
7605 VkShaderObj
7606te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7607this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007608
Karl Schultz6addd812016-02-02 17:17:23 -07007609 shaderStages[0].sType =
7610VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007611 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007612 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007613 shaderStages[1].sType =
7614VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007615 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007616 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007617 shaderStages[2].sType =
7618VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007619 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007620 shaderStages[2].shader = te.handle();
7621
7622 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007623 iaCI.sType =
7624VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007625 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007626
7627 VkPipelineTessellationStateCreateInfo tsCI = {};
7628 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7629 tsCI.patchControlPoints = 0; // This will cause an error
7630
7631 VkGraphicsPipelineCreateInfo gp_ci = {};
7632 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7633 gp_ci.pNext = NULL;
7634 gp_ci.stageCount = 3;
7635 gp_ci.pStages = shaderStages;
7636 gp_ci.pVertexInputState = NULL;
7637 gp_ci.pInputAssemblyState = &iaCI;
7638 gp_ci.pTessellationState = &tsCI;
7639 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007640 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007641 gp_ci.pMultisampleState = NULL;
7642 gp_ci.pDepthStencilState = NULL;
7643 gp_ci.pColorBlendState = NULL;
7644 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7645 gp_ci.layout = pipeline_layout;
7646 gp_ci.renderPass = renderPass();
7647
7648 VkPipelineCacheCreateInfo pc_ci = {};
7649 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7650 pc_ci.pNext = NULL;
7651 pc_ci.initialSize = 0;
7652 pc_ci.initialData = 0;
7653 pc_ci.maxSize = 0;
7654
7655 VkPipeline pipeline;
7656 VkPipelineCache pipelineCache;
7657
Karl Schultz6addd812016-02-02 17:17:23 -07007658 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7659&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007660 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007661 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7662&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007664 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007665
Chia-I Wuf7458c52015-10-26 21:10:41 +08007666 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007670}
7671*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007672
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007673TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007674 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007675
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007676 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007677
Tobin Ehlise68360f2015-10-01 11:15:13 -06007678 ASSERT_NO_FATAL_FAILURE(InitState());
7679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007680
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007681 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007682 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7683 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007684
7685 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007686 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7687 ds_pool_ci.maxSets = 1;
7688 ds_pool_ci.poolSizeCount = 1;
7689 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007690
7691 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007692 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007693 ASSERT_VK_SUCCESS(err);
7694
7695 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007696 dsl_binding.binding = 0;
7697 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7698 dsl_binding.descriptorCount = 1;
7699 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007700
7701 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007702 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7703 ds_layout_ci.bindingCount = 1;
7704 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007705
7706 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007708 ASSERT_VK_SUCCESS(err);
7709
7710 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007711 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007712 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007713 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007714 alloc_info.descriptorPool = ds_pool;
7715 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007717 ASSERT_VK_SUCCESS(err);
7718
7719 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007720 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7721 pipeline_layout_ci.setLayoutCount = 1;
7722 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007723
7724 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007725 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007726 ASSERT_VK_SUCCESS(err);
7727
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007728 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007729 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007731 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007732 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007733 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007735 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7736 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7737 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7738 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7739 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7740 rs_state_ci.depthClampEnable = VK_FALSE;
7741 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7742 rs_state_ci.depthBiasEnable = VK_FALSE;
7743
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007744 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7745 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7746 vi_ci.pNext = nullptr;
7747 vi_ci.vertexBindingDescriptionCount = 0;
7748 vi_ci.pVertexBindingDescriptions = nullptr;
7749 vi_ci.vertexAttributeDescriptionCount = 0;
7750 vi_ci.pVertexAttributeDescriptions = nullptr;
7751
7752 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7753 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7754 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7755
7756 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7757 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7758 pipe_ms_state_ci.pNext = NULL;
7759 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7760 pipe_ms_state_ci.sampleShadingEnable = 0;
7761 pipe_ms_state_ci.minSampleShading = 1.0;
7762 pipe_ms_state_ci.pSampleMask = NULL;
7763
Cody Northropeb3a6c12015-10-05 14:44:45 -06007764 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007765 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007766
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007767 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007768 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007769 shaderStages[0] = vs.GetStageCreateInfo();
7770 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007771
7772 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007773 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7774 gp_ci.stageCount = 2;
7775 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007776 gp_ci.pVertexInputState = &vi_ci;
7777 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007778 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007779 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007780 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007781 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7782 gp_ci.layout = pipeline_layout;
7783 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007784
7785 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007786 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007787
7788 VkPipeline pipeline;
7789 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007790 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007791 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007792
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007793 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007794 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007795
7796 // Check case where multiViewport is disabled and viewport count is not 1
7797 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7800 vp_state_ci.scissorCount = 0;
7801 vp_state_ci.viewportCount = 0;
7802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7803 m_errorMonitor->VerifyFound();
7804 } else {
7805 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007806 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007807 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007808 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007809
7810 // Check is that viewportcount and scissorcount match
7811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7812 vp_state_ci.scissorCount = 1;
7813 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7815 m_errorMonitor->VerifyFound();
7816
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007817 // Check case where multiViewport is enabled and viewport count is greater than max
7818 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7821 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7822 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7823 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7824 m_errorMonitor->VerifyFound();
7825 }
7826 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007827
Chia-I Wuf7458c52015-10-26 21:10:41 +08007828 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007832}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007833
7834// 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
7835// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007836TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007837 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007839 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7840
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007842
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843 ASSERT_NO_FATAL_FAILURE(InitState());
7844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007845
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007846 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7848 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849
7850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7852 ds_pool_ci.maxSets = 1;
7853 ds_pool_ci.poolSizeCount = 1;
7854 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007855
7856 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007858 ASSERT_VK_SUCCESS(err);
7859
7860 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007861 dsl_binding.binding = 0;
7862 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7863 dsl_binding.descriptorCount = 1;
7864 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007865
7866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7868 ds_layout_ci.bindingCount = 1;
7869 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007870
7871 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007872 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007873 ASSERT_VK_SUCCESS(err);
7874
7875 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007876 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007878 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007879 alloc_info.descriptorPool = ds_pool;
7880 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007881 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007882 ASSERT_VK_SUCCESS(err);
7883
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007884 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7885 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7886 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7887
7888 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7889 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7890 vi_ci.pNext = nullptr;
7891 vi_ci.vertexBindingDescriptionCount = 0;
7892 vi_ci.pVertexBindingDescriptions = nullptr;
7893 vi_ci.vertexAttributeDescriptionCount = 0;
7894 vi_ci.pVertexAttributeDescriptions = nullptr;
7895
7896 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7897 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7898 pipe_ms_state_ci.pNext = NULL;
7899 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7900 pipe_ms_state_ci.sampleShadingEnable = 0;
7901 pipe_ms_state_ci.minSampleShading = 1.0;
7902 pipe_ms_state_ci.pSampleMask = NULL;
7903
Tobin Ehlise68360f2015-10-01 11:15:13 -06007904 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007905 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7906 pipeline_layout_ci.setLayoutCount = 1;
7907 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007908
7909 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007911 ASSERT_VK_SUCCESS(err);
7912
7913 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7914 // Set scissor as dynamic to avoid second error
7915 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007916 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7917 dyn_state_ci.dynamicStateCount = 1;
7918 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
Cody Northropeb3a6c12015-10-05 14:44:45 -06007920 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007921 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007924 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7925 // 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 +08007926 shaderStages[0] = vs.GetStageCreateInfo();
7927 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007928
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007929 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7930 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7931 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7932 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7933 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7934 rs_state_ci.depthClampEnable = VK_FALSE;
7935 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7936 rs_state_ci.depthBiasEnable = VK_FALSE;
7937
Tobin Ehlise68360f2015-10-01 11:15:13 -06007938 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007939 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7940 gp_ci.stageCount = 2;
7941 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007942 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007943 // Not setting VP state w/o dynamic vp state should cause validation error
7944 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007945 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007946 gp_ci.pVertexInputState = &vi_ci;
7947 gp_ci.pInputAssemblyState = &ia_ci;
7948 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007949 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7950 gp_ci.layout = pipeline_layout;
7951 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007952
7953 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007954 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955
7956 VkPipeline pipeline;
7957 VkPipelineCache pipelineCache;
7958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007959 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007960 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007963 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964
Chia-I Wuf7458c52015-10-26 21:10:41 +08007965 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007969}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007970
7971// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7972// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007973TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7974 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007977
Tobin Ehlise68360f2015-10-01 11:15:13 -06007978 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007979
7980 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007981 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007982 return;
7983 }
7984
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007987 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007988 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7989 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007990
7991 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007992 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7993 ds_pool_ci.maxSets = 1;
7994 ds_pool_ci.poolSizeCount = 1;
7995 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996
7997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007998 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007999 ASSERT_VK_SUCCESS(err);
8000
8001 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008002 dsl_binding.binding = 0;
8003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8004 dsl_binding.descriptorCount = 1;
8005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008006
8007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8009 ds_layout_ci.bindingCount = 1;
8010 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008011
8012 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008014 ASSERT_VK_SUCCESS(err);
8015
8016 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008017 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008018 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008019 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008020 alloc_info.descriptorPool = ds_pool;
8021 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008023 ASSERT_VK_SUCCESS(err);
8024
8025 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008026 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8027 pipeline_layout_ci.setLayoutCount = 1;
8028 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008029
8030 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008031 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008032 ASSERT_VK_SUCCESS(err);
8033
8034 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008035 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8036 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008037 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008038 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008039 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008040
8041 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8042 // Set scissor as dynamic to avoid that error
8043 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008044 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8045 dyn_state_ci.dynamicStateCount = 1;
8046 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008047
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008048 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8049 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8050 pipe_ms_state_ci.pNext = NULL;
8051 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8052 pipe_ms_state_ci.sampleShadingEnable = 0;
8053 pipe_ms_state_ci.minSampleShading = 1.0;
8054 pipe_ms_state_ci.pSampleMask = NULL;
8055
Cody Northropeb3a6c12015-10-05 14:44:45 -06008056 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008057 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008060 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8061 // 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 +08008062 shaderStages[0] = vs.GetStageCreateInfo();
8063 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008064
Cody Northropf6622dc2015-10-06 10:33:21 -06008065 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8066 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8067 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008068 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008069 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008070 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008071 vi_ci.pVertexAttributeDescriptions = nullptr;
8072
8073 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8074 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8075 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8076
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008077 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008078 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008079 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008080 rs_ci.pNext = nullptr;
8081
Mark Youngc89c6312016-03-31 16:03:20 -06008082 VkPipelineColorBlendAttachmentState att = {};
8083 att.blendEnable = VK_FALSE;
8084 att.colorWriteMask = 0xf;
8085
Cody Northropf6622dc2015-10-06 10:33:21 -06008086 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8087 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8088 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008089 cb_ci.attachmentCount = 1;
8090 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008091
Tobin Ehlise68360f2015-10-01 11:15:13 -06008092 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8094 gp_ci.stageCount = 2;
8095 gp_ci.pStages = shaderStages;
8096 gp_ci.pVertexInputState = &vi_ci;
8097 gp_ci.pInputAssemblyState = &ia_ci;
8098 gp_ci.pViewportState = &vp_state_ci;
8099 gp_ci.pRasterizationState = &rs_ci;
8100 gp_ci.pColorBlendState = &cb_ci;
8101 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008102 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008103 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8104 gp_ci.layout = pipeline_layout;
8105 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008106
8107 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008108 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008109
8110 VkPipeline pipeline;
8111 VkPipelineCache pipelineCache;
8112
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008114 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008116
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008117 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008118
Tobin Ehlisd332f282015-10-02 11:00:56 -06008119 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008120 // First need to successfully create the PSO from above by setting
8121 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008122 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 -07008123
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008124 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008125 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008127 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008128 m_commandBuffer->BeginCommandBuffer();
8129 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008130 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008131 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008132 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008133 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008134 Draw(1, 0, 0, 0);
8135
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008136 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008137
8138 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8139 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8140 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8141 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008142 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008143}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008144
8145// 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 -07008146// viewportCount
8147TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8148 VkResult err;
8149
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008151
8152 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008153
8154 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008155 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008156 return;
8157 }
8158
Karl Schultz6addd812016-02-02 17:17:23 -07008159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8160
8161 VkDescriptorPoolSize ds_type_count = {};
8162 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8163 ds_type_count.descriptorCount = 1;
8164
8165 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8166 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8167 ds_pool_ci.maxSets = 1;
8168 ds_pool_ci.poolSizeCount = 1;
8169 ds_pool_ci.pPoolSizes = &ds_type_count;
8170
8171 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008173 ASSERT_VK_SUCCESS(err);
8174
8175 VkDescriptorSetLayoutBinding dsl_binding = {};
8176 dsl_binding.binding = 0;
8177 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8178 dsl_binding.descriptorCount = 1;
8179 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8180
8181 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8182 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8183 ds_layout_ci.bindingCount = 1;
8184 ds_layout_ci.pBindings = &dsl_binding;
8185
8186 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008188 ASSERT_VK_SUCCESS(err);
8189
8190 VkDescriptorSet descriptorSet;
8191 VkDescriptorSetAllocateInfo alloc_info = {};
8192 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8193 alloc_info.descriptorSetCount = 1;
8194 alloc_info.descriptorPool = ds_pool;
8195 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008197 ASSERT_VK_SUCCESS(err);
8198
8199 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8200 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8201 pipeline_layout_ci.setLayoutCount = 1;
8202 pipeline_layout_ci.pSetLayouts = &ds_layout;
8203
8204 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008206 ASSERT_VK_SUCCESS(err);
8207
8208 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8209 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8210 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008211 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008212 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008213 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008214
8215 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8216 // Set scissor as dynamic to avoid that error
8217 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8218 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8219 dyn_state_ci.dynamicStateCount = 1;
8220 dyn_state_ci.pDynamicStates = &vp_state;
8221
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008222 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8223 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8224 pipe_ms_state_ci.pNext = NULL;
8225 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8226 pipe_ms_state_ci.sampleShadingEnable = 0;
8227 pipe_ms_state_ci.minSampleShading = 1.0;
8228 pipe_ms_state_ci.pSampleMask = NULL;
8229
Karl Schultz6addd812016-02-02 17:17:23 -07008230 VkPipelineShaderStageCreateInfo shaderStages[2];
8231 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008234 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8235 // 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 -07008236 shaderStages[0] = vs.GetStageCreateInfo();
8237 shaderStages[1] = fs.GetStageCreateInfo();
8238
8239 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8240 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8241 vi_ci.pNext = nullptr;
8242 vi_ci.vertexBindingDescriptionCount = 0;
8243 vi_ci.pVertexBindingDescriptions = nullptr;
8244 vi_ci.vertexAttributeDescriptionCount = 0;
8245 vi_ci.pVertexAttributeDescriptions = nullptr;
8246
8247 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8248 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8249 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8250
8251 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8252 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008253 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008254 rs_ci.pNext = nullptr;
8255
Mark Youngc89c6312016-03-31 16:03:20 -06008256 VkPipelineColorBlendAttachmentState att = {};
8257 att.blendEnable = VK_FALSE;
8258 att.colorWriteMask = 0xf;
8259
Karl Schultz6addd812016-02-02 17:17:23 -07008260 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8261 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8262 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008263 cb_ci.attachmentCount = 1;
8264 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008265
8266 VkGraphicsPipelineCreateInfo gp_ci = {};
8267 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8268 gp_ci.stageCount = 2;
8269 gp_ci.pStages = shaderStages;
8270 gp_ci.pVertexInputState = &vi_ci;
8271 gp_ci.pInputAssemblyState = &ia_ci;
8272 gp_ci.pViewportState = &vp_state_ci;
8273 gp_ci.pRasterizationState = &rs_ci;
8274 gp_ci.pColorBlendState = &cb_ci;
8275 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008276 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008277 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8278 gp_ci.layout = pipeline_layout;
8279 gp_ci.renderPass = renderPass();
8280
8281 VkPipelineCacheCreateInfo pc_ci = {};
8282 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8283
8284 VkPipeline pipeline;
8285 VkPipelineCache pipelineCache;
8286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008287 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008288 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008290
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008291 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008292
8293 // Now hit second fail case where we set scissor w/ different count than PSO
8294 // First need to successfully create the PSO from above by setting
8295 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8297 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008298
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008299 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008300 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008302 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008303 m_commandBuffer->BeginCommandBuffer();
8304 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008305 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008306 VkViewport viewports[1] = {};
8307 viewports[0].width = 8;
8308 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008309 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008310 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 Draw(1, 0, 0, 0);
8312
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008313 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008314
Chia-I Wuf7458c52015-10-26 21:10:41 +08008315 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8316 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8317 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8318 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008319 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008320}
8321
Mark Young7394fdd2016-03-31 14:56:43 -06008322TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8323 VkResult err;
8324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008326
8327 ASSERT_NO_FATAL_FAILURE(InitState());
8328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8329
8330 VkDescriptorPoolSize ds_type_count = {};
8331 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8332 ds_type_count.descriptorCount = 1;
8333
8334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8336 ds_pool_ci.maxSets = 1;
8337 ds_pool_ci.poolSizeCount = 1;
8338 ds_pool_ci.pPoolSizes = &ds_type_count;
8339
8340 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008342 ASSERT_VK_SUCCESS(err);
8343
8344 VkDescriptorSetLayoutBinding dsl_binding = {};
8345 dsl_binding.binding = 0;
8346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8347 dsl_binding.descriptorCount = 1;
8348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8349
8350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8352 ds_layout_ci.bindingCount = 1;
8353 ds_layout_ci.pBindings = &dsl_binding;
8354
8355 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008357 ASSERT_VK_SUCCESS(err);
8358
8359 VkDescriptorSet descriptorSet;
8360 VkDescriptorSetAllocateInfo alloc_info = {};
8361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8362 alloc_info.descriptorSetCount = 1;
8363 alloc_info.descriptorPool = ds_pool;
8364 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008366 ASSERT_VK_SUCCESS(err);
8367
8368 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8369 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8370 pipeline_layout_ci.setLayoutCount = 1;
8371 pipeline_layout_ci.pSetLayouts = &ds_layout;
8372
8373 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008375 ASSERT_VK_SUCCESS(err);
8376
8377 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8378 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8379 vp_state_ci.scissorCount = 1;
8380 vp_state_ci.pScissors = NULL;
8381 vp_state_ci.viewportCount = 1;
8382 vp_state_ci.pViewports = NULL;
8383
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008385 // Set scissor as dynamic to avoid that error
8386 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8387 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8388 dyn_state_ci.dynamicStateCount = 2;
8389 dyn_state_ci.pDynamicStates = dynamic_states;
8390
8391 VkPipelineShaderStageCreateInfo shaderStages[2];
8392 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008394 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8395 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008396 this); // TODO - We shouldn't need a fragment shader
8397 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008398 shaderStages[0] = vs.GetStageCreateInfo();
8399 shaderStages[1] = fs.GetStageCreateInfo();
8400
8401 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8402 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8403 vi_ci.pNext = nullptr;
8404 vi_ci.vertexBindingDescriptionCount = 0;
8405 vi_ci.pVertexBindingDescriptions = nullptr;
8406 vi_ci.vertexAttributeDescriptionCount = 0;
8407 vi_ci.pVertexAttributeDescriptions = nullptr;
8408
8409 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8410 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8411 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8412
8413 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8414 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8415 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008416 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008417
Mark Young47107952016-05-02 15:59:55 -06008418 // Check too low (line width of -1.0f).
8419 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008420
8421 VkPipelineColorBlendAttachmentState att = {};
8422 att.blendEnable = VK_FALSE;
8423 att.colorWriteMask = 0xf;
8424
8425 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8426 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8427 cb_ci.pNext = nullptr;
8428 cb_ci.attachmentCount = 1;
8429 cb_ci.pAttachments = &att;
8430
8431 VkGraphicsPipelineCreateInfo gp_ci = {};
8432 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8433 gp_ci.stageCount = 2;
8434 gp_ci.pStages = shaderStages;
8435 gp_ci.pVertexInputState = &vi_ci;
8436 gp_ci.pInputAssemblyState = &ia_ci;
8437 gp_ci.pViewportState = &vp_state_ci;
8438 gp_ci.pRasterizationState = &rs_ci;
8439 gp_ci.pColorBlendState = &cb_ci;
8440 gp_ci.pDynamicState = &dyn_state_ci;
8441 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8442 gp_ci.layout = pipeline_layout;
8443 gp_ci.renderPass = renderPass();
8444
8445 VkPipelineCacheCreateInfo pc_ci = {};
8446 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8447
8448 VkPipeline pipeline;
8449 VkPipelineCache pipelineCache;
8450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008452 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008453 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008454
8455 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008456 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008457
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008459
8460 // Check too high (line width of 65536.0f).
8461 rs_ci.lineWidth = 65536.0f;
8462
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008464 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008466
8467 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008468 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008471
8472 dyn_state_ci.dynamicStateCount = 3;
8473
8474 rs_ci.lineWidth = 1.0f;
8475
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008477 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008479 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008480 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008481
8482 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008483 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008484 m_errorMonitor->VerifyFound();
8485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008487
8488 // Check too high with dynamic setting.
8489 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8490 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008491 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008492
8493 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8494 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8495 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008497 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008498}
8499
Karl Schultz6addd812016-02-02 17:17:23 -07008500TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008501 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008503 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008504
8505 ASSERT_NO_FATAL_FAILURE(InitState());
8506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008507
Tony Barbour552f6c02016-12-21 14:34:07 -07008508 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008509 // Don't care about RenderPass handle b/c error should be flagged before
8510 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008511 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008512
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008513 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008514}
8515
Karl Schultz6addd812016-02-02 17:17:23 -07008516TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008517 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8519 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008520
8521 ASSERT_NO_FATAL_FAILURE(InitState());
8522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008523
Tony Barbour552f6c02016-12-21 14:34:07 -07008524 m_commandBuffer->BeginCommandBuffer();
8525 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008526 // Just create a dummy Renderpass that's non-NULL so we can get to the
8527 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008530 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008531}
8532
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008533TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008534 TEST_DESCRIPTION(
8535 "Begin a renderPass where clearValueCount is less than"
8536 "the number of renderPass attachments that use loadOp"
8537 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008538
8539 ASSERT_NO_FATAL_FAILURE(InitState());
8540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8541
8542 // Create a renderPass with a single attachment that uses loadOp CLEAR
8543 VkAttachmentReference attach = {};
8544 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8545 VkSubpassDescription subpass = {};
8546 subpass.inputAttachmentCount = 1;
8547 subpass.pInputAttachments = &attach;
8548 VkRenderPassCreateInfo rpci = {};
8549 rpci.subpassCount = 1;
8550 rpci.pSubpasses = &subpass;
8551 rpci.attachmentCount = 1;
8552 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008553 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008554 // Set loadOp to CLEAR
8555 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8556 rpci.pAttachments = &attach_desc;
8557 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8558 VkRenderPass rp;
8559 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8560
8561 VkCommandBufferInheritanceInfo hinfo = {};
8562 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8563 hinfo.renderPass = VK_NULL_HANDLE;
8564 hinfo.subpass = 0;
8565 hinfo.framebuffer = VK_NULL_HANDLE;
8566 hinfo.occlusionQueryEnable = VK_FALSE;
8567 hinfo.queryFlags = 0;
8568 hinfo.pipelineStatistics = 0;
8569 VkCommandBufferBeginInfo info = {};
8570 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8571 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8572 info.pInheritanceInfo = &hinfo;
8573
8574 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8575 VkRenderPassBeginInfo rp_begin = {};
8576 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8577 rp_begin.pNext = NULL;
8578 rp_begin.renderPass = renderPass();
8579 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008580 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008581
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008584 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008585
8586 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008587
8588 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008589}
8590
Slawomir Cygan0808f392016-11-28 17:53:23 +01008591TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008592 TEST_DESCRIPTION(
8593 "Begin a renderPass where clearValueCount is greater than"
8594 "the number of renderPass attachments that use loadOp"
8595 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008596
8597 ASSERT_NO_FATAL_FAILURE(InitState());
8598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8599
8600 // Create a renderPass with a single attachment that uses loadOp CLEAR
8601 VkAttachmentReference attach = {};
8602 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8603 VkSubpassDescription subpass = {};
8604 subpass.inputAttachmentCount = 1;
8605 subpass.pInputAttachments = &attach;
8606 VkRenderPassCreateInfo rpci = {};
8607 rpci.subpassCount = 1;
8608 rpci.pSubpasses = &subpass;
8609 rpci.attachmentCount = 1;
8610 VkAttachmentDescription attach_desc = {};
8611 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8612 // Set loadOp to CLEAR
8613 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8614 rpci.pAttachments = &attach_desc;
8615 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8616 VkRenderPass rp;
8617 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8618
8619 VkCommandBufferBeginInfo info = {};
8620 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8621 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8622
8623 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8624 VkRenderPassBeginInfo rp_begin = {};
8625 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8626 rp_begin.pNext = NULL;
8627 rp_begin.renderPass = renderPass();
8628 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008629 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008630
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8632 " has a clearValueCount of"
8633 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008634
8635 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8636
8637 m_errorMonitor->VerifyFound();
8638
8639 vkDestroyRenderPass(m_device->device(), rp, NULL);
8640}
8641
Cody Northrop3bb4d962016-05-09 16:15:57 -06008642TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008643 TEST_DESCRIPTION("End a command buffer with an active render pass");
8644
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8646 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008647
8648 ASSERT_NO_FATAL_FAILURE(InitState());
8649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8650
Tony Barbour552f6c02016-12-21 14:34:07 -07008651 m_commandBuffer->BeginCommandBuffer();
8652 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8653 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008654
8655 m_errorMonitor->VerifyFound();
8656
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008657 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8658 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008659}
8660
Karl Schultz6addd812016-02-02 17:17:23 -07008661TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008662 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8664 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008665
8666 ASSERT_NO_FATAL_FAILURE(InitState());
8667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008668
Tony Barbour552f6c02016-12-21 14:34:07 -07008669 m_commandBuffer->BeginCommandBuffer();
8670 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008671
8672 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008673 vk_testing::Buffer dstBuffer;
8674 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008675
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008676 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008678 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679}
8680
Karl Schultz6addd812016-02-02 17:17:23 -07008681TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8684 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008685
8686 ASSERT_NO_FATAL_FAILURE(InitState());
8687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Tony Barbour552f6c02016-12-21 14:34:07 -07008689 m_commandBuffer->BeginCommandBuffer();
8690 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691
8692 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008693 vk_testing::Buffer dstBuffer;
8694 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008695
Karl Schultz6addd812016-02-02 17:17:23 -07008696 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008697 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8698 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8699 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008700
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008701 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702}
8703
Karl Schultz6addd812016-02-02 17:17:23 -07008704TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008705 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8707 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008708
8709 ASSERT_NO_FATAL_FAILURE(InitState());
8710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Tony Barbour552f6c02016-12-21 14:34:07 -07008712 m_commandBuffer->BeginCommandBuffer();
8713 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008714
Michael Lentine0a369f62016-02-03 16:51:46 -06008715 VkClearColorValue clear_color;
8716 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008717 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8718 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8719 const int32_t tex_width = 32;
8720 const int32_t tex_height = 32;
8721 VkImageCreateInfo image_create_info = {};
8722 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8723 image_create_info.pNext = NULL;
8724 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8725 image_create_info.format = tex_format;
8726 image_create_info.extent.width = tex_width;
8727 image_create_info.extent.height = tex_height;
8728 image_create_info.extent.depth = 1;
8729 image_create_info.mipLevels = 1;
8730 image_create_info.arrayLayers = 1;
8731 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8732 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8733 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008734
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008735 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008736 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008739
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008740 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008741 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008743 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008744}
8745
Karl Schultz6addd812016-02-02 17:17:23 -07008746TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8749 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
8751 ASSERT_NO_FATAL_FAILURE(InitState());
8752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008753
Tony Barbourf887b162017-03-09 10:06:46 -07008754 auto depth_format = find_depth_stencil_format(m_device);
8755 if (!depth_format) {
8756 printf(" No Depth + Stencil format found. Skipped.\n");
8757 return;
8758 }
8759
Tony Barbour552f6c02016-12-21 14:34:07 -07008760 m_commandBuffer->BeginCommandBuffer();
8761 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762
8763 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008764 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008765 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8766 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008767 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008768 image_create_info.extent.width = 64;
8769 image_create_info.extent.height = 64;
8770 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8771 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008773 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008774 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008777
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008778 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8779 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008781 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782}
8783
Karl Schultz6addd812016-02-02 17:17:23 -07008784TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008785 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008786 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8789 "vkCmdClearAttachments(): This call "
8790 "must be issued inside an active "
8791 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008792
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008793 ASSERT_NO_FATAL_FAILURE(InitState());
8794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008795
8796 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008797 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008798 ASSERT_VK_SUCCESS(err);
8799
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008800 VkClearAttachment color_attachment;
8801 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8802 color_attachment.clearValue.color.float32[0] = 0;
8803 color_attachment.clearValue.color.float32[1] = 0;
8804 color_attachment.clearValue.color.float32[2] = 0;
8805 color_attachment.clearValue.color.float32[3] = 0;
8806 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008807 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008808 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008809
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008810 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008811}
8812
Chris Forbes3b97e932016-09-07 11:29:24 +12008813TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008814 TEST_DESCRIPTION(
8815 "Test that an error is produced when CmdNextSubpass is "
8816 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008817
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8819 "vkCmdNextSubpass(): Attempted to advance "
8820 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008821
8822 ASSERT_NO_FATAL_FAILURE(InitState());
8823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8824
Tony Barbour552f6c02016-12-21 14:34:07 -07008825 m_commandBuffer->BeginCommandBuffer();
8826 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
8828 // error here.
8829 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8830 m_errorMonitor->VerifyFound();
8831
Tony Barbour552f6c02016-12-21 14:34:07 -07008832 m_commandBuffer->EndRenderPass();
8833 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008834}
8835
Chris Forbes6d624702016-09-07 13:57:05 +12008836TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008837 TEST_DESCRIPTION(
8838 "Test that an error is produced when CmdEndRenderPass is "
8839 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8842 "vkCmdEndRenderPass(): Called before reaching "
8843 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008844
8845 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8847 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008850
8851 VkRenderPass rp;
8852 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8853 ASSERT_VK_SUCCESS(err);
8854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008856
8857 VkFramebuffer fb;
8858 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8859 ASSERT_VK_SUCCESS(err);
8860
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008861 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008863 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008864
8865 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8866
8867 // Error here.
8868 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8869 m_errorMonitor->VerifyFound();
8870
8871 // Clean up.
8872 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8873 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8874}
8875
Karl Schultz9e66a292016-04-21 15:57:51 -06008876TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8877 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8879 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008880
8881 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008882 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008883
8884 VkBufferMemoryBarrier buf_barrier = {};
8885 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8886 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8887 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8888 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8889 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8890 buf_barrier.buffer = VK_NULL_HANDLE;
8891 buf_barrier.offset = 0;
8892 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008893 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8894 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008895
8896 m_errorMonitor->VerifyFound();
8897}
8898
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899TEST_F(VkLayerTest, InvalidBarriers) {
8900 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008903
8904 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008905 auto depth_format = find_depth_stencil_format(m_device);
8906 if (!depth_format) {
8907 printf(" No Depth + Stencil format found. Skipped.\n");
8908 return;
8909 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8911
8912 VkMemoryBarrier mem_barrier = {};
8913 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8914 mem_barrier.pNext = NULL;
8915 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8916 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008917 m_commandBuffer->BeginCommandBuffer();
8918 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008919 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008920 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008921 &mem_barrier, 0, nullptr, 0, nullptr);
8922 m_errorMonitor->VerifyFound();
8923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008925 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008927 ASSERT_TRUE(image.initialized());
8928 VkImageMemoryBarrier img_barrier = {};
8929 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8930 img_barrier.pNext = NULL;
8931 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8932 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8933 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8934 // New layout can't be UNDEFINED
8935 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8936 img_barrier.image = image.handle();
8937 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8938 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8939 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8940 img_barrier.subresourceRange.baseArrayLayer = 0;
8941 img_barrier.subresourceRange.baseMipLevel = 0;
8942 img_barrier.subresourceRange.layerCount = 1;
8943 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008944 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8945 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008946 m_errorMonitor->VerifyFound();
8947 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8948
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8950 "Subresource must have the sum of the "
8951 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008952 // baseArrayLayer + layerCount must be <= image's arrayLayers
8953 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8955 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008956 m_errorMonitor->VerifyFound();
8957 img_barrier.subresourceRange.baseArrayLayer = 0;
8958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008960 // baseMipLevel + levelCount must be <= image's mipLevels
8961 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008962 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8963 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008964 m_errorMonitor->VerifyFound();
8965 img_barrier.subresourceRange.baseMipLevel = 0;
8966
Mike Weiblen7053aa32017-01-25 15:21:10 -07008967 // levelCount must be non-zero.
8968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8969 img_barrier.subresourceRange.levelCount = 0;
8970 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8971 nullptr, 0, nullptr, 1, &img_barrier);
8972 m_errorMonitor->VerifyFound();
8973 img_barrier.subresourceRange.levelCount = 1;
8974
8975 // layerCount must be non-zero.
8976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8977 img_barrier.subresourceRange.layerCount = 0;
8978 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8979 nullptr, 0, nullptr, 1, &img_barrier);
8980 m_errorMonitor->VerifyFound();
8981 img_barrier.subresourceRange.layerCount = 1;
8982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008984 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008985 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8986 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008987 VkBufferMemoryBarrier buf_barrier = {};
8988 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8989 buf_barrier.pNext = NULL;
8990 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8991 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8992 buf_barrier.buffer = buffer.handle();
8993 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8994 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8995 buf_barrier.offset = 0;
8996 buf_barrier.size = VK_WHOLE_SIZE;
8997 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8999 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009000 m_errorMonitor->VerifyFound();
9001 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009004 buf_barrier.offset = 257;
9005 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009006 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9007 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009008 m_errorMonitor->VerifyFound();
9009 buf_barrier.offset = 0;
9010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009012 buf_barrier.size = 257;
9013 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9015 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009016 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009017
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009018 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009019 m_errorMonitor->SetDesiredFailureMsg(
9020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009021 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009023 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009024 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009025 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9026 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009028
9029 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009030 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009031 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9032 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009033 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009034
9035 // Having anything other than DEPTH or STENCIL is an error
9036 m_errorMonitor->SetDesiredFailureMsg(
9037 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9038 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9039 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9040 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9041 nullptr, 0, nullptr, 1, &img_barrier);
9042 m_errorMonitor->VerifyFound();
9043
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009044 // Now test depth-only
9045 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009046 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9047 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009048 VkDepthStencilObj d_image(m_device);
9049 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9050 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009052 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009053 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009054
9055 // DEPTH bit must be set
9056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9057 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009058 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009059 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9060 0, nullptr, 0, nullptr, 1, &img_barrier);
9061 m_errorMonitor->VerifyFound();
9062
9063 // No bits other than DEPTH may be set
9064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9065 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009067 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9068 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009069 m_errorMonitor->VerifyFound();
9070 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009071
9072 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9074 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009075 VkDepthStencilObj s_image(m_device);
9076 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9077 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009079 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009080 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009081 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9083 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009084 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009085 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9086 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009087 m_errorMonitor->VerifyFound();
9088 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009089
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009091 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009092 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009093 ASSERT_TRUE(c_image.initialized());
9094 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9095 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9096 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009097
9098 // COLOR bit must be set
9099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9100 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009101 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009102 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9103 nullptr, 0, nullptr, 1, &img_barrier);
9104 m_errorMonitor->VerifyFound();
9105
9106 // No bits other than COLOR may be set
9107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9108 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9109 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009110 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9111 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009112 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009113
9114 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9115
9116 // Create command pool with incompatible queueflags
9117 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9118 uint32_t queue_family_index = UINT32_MAX;
9119 for (uint32_t i = 0; i < queue_props.size(); i++) {
9120 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9121 queue_family_index = i;
9122 break;
9123 }
9124 }
9125 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009126 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009127 return;
9128 }
9129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9130
9131 VkCommandPool command_pool;
9132 VkCommandPoolCreateInfo pool_create_info{};
9133 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9134 pool_create_info.queueFamilyIndex = queue_family_index;
9135 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9136 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9137
9138 // Allocate a command buffer
9139 VkCommandBuffer bad_command_buffer;
9140 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9141 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9142 command_buffer_allocate_info.commandPool = command_pool;
9143 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9144 command_buffer_allocate_info.commandBufferCount = 1;
9145 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9146
9147 VkCommandBufferBeginInfo cbbi = {};
9148 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9149 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9150 buf_barrier.offset = 0;
9151 buf_barrier.size = VK_WHOLE_SIZE;
9152 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9153 &buf_barrier, 0, nullptr);
9154 m_errorMonitor->VerifyFound();
9155
9156 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9157 vkEndCommandBuffer(bad_command_buffer);
9158 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009159 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009160 return;
9161 }
9162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9163 VkEvent event;
9164 VkEventCreateInfo event_create_info{};
9165 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9166 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9167 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9168 nullptr, 0, nullptr);
9169 m_errorMonitor->VerifyFound();
9170
9171 vkEndCommandBuffer(bad_command_buffer);
9172 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009173}
9174
Tony Barbour18ba25c2016-09-29 13:42:40 -06009175TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9176 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9177
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009179 ASSERT_NO_FATAL_FAILURE(InitState());
9180 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009181 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009182 ASSERT_TRUE(image.initialized());
9183
9184 VkImageMemoryBarrier barrier = {};
9185 VkImageSubresourceRange range;
9186 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9187 barrier.srcAccessMask = 0;
9188 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9189 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9190 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9191 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9192 barrier.image = image.handle();
9193 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9194 range.baseMipLevel = 0;
9195 range.levelCount = 1;
9196 range.baseArrayLayer = 0;
9197 range.layerCount = 1;
9198 barrier.subresourceRange = range;
9199 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9200 cmdbuf.BeginCommandBuffer();
9201 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9202 &barrier);
9203 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9204 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9205 barrier.srcAccessMask = 0;
9206 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9207 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9208 &barrier);
9209
9210 m_errorMonitor->VerifyFound();
9211}
9212
Karl Schultz6addd812016-02-02 17:17:23 -07009213TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009214 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009215 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009218
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009219 ASSERT_NO_FATAL_FAILURE(InitState());
9220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009221 uint32_t qfi = 0;
9222 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009223 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9224 buffCI.size = 1024;
9225 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9226 buffCI.queueFamilyIndexCount = 1;
9227 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009228
9229 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009230 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009231 ASSERT_VK_SUCCESS(err);
9232
Tony Barbour552f6c02016-12-21 14:34:07 -07009233 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009234 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009235 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9236 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009237 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009238 m_errorMonitor->SetUnexpectedError(
9239 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009241
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009242 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009243
Chia-I Wuf7458c52015-10-26 21:10:41 +08009244 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009245}
9246
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009247TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9248 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9250 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9251 "of the indices specified when the device was created, via the "
9252 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009253
9254 ASSERT_NO_FATAL_FAILURE(InitState());
9255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9256 VkBufferCreateInfo buffCI = {};
9257 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9258 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009259 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009260 buffCI.queueFamilyIndexCount = 1;
9261 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009262 uint32_t qfi[2];
9263 qfi[0] = 777;
9264
9265 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009266 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009267
9268 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009269 m_errorMonitor->SetUnexpectedError(
9270 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009271 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009273 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009274
9275 if (m_device->queue_props.size() > 2) {
9276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9277
9278 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9279 buffCI.queueFamilyIndexCount = 2;
9280 qfi[0] = 1;
9281 qfi[1] = 2;
9282 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9283 VkDeviceMemory mem;
9284 VkMemoryRequirements mem_reqs;
9285 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9286
9287 VkMemoryAllocateInfo alloc_info = {};
9288 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9289 alloc_info.allocationSize = 1024;
9290 bool pass = false;
9291 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9292 if (!pass) {
9293 vkDestroyBuffer(m_device->device(), ib, NULL);
9294 return;
9295 }
9296 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9297 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9298
9299 m_commandBuffer->begin();
9300 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9301 m_commandBuffer->end();
9302 QueueCommandBuffer(false);
9303 m_errorMonitor->VerifyFound();
9304 }
9305
Tony Barbourdf4c0042016-06-01 15:55:43 -06009306 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009307}
9308
Karl Schultz6addd812016-02-02 17:17:23 -07009309TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009310 TEST_DESCRIPTION(
9311 "Attempt vkCmdExecuteCommands with a primary command buffer"
9312 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009313
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009314 ASSERT_NO_FATAL_FAILURE(InitState());
9315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009316
Chris Forbesf29a84f2016-10-06 18:39:28 +13009317 // An empty primary command buffer
9318 VkCommandBufferObj cb(m_device, m_commandPool);
9319 cb.BeginCommandBuffer();
9320 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009321
Chris Forbesf29a84f2016-10-06 18:39:28 +13009322 m_commandBuffer->BeginCommandBuffer();
9323 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9324 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009325
Chris Forbesf29a84f2016-10-06 18:39:28 +13009326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9327 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009328 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009329
9330 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009331}
9332
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009333TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009334 TEST_DESCRIPTION(
9335 "Attempt to update descriptor sets for images and buffers "
9336 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009337 VkResult err;
9338
9339 ASSERT_NO_FATAL_FAILURE(InitState());
9340 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9341 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9342 ds_type_count[i].type = VkDescriptorType(i);
9343 ds_type_count[i].descriptorCount = 1;
9344 }
9345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9347 ds_pool_ci.pNext = NULL;
9348 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9349 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9350 ds_pool_ci.pPoolSizes = ds_type_count;
9351
9352 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009354 ASSERT_VK_SUCCESS(err);
9355
9356 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009357 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009358 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9359 dsl_binding[i].binding = 0;
9360 dsl_binding[i].descriptorType = VkDescriptorType(i);
9361 dsl_binding[i].descriptorCount = 1;
9362 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9363 dsl_binding[i].pImmutableSamplers = NULL;
9364 }
9365
9366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9368 ds_layout_ci.pNext = NULL;
9369 ds_layout_ci.bindingCount = 1;
9370 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9371 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9372 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009374 ASSERT_VK_SUCCESS(err);
9375 }
9376 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9377 VkDescriptorSetAllocateInfo alloc_info = {};
9378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9379 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9380 alloc_info.descriptorPool = ds_pool;
9381 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009383 ASSERT_VK_SUCCESS(err);
9384
9385 // Create a buffer & bufferView to be used for invalid updates
9386 VkBufferCreateInfo buff_ci = {};
9387 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009388 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009389 buff_ci.size = 256;
9390 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009391 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009392 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9393 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009394
9395 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9396 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9397 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9398 ASSERT_VK_SUCCESS(err);
9399
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009400 VkMemoryRequirements mem_reqs;
9401 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9402 VkMemoryAllocateInfo mem_alloc_info = {};
9403 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9404 mem_alloc_info.pNext = NULL;
9405 mem_alloc_info.memoryTypeIndex = 0;
9406 mem_alloc_info.allocationSize = mem_reqs.size;
9407 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9408 if (!pass) {
9409 vkDestroyBuffer(m_device->device(), buffer, NULL);
9410 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9411 return;
9412 }
9413 VkDeviceMemory mem;
9414 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9415 ASSERT_VK_SUCCESS(err);
9416 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9417 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009418
9419 VkBufferViewCreateInfo buff_view_ci = {};
9420 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9421 buff_view_ci.buffer = buffer;
9422 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9423 buff_view_ci.range = VK_WHOLE_SIZE;
9424 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009425 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009426 ASSERT_VK_SUCCESS(err);
9427
Tony Barbour415497c2017-01-24 10:06:09 -07009428 // Now get resources / view for storage_texel_buffer
9429 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9431 if (!pass) {
9432 vkDestroyBuffer(m_device->device(), buffer, NULL);
9433 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9434 vkFreeMemory(m_device->device(), mem, NULL);
9435 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9437 return;
9438 }
9439 VkDeviceMemory storage_texel_buffer_mem;
9440 VkBufferView storage_texel_buffer_view;
9441 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9442 ASSERT_VK_SUCCESS(err);
9443 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9444 ASSERT_VK_SUCCESS(err);
9445 buff_view_ci.buffer = storage_texel_buffer;
9446 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9447 ASSERT_VK_SUCCESS(err);
9448
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009449 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009450 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009451 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009452 image_ci.format = VK_FORMAT_UNDEFINED;
9453 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9454 VkFormat format = static_cast<VkFormat>(f);
9455 VkFormatProperties fProps = m_device->format_properties(format);
9456 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9457 image_ci.format = format;
9458 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9459 break;
9460 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9461 image_ci.format = format;
9462 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9463 break;
9464 }
9465 }
9466 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9467 return;
9468 }
9469
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009470 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9471 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009472 image_ci.extent.width = 64;
9473 image_ci.extent.height = 64;
9474 image_ci.extent.depth = 1;
9475 image_ci.mipLevels = 1;
9476 image_ci.arrayLayers = 1;
9477 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009478 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009479 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009480 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9481 VkImage image;
9482 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9483 ASSERT_VK_SUCCESS(err);
9484 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009486
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009487 VkMemoryAllocateInfo mem_alloc = {};
9488 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9489 mem_alloc.pNext = NULL;
9490 mem_alloc.allocationSize = 0;
9491 mem_alloc.memoryTypeIndex = 0;
9492 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9493 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 ASSERT_TRUE(pass);
9496 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9497 ASSERT_VK_SUCCESS(err);
9498 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9499 ASSERT_VK_SUCCESS(err);
9500 // Now create view for image
9501 VkImageViewCreateInfo image_view_ci = {};
9502 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9503 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009504 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009505 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9506 image_view_ci.subresourceRange.layerCount = 1;
9507 image_view_ci.subresourceRange.baseArrayLayer = 0;
9508 image_view_ci.subresourceRange.levelCount = 1;
9509 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9510 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009511 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009512 ASSERT_VK_SUCCESS(err);
9513
9514 VkDescriptorBufferInfo buff_info = {};
9515 buff_info.buffer = buffer;
9516 VkDescriptorImageInfo img_info = {};
9517 img_info.imageView = image_view;
9518 VkWriteDescriptorSet descriptor_write = {};
9519 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9520 descriptor_write.dstBinding = 0;
9521 descriptor_write.descriptorCount = 1;
9522 descriptor_write.pTexelBufferView = &buff_view;
9523 descriptor_write.pBufferInfo = &buff_info;
9524 descriptor_write.pImageInfo = &img_info;
9525
9526 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009527 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009528 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9529 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9530 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9531 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9532 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9533 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9534 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9535 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9536 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9537 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9538 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009539 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009540 // Start loop at 1 as SAMPLER desc type has no usage bit error
9541 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009542 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9543 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9544 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9545 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009546 descriptor_write.descriptorType = VkDescriptorType(i);
9547 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009551
9552 m_errorMonitor->VerifyFound();
9553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009554 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9555 descriptor_write.pTexelBufferView = &buff_view;
9556 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009557 }
Tony Barbour415497c2017-01-24 10:06:09 -07009558
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009559 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9560 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009561 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009562 vkDestroyImageView(m_device->device(), image_view, NULL);
9563 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009564 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009565 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009566 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009567 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009568 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009569 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9570}
9571
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009572TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009573 TEST_DESCRIPTION(
9574 "Attempt to update buffer descriptor set that has incorrect "
9575 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9576 "1. offset value greater than buffer size\n"
9577 "2. range value of 0\n"
9578 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009579 VkResult err;
9580
9581 ASSERT_NO_FATAL_FAILURE(InitState());
9582 VkDescriptorPoolSize ds_type_count = {};
9583 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9584 ds_type_count.descriptorCount = 1;
9585
9586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9588 ds_pool_ci.pNext = NULL;
9589 ds_pool_ci.maxSets = 1;
9590 ds_pool_ci.poolSizeCount = 1;
9591 ds_pool_ci.pPoolSizes = &ds_type_count;
9592
9593 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009594 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009595 ASSERT_VK_SUCCESS(err);
9596
9597 // Create layout with single uniform buffer descriptor
9598 VkDescriptorSetLayoutBinding dsl_binding = {};
9599 dsl_binding.binding = 0;
9600 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9601 dsl_binding.descriptorCount = 1;
9602 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9603 dsl_binding.pImmutableSamplers = NULL;
9604
9605 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9606 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9607 ds_layout_ci.pNext = NULL;
9608 ds_layout_ci.bindingCount = 1;
9609 ds_layout_ci.pBindings = &dsl_binding;
9610 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009612 ASSERT_VK_SUCCESS(err);
9613
9614 VkDescriptorSet descriptor_set = {};
9615 VkDescriptorSetAllocateInfo alloc_info = {};
9616 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9617 alloc_info.descriptorSetCount = 1;
9618 alloc_info.descriptorPool = ds_pool;
9619 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009620 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009621 ASSERT_VK_SUCCESS(err);
9622
9623 // Create a buffer to be used for invalid updates
9624 VkBufferCreateInfo buff_ci = {};
9625 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9626 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9627 buff_ci.size = 256;
9628 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9629 VkBuffer buffer;
9630 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9631 ASSERT_VK_SUCCESS(err);
9632 // Have to bind memory to buffer before descriptor update
9633 VkMemoryAllocateInfo mem_alloc = {};
9634 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9635 mem_alloc.pNext = NULL;
9636 mem_alloc.allocationSize = 256;
9637 mem_alloc.memoryTypeIndex = 0;
9638
9639 VkMemoryRequirements mem_reqs;
9640 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009641 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009642 if (!pass) {
9643 vkDestroyBuffer(m_device->device(), buffer, NULL);
9644 return;
9645 }
9646
9647 VkDeviceMemory mem;
9648 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9649 ASSERT_VK_SUCCESS(err);
9650 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9651 ASSERT_VK_SUCCESS(err);
9652
9653 VkDescriptorBufferInfo buff_info = {};
9654 buff_info.buffer = buffer;
9655 // First make offset 1 larger than buffer size
9656 buff_info.offset = 257;
9657 buff_info.range = VK_WHOLE_SIZE;
9658 VkWriteDescriptorSet descriptor_write = {};
9659 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9660 descriptor_write.dstBinding = 0;
9661 descriptor_write.descriptorCount = 1;
9662 descriptor_write.pTexelBufferView = nullptr;
9663 descriptor_write.pBufferInfo = &buff_info;
9664 descriptor_write.pImageInfo = nullptr;
9665
9666 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9667 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009669
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009670 m_errorMonitor->SetUnexpectedError(
9671 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9672 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009673 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9674
9675 m_errorMonitor->VerifyFound();
9676 // Now cause error due to range of 0
9677 buff_info.offset = 0;
9678 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009680
9681 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9682
9683 m_errorMonitor->VerifyFound();
9684 // Now cause error due to range exceeding buffer size - offset
9685 buff_info.offset = 128;
9686 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009688
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009689 m_errorMonitor->SetUnexpectedError(
9690 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9691 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9693
9694 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009695 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009696 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9697 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009698 m_errorMonitor->SetUnexpectedError(
9699 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009700 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9701 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9702}
9703
Tobin Ehlis845887e2017-02-02 19:01:44 -07009704TEST_F(VkLayerTest, DSBufferLimitErrors) {
9705 TEST_DESCRIPTION(
9706 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9707 "Test cases include:\n"
9708 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9709 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9710 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9711 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9712 VkResult err;
9713
9714 ASSERT_NO_FATAL_FAILURE(InitState());
9715 VkDescriptorPoolSize ds_type_count[2] = {};
9716 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9717 ds_type_count[0].descriptorCount = 1;
9718 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9719 ds_type_count[1].descriptorCount = 1;
9720
9721 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9722 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9723 ds_pool_ci.pNext = NULL;
9724 ds_pool_ci.maxSets = 1;
9725 ds_pool_ci.poolSizeCount = 2;
9726 ds_pool_ci.pPoolSizes = ds_type_count;
9727
9728 VkDescriptorPool ds_pool;
9729 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9730 ASSERT_VK_SUCCESS(err);
9731
9732 // Create layout with single uniform buffer & single storage buffer descriptor
9733 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9734 dsl_binding[0].binding = 0;
9735 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9736 dsl_binding[0].descriptorCount = 1;
9737 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9738 dsl_binding[0].pImmutableSamplers = NULL;
9739 dsl_binding[1].binding = 1;
9740 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9741 dsl_binding[1].descriptorCount = 1;
9742 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9743 dsl_binding[1].pImmutableSamplers = NULL;
9744
9745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9747 ds_layout_ci.pNext = NULL;
9748 ds_layout_ci.bindingCount = 2;
9749 ds_layout_ci.pBindings = dsl_binding;
9750 VkDescriptorSetLayout ds_layout;
9751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9752 ASSERT_VK_SUCCESS(err);
9753
9754 VkDescriptorSet descriptor_set = {};
9755 VkDescriptorSetAllocateInfo alloc_info = {};
9756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9757 alloc_info.descriptorSetCount = 1;
9758 alloc_info.descriptorPool = ds_pool;
9759 alloc_info.pSetLayouts = &ds_layout;
9760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9761 ASSERT_VK_SUCCESS(err);
9762
9763 // Create a buffer to be used for invalid updates
9764 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9765 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9766 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9767 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9768 VkBufferCreateInfo ub_ci = {};
9769 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9770 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9771 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9772 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9773 VkBuffer uniform_buffer;
9774 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9775 ASSERT_VK_SUCCESS(err);
9776 VkBufferCreateInfo sb_ci = {};
9777 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9778 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9779 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9780 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9781 VkBuffer storage_buffer;
9782 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9783 ASSERT_VK_SUCCESS(err);
9784 // Have to bind memory to buffer before descriptor update
9785 VkMemoryAllocateInfo mem_alloc = {};
9786 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9787 mem_alloc.pNext = NULL;
9788 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9789 mem_alloc.memoryTypeIndex = 0;
9790
Cort Stratton77a0d592017-02-17 13:14:13 -08009791 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9792 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9793 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9794 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9795 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009796 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009798 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009799 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009801 return;
9802 }
9803
9804 VkDeviceMemory mem;
9805 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009806 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009807 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009808 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9809 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9810 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9811 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9812 return;
9813 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009814 ASSERT_VK_SUCCESS(err);
9815 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9816 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009817 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009818 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9819 ASSERT_VK_SUCCESS(err);
9820
9821 VkDescriptorBufferInfo buff_info = {};
9822 buff_info.buffer = uniform_buffer;
9823 buff_info.range = ub_ci.size; // This will exceed limit
9824 VkWriteDescriptorSet descriptor_write = {};
9825 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9826 descriptor_write.dstBinding = 0;
9827 descriptor_write.descriptorCount = 1;
9828 descriptor_write.pTexelBufferView = nullptr;
9829 descriptor_write.pBufferInfo = &buff_info;
9830 descriptor_write.pImageInfo = nullptr;
9831
9832 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9833 descriptor_write.dstSet = descriptor_set;
9834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9835 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9836 m_errorMonitor->VerifyFound();
9837
9838 // Reduce size of range to acceptable limit & cause offset error
9839 buff_info.range = max_ub_range;
9840 buff_info.offset = min_ub_align - 1;
9841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9842 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9843 m_errorMonitor->VerifyFound();
9844
9845 // Now break storage updates
9846 buff_info.buffer = storage_buffer;
9847 buff_info.range = sb_ci.size; // This will exceed limit
9848 buff_info.offset = 0; // Reset offset for this update
9849
9850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9851 descriptor_write.dstBinding = 1;
9852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9854 m_errorMonitor->VerifyFound();
9855
9856 // Reduce size of range to acceptable limit & cause offset error
9857 buff_info.range = max_sb_range;
9858 buff_info.offset = min_sb_align - 1;
9859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9861 m_errorMonitor->VerifyFound();
9862
9863 vkFreeMemory(m_device->device(), mem, NULL);
9864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9865 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9866 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9867 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9868}
9869
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009870TEST_F(VkLayerTest, DSAspectBitsErrors) {
9871 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9872 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009873 TEST_DESCRIPTION(
9874 "Attempt to update descriptor sets for images "
9875 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009876 VkResult err;
9877
9878 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009879 auto depth_format = find_depth_stencil_format(m_device);
9880 if (!depth_format) {
9881 printf(" No Depth + Stencil format found. Skipped.\n");
9882 return;
9883 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009884 VkDescriptorPoolSize ds_type_count = {};
9885 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9886 ds_type_count.descriptorCount = 1;
9887
9888 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9889 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9890 ds_pool_ci.pNext = NULL;
9891 ds_pool_ci.maxSets = 5;
9892 ds_pool_ci.poolSizeCount = 1;
9893 ds_pool_ci.pPoolSizes = &ds_type_count;
9894
9895 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009897 ASSERT_VK_SUCCESS(err);
9898
9899 VkDescriptorSetLayoutBinding dsl_binding = {};
9900 dsl_binding.binding = 0;
9901 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9902 dsl_binding.descriptorCount = 1;
9903 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9904 dsl_binding.pImmutableSamplers = NULL;
9905
9906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9908 ds_layout_ci.pNext = NULL;
9909 ds_layout_ci.bindingCount = 1;
9910 ds_layout_ci.pBindings = &dsl_binding;
9911 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009912 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009913 ASSERT_VK_SUCCESS(err);
9914
9915 VkDescriptorSet descriptor_set = {};
9916 VkDescriptorSetAllocateInfo alloc_info = {};
9917 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9918 alloc_info.descriptorSetCount = 1;
9919 alloc_info.descriptorPool = ds_pool;
9920 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009922 ASSERT_VK_SUCCESS(err);
9923
9924 // Create an image to be used for invalid updates
9925 VkImageCreateInfo image_ci = {};
9926 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9927 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009928 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009929 image_ci.extent.width = 64;
9930 image_ci.extent.height = 64;
9931 image_ci.extent.depth = 1;
9932 image_ci.mipLevels = 1;
9933 image_ci.arrayLayers = 1;
9934 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009935 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009936 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9937 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9938 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9939 VkImage image;
9940 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9941 ASSERT_VK_SUCCESS(err);
9942 // Bind memory to image
9943 VkMemoryRequirements mem_reqs;
9944 VkDeviceMemory image_mem;
9945 bool pass;
9946 VkMemoryAllocateInfo mem_alloc = {};
9947 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9948 mem_alloc.pNext = NULL;
9949 mem_alloc.allocationSize = 0;
9950 mem_alloc.memoryTypeIndex = 0;
9951 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9952 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009953 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009954 ASSERT_TRUE(pass);
9955 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9956 ASSERT_VK_SUCCESS(err);
9957 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9958 ASSERT_VK_SUCCESS(err);
9959 // Now create view for image
9960 VkImageViewCreateInfo image_view_ci = {};
9961 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9962 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -07009963 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009964 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9965 image_view_ci.subresourceRange.layerCount = 1;
9966 image_view_ci.subresourceRange.baseArrayLayer = 0;
9967 image_view_ci.subresourceRange.levelCount = 1;
9968 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009969 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009970
9971 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009973 ASSERT_VK_SUCCESS(err);
9974
9975 VkDescriptorImageInfo img_info = {};
9976 img_info.imageView = image_view;
9977 VkWriteDescriptorSet descriptor_write = {};
9978 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9979 descriptor_write.dstBinding = 0;
9980 descriptor_write.descriptorCount = 1;
9981 descriptor_write.pTexelBufferView = NULL;
9982 descriptor_write.pBufferInfo = NULL;
9983 descriptor_write.pImageInfo = &img_info;
9984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9985 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009986 const char *error_msg =
9987 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9988 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009990
9991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9992
9993 m_errorMonitor->VerifyFound();
9994 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9995 vkDestroyImage(m_device->device(), image, NULL);
9996 vkFreeMemory(m_device->device(), image_mem, NULL);
9997 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009998 m_errorMonitor->SetUnexpectedError(
9999 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010000 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10002}
10003
Karl Schultz6addd812016-02-02 17:17:23 -070010004TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010005 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010006 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10009 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10010 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010011
Tobin Ehlis3b780662015-05-28 12:11:26 -060010012 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010013 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010014 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10016 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010017
10018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10020 ds_pool_ci.pNext = NULL;
10021 ds_pool_ci.maxSets = 1;
10022 ds_pool_ci.poolSizeCount = 1;
10023 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010024
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010027 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010028 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010029 dsl_binding.binding = 0;
10030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10031 dsl_binding.descriptorCount = 1;
10032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10033 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010034
Tony Barboureb254902015-07-15 12:50:33 -060010035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10037 ds_layout_ci.pNext = NULL;
10038 ds_layout_ci.bindingCount = 1;
10039 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010040
Tobin Ehlis3b780662015-05-28 12:11:26 -060010041 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043 ASSERT_VK_SUCCESS(err);
10044
10045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010048 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010049 alloc_info.descriptorPool = ds_pool;
10050 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010053
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010054 VkSamplerCreateInfo sampler_ci = {};
10055 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10056 sampler_ci.pNext = NULL;
10057 sampler_ci.magFilter = VK_FILTER_NEAREST;
10058 sampler_ci.minFilter = VK_FILTER_NEAREST;
10059 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10060 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10061 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10062 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10063 sampler_ci.mipLodBias = 1.0;
10064 sampler_ci.anisotropyEnable = VK_FALSE;
10065 sampler_ci.maxAnisotropy = 1;
10066 sampler_ci.compareEnable = VK_FALSE;
10067 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10068 sampler_ci.minLod = 1.0;
10069 sampler_ci.maxLod = 1.0;
10070 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10071 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10072 VkSampler sampler;
10073 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10074 ASSERT_VK_SUCCESS(err);
10075
10076 VkDescriptorImageInfo info = {};
10077 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010078
10079 VkWriteDescriptorSet descriptor_write;
10080 memset(&descriptor_write, 0, sizeof(descriptor_write));
10081 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010082 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010083 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010084 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010085 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010086 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010087
10088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010090 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010091
Chia-I Wuf7458c52015-10-26 21:10:41 +080010092 vkDestroySampler(m_device->device(), sampler, NULL);
10093 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10094 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010095}
10096
Karl Schultz6addd812016-02-02 17:17:23 -070010097TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010098 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010099 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010100
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010102
Tobin Ehlis3b780662015-05-28 12:11:26 -060010103 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010104 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010105 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010106 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10107 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010108
10109 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010110 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10111 ds_pool_ci.pNext = NULL;
10112 ds_pool_ci.maxSets = 1;
10113 ds_pool_ci.poolSizeCount = 1;
10114 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010115
Tobin Ehlis3b780662015-05-28 12:11:26 -060010116 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010119
Tony Barboureb254902015-07-15 12:50:33 -060010120 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010121 dsl_binding.binding = 0;
10122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10123 dsl_binding.descriptorCount = 1;
10124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10125 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010126
10127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10129 ds_layout_ci.pNext = NULL;
10130 ds_layout_ci.bindingCount = 1;
10131 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010132
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010135 ASSERT_VK_SUCCESS(err);
10136
10137 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010138 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010140 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010141 alloc_info.descriptorPool = ds_pool;
10142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010144 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010145
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010146 // Correctly update descriptor to avoid "NOT_UPDATED" error
10147 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010148 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010149 buff_info.offset = 0;
10150 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010151
10152 VkWriteDescriptorSet descriptor_write;
10153 memset(&descriptor_write, 0, sizeof(descriptor_write));
10154 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010155 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010157 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010158 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10159 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010160
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010161 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010162 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10163
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010164 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010165
Chia-I Wuf7458c52015-10-26 21:10:41 +080010166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010168}
10169
Karl Schultz6addd812016-02-02 17:17:23 -070010170TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010171 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010172 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010173
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010175
Tobin Ehlis3b780662015-05-28 12:11:26 -060010176 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010177 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010178 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010179 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10180 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010181
10182 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010183 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10184 ds_pool_ci.pNext = NULL;
10185 ds_pool_ci.maxSets = 1;
10186 ds_pool_ci.poolSizeCount = 1;
10187 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010188
Tobin Ehlis3b780662015-05-28 12:11:26 -060010189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010192
Tony Barboureb254902015-07-15 12:50:33 -060010193 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010194 dsl_binding.binding = 0;
10195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10196 dsl_binding.descriptorCount = 1;
10197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10198 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010199
10200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10202 ds_layout_ci.pNext = NULL;
10203 ds_layout_ci.bindingCount = 1;
10204 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010205 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010207 ASSERT_VK_SUCCESS(err);
10208
10209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010212 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010213 alloc_info.descriptorPool = ds_pool;
10214 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010216 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217
Tony Barboureb254902015-07-15 12:50:33 -060010218 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010219 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10220 sampler_ci.pNext = NULL;
10221 sampler_ci.magFilter = VK_FILTER_NEAREST;
10222 sampler_ci.minFilter = VK_FILTER_NEAREST;
10223 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10224 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10225 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10226 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10227 sampler_ci.mipLodBias = 1.0;
10228 sampler_ci.anisotropyEnable = VK_FALSE;
10229 sampler_ci.maxAnisotropy = 1;
10230 sampler_ci.compareEnable = VK_FALSE;
10231 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10232 sampler_ci.minLod = 1.0;
10233 sampler_ci.maxLod = 1.0;
10234 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10235 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010236
Tobin Ehlis3b780662015-05-28 12:11:26 -060010237 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010238 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010239 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010240
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010241 VkDescriptorImageInfo info = {};
10242 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010243
10244 VkWriteDescriptorSet descriptor_write;
10245 memset(&descriptor_write, 0, sizeof(descriptor_write));
10246 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010247 descriptor_write.dstSet = descriptorSet;
10248 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010249 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010250 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010252 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010253
10254 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10255
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010256 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010257
Chia-I Wuf7458c52015-10-26 21:10:41 +080010258 vkDestroySampler(m_device->device(), sampler, NULL);
10259 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10260 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010261}
10262
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010263TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10264 // Create layout w/ empty binding and attempt to update it
10265 VkResult err;
10266
10267 ASSERT_NO_FATAL_FAILURE(InitState());
10268
10269 VkDescriptorPoolSize ds_type_count = {};
10270 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10271 ds_type_count.descriptorCount = 1;
10272
10273 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10274 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10275 ds_pool_ci.pNext = NULL;
10276 ds_pool_ci.maxSets = 1;
10277 ds_pool_ci.poolSizeCount = 1;
10278 ds_pool_ci.pPoolSizes = &ds_type_count;
10279
10280 VkDescriptorPool ds_pool;
10281 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10282 ASSERT_VK_SUCCESS(err);
10283
10284 VkDescriptorSetLayoutBinding dsl_binding = {};
10285 dsl_binding.binding = 0;
10286 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10287 dsl_binding.descriptorCount = 0;
10288 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10289 dsl_binding.pImmutableSamplers = NULL;
10290
10291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10293 ds_layout_ci.pNext = NULL;
10294 ds_layout_ci.bindingCount = 1;
10295 ds_layout_ci.pBindings = &dsl_binding;
10296 VkDescriptorSetLayout ds_layout;
10297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10298 ASSERT_VK_SUCCESS(err);
10299
10300 VkDescriptorSet descriptor_set;
10301 VkDescriptorSetAllocateInfo alloc_info = {};
10302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10303 alloc_info.descriptorSetCount = 1;
10304 alloc_info.descriptorPool = ds_pool;
10305 alloc_info.pSetLayouts = &ds_layout;
10306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10307 ASSERT_VK_SUCCESS(err);
10308
10309 VkSamplerCreateInfo sampler_ci = {};
10310 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10311 sampler_ci.magFilter = VK_FILTER_NEAREST;
10312 sampler_ci.minFilter = VK_FILTER_NEAREST;
10313 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10314 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10315 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10316 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10317 sampler_ci.mipLodBias = 1.0;
10318 sampler_ci.maxAnisotropy = 1;
10319 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10320 sampler_ci.minLod = 1.0;
10321 sampler_ci.maxLod = 1.0;
10322 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10323
10324 VkSampler sampler;
10325 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10326 ASSERT_VK_SUCCESS(err);
10327
10328 VkDescriptorImageInfo info = {};
10329 info.sampler = sampler;
10330
10331 VkWriteDescriptorSet descriptor_write;
10332 memset(&descriptor_write, 0, sizeof(descriptor_write));
10333 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10334 descriptor_write.dstSet = descriptor_set;
10335 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010336 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010337 // This is the wrong type, but empty binding error will be flagged first
10338 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10339 descriptor_write.pImageInfo = &info;
10340
10341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10342 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10343 m_errorMonitor->VerifyFound();
10344
10345 vkDestroySampler(m_device->device(), sampler, NULL);
10346 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10347 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10348}
10349
Karl Schultz6addd812016-02-02 17:17:23 -070010350TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10351 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10352 // types
10353 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010355 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 -060010356
Tobin Ehlis3b780662015-05-28 12:11:26 -060010357 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010358
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010359 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010360 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10361 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010362
10363 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010364 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10365 ds_pool_ci.pNext = NULL;
10366 ds_pool_ci.maxSets = 1;
10367 ds_pool_ci.poolSizeCount = 1;
10368 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010369
Tobin Ehlis3b780662015-05-28 12:11:26 -060010370 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010373 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010374 dsl_binding.binding = 0;
10375 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10376 dsl_binding.descriptorCount = 1;
10377 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10378 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010379
Tony Barboureb254902015-07-15 12:50:33 -060010380 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010381 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10382 ds_layout_ci.pNext = NULL;
10383 ds_layout_ci.bindingCount = 1;
10384 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010385
Tobin Ehlis3b780662015-05-28 12:11:26 -060010386 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010387 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010388 ASSERT_VK_SUCCESS(err);
10389
10390 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010391 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010392 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010393 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010394 alloc_info.descriptorPool = ds_pool;
10395 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010398
Tony Barboureb254902015-07-15 12:50:33 -060010399 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010400 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10401 sampler_ci.pNext = NULL;
10402 sampler_ci.magFilter = VK_FILTER_NEAREST;
10403 sampler_ci.minFilter = VK_FILTER_NEAREST;
10404 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10405 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10406 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10407 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10408 sampler_ci.mipLodBias = 1.0;
10409 sampler_ci.anisotropyEnable = VK_FALSE;
10410 sampler_ci.maxAnisotropy = 1;
10411 sampler_ci.compareEnable = VK_FALSE;
10412 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10413 sampler_ci.minLod = 1.0;
10414 sampler_ci.maxLod = 1.0;
10415 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10416 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010417 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010418 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010419 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010420
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010421 VkDescriptorImageInfo info = {};
10422 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010423
10424 VkWriteDescriptorSet descriptor_write;
10425 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010426 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010427 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010428 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010429 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010430 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010431 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010432
10433 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010435 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010436
Chia-I Wuf7458c52015-10-26 21:10:41 +080010437 vkDestroySampler(m_device->device(), sampler, NULL);
10438 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10439 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010440}
10441
Karl Schultz6addd812016-02-02 17:17:23 -070010442TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010443 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010444 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010445
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010447
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010448 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010449 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10450 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010451 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010452 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10453 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010454
10455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10457 ds_pool_ci.pNext = NULL;
10458 ds_pool_ci.maxSets = 1;
10459 ds_pool_ci.poolSizeCount = 1;
10460 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010461
10462 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010464 ASSERT_VK_SUCCESS(err);
10465
10466 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010467 dsl_binding.binding = 0;
10468 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10469 dsl_binding.descriptorCount = 1;
10470 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10471 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010472
10473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10475 ds_layout_ci.pNext = NULL;
10476 ds_layout_ci.bindingCount = 1;
10477 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010478 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010480 ASSERT_VK_SUCCESS(err);
10481
10482 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010483 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010485 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010486 alloc_info.descriptorPool = ds_pool;
10487 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010489 ASSERT_VK_SUCCESS(err);
10490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010491 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010492
10493 VkDescriptorImageInfo descriptor_info;
10494 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10495 descriptor_info.sampler = sampler;
10496
10497 VkWriteDescriptorSet descriptor_write;
10498 memset(&descriptor_write, 0, sizeof(descriptor_write));
10499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010500 descriptor_write.dstSet = descriptorSet;
10501 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010502 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010503 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10504 descriptor_write.pImageInfo = &descriptor_info;
10505
10506 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10507
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010508 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010509
Chia-I Wuf7458c52015-10-26 21:10:41 +080010510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10511 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010512}
10513
Karl Schultz6addd812016-02-02 17:17:23 -070010514TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10515 // Create a single combined Image/Sampler descriptor and send it an invalid
10516 // imageView
10517 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010518
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010520
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010521 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010522 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010523 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10524 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010525
10526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10528 ds_pool_ci.pNext = NULL;
10529 ds_pool_ci.maxSets = 1;
10530 ds_pool_ci.poolSizeCount = 1;
10531 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010532
10533 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010535 ASSERT_VK_SUCCESS(err);
10536
10537 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010538 dsl_binding.binding = 0;
10539 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10540 dsl_binding.descriptorCount = 1;
10541 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10542 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010543
10544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10546 ds_layout_ci.pNext = NULL;
10547 ds_layout_ci.bindingCount = 1;
10548 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010549 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010551 ASSERT_VK_SUCCESS(err);
10552
10553 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010554 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010556 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010557 alloc_info.descriptorPool = ds_pool;
10558 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010560 ASSERT_VK_SUCCESS(err);
10561
10562 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010563 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10564 sampler_ci.pNext = NULL;
10565 sampler_ci.magFilter = VK_FILTER_NEAREST;
10566 sampler_ci.minFilter = VK_FILTER_NEAREST;
10567 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10568 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10569 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10570 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10571 sampler_ci.mipLodBias = 1.0;
10572 sampler_ci.anisotropyEnable = VK_FALSE;
10573 sampler_ci.maxAnisotropy = 1;
10574 sampler_ci.compareEnable = VK_FALSE;
10575 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10576 sampler_ci.minLod = 1.0;
10577 sampler_ci.maxLod = 1.0;
10578 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10579 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010580
10581 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010582 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010583 ASSERT_VK_SUCCESS(err);
10584
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010585 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010586
10587 VkDescriptorImageInfo descriptor_info;
10588 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10589 descriptor_info.sampler = sampler;
10590 descriptor_info.imageView = view;
10591
10592 VkWriteDescriptorSet descriptor_write;
10593 memset(&descriptor_write, 0, sizeof(descriptor_write));
10594 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010595 descriptor_write.dstSet = descriptorSet;
10596 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010597 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010598 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10599 descriptor_write.pImageInfo = &descriptor_info;
10600
10601 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10602
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010603 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604
Chia-I Wuf7458c52015-10-26 21:10:41 +080010605 vkDestroySampler(m_device->device(), sampler, NULL);
10606 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10607 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010608}
10609
Karl Schultz6addd812016-02-02 17:17:23 -070010610TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10611 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10612 // into the other
10613 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010614
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10616 " binding #1 with type "
10617 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10618 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010619
Tobin Ehlis04356f92015-10-27 16:35:27 -060010620 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010621 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010622 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010623 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10624 ds_type_count[0].descriptorCount = 1;
10625 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10626 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010627
10628 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010629 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10630 ds_pool_ci.pNext = NULL;
10631 ds_pool_ci.maxSets = 1;
10632 ds_pool_ci.poolSizeCount = 2;
10633 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010634
10635 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010636 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010637 ASSERT_VK_SUCCESS(err);
10638 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010639 dsl_binding[0].binding = 0;
10640 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10641 dsl_binding[0].descriptorCount = 1;
10642 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10643 dsl_binding[0].pImmutableSamplers = NULL;
10644 dsl_binding[1].binding = 1;
10645 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10646 dsl_binding[1].descriptorCount = 1;
10647 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10648 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010649
10650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10652 ds_layout_ci.pNext = NULL;
10653 ds_layout_ci.bindingCount = 2;
10654 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655
10656 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010658 ASSERT_VK_SUCCESS(err);
10659
10660 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010661 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010663 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010664 alloc_info.descriptorPool = ds_pool;
10665 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667 ASSERT_VK_SUCCESS(err);
10668
10669 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010670 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10671 sampler_ci.pNext = NULL;
10672 sampler_ci.magFilter = VK_FILTER_NEAREST;
10673 sampler_ci.minFilter = VK_FILTER_NEAREST;
10674 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10675 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10676 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10677 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10678 sampler_ci.mipLodBias = 1.0;
10679 sampler_ci.anisotropyEnable = VK_FALSE;
10680 sampler_ci.maxAnisotropy = 1;
10681 sampler_ci.compareEnable = VK_FALSE;
10682 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10683 sampler_ci.minLod = 1.0;
10684 sampler_ci.maxLod = 1.0;
10685 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10686 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010687
10688 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010689 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010690 ASSERT_VK_SUCCESS(err);
10691
10692 VkDescriptorImageInfo info = {};
10693 info.sampler = sampler;
10694
10695 VkWriteDescriptorSet descriptor_write;
10696 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10697 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010698 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010699 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010700 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010701 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10702 descriptor_write.pImageInfo = &info;
10703 // This write update should succeed
10704 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10705 // Now perform a copy update that fails due to type mismatch
10706 VkCopyDescriptorSet copy_ds_update;
10707 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10708 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10709 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010710 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010711 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010712 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10713 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010714 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10715
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010716 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010717 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010718 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 -060010719 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10720 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10721 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010722 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010723 copy_ds_update.dstSet = descriptorSet;
10724 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010725 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010726 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10727
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010728 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010729
Tobin Ehlis04356f92015-10-27 16:35:27 -060010730 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10732 " binding#1 with offset index of 1 plus "
10733 "update array offset of 0 and update of "
10734 "5 descriptors oversteps total number "
10735 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010736
Tobin Ehlis04356f92015-10-27 16:35:27 -060010737 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10738 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10739 copy_ds_update.srcSet = descriptorSet;
10740 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010741 copy_ds_update.dstSet = descriptorSet;
10742 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010743 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010744 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010746 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010747
Chia-I Wuf7458c52015-10-26 21:10:41 +080010748 vkDestroySampler(m_device->device(), sampler, NULL);
10749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010751}
10752
Karl Schultz6addd812016-02-02 17:17:23 -070010753TEST_F(VkLayerTest, NumSamplesMismatch) {
10754 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10755 // sampleCount
10756 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010759
Tobin Ehlis3b780662015-05-28 12:11:26 -060010760 ASSERT_NO_FATAL_FAILURE(InitState());
10761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010762 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010764 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010765
10766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10768 ds_pool_ci.pNext = NULL;
10769 ds_pool_ci.maxSets = 1;
10770 ds_pool_ci.poolSizeCount = 1;
10771 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010772
Tobin Ehlis3b780662015-05-28 12:11:26 -060010773 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010774 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010776
Tony Barboureb254902015-07-15 12:50:33 -060010777 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010778 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010780 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10782 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010783
Tony Barboureb254902015-07-15 12:50:33 -060010784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10786 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010787 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010788 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010789
Tobin Ehlis3b780662015-05-28 12:11:26 -060010790 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010791 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010792 ASSERT_VK_SUCCESS(err);
10793
10794 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010795 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010796 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010797 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010798 alloc_info.descriptorPool = ds_pool;
10799 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010800 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010801 ASSERT_VK_SUCCESS(err);
10802
Tony Barboureb254902015-07-15 12:50:33 -060010803 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010804 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010805 pipe_ms_state_ci.pNext = NULL;
10806 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10807 pipe_ms_state_ci.sampleShadingEnable = 0;
10808 pipe_ms_state_ci.minSampleShading = 1.0;
10809 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010810
Tony Barboureb254902015-07-15 12:50:33 -060010811 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010812 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10813 pipeline_layout_ci.pNext = NULL;
10814 pipeline_layout_ci.setLayoutCount = 1;
10815 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010816
10817 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010819 ASSERT_VK_SUCCESS(err);
10820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010822 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 -060010823 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010824 VkPipelineObj pipe(m_device);
10825 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010826 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010827 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010828 pipe.SetMSAA(&pipe_ms_state_ci);
10829 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010830
Tony Barbour552f6c02016-12-21 14:34:07 -070010831 m_commandBuffer->BeginCommandBuffer();
10832 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010835 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10836 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10837 VkRect2D scissor = {{0, 0}, {16, 16}};
10838 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10839
Mark Young29927482016-05-04 14:38:51 -060010840 // Render triangle (the error should trigger on the attempt to draw).
10841 Draw(3, 1, 0, 0);
10842
10843 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010844 m_commandBuffer->EndRenderPass();
10845 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010846
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010847 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010848
Chia-I Wuf7458c52015-10-26 21:10:41 +080010849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010852}
Mark Young29927482016-05-04 14:38:51 -060010853
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010854TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010855 TEST_DESCRIPTION(
10856 "Hit RenderPass incompatible cases. "
10857 "Initial case is drawing with an active renderpass that's "
10858 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010859 VkResult err;
10860
10861 ASSERT_NO_FATAL_FAILURE(InitState());
10862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10863
10864 VkDescriptorSetLayoutBinding dsl_binding = {};
10865 dsl_binding.binding = 0;
10866 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10867 dsl_binding.descriptorCount = 1;
10868 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10869 dsl_binding.pImmutableSamplers = NULL;
10870
10871 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10872 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10873 ds_layout_ci.pNext = NULL;
10874 ds_layout_ci.bindingCount = 1;
10875 ds_layout_ci.pBindings = &dsl_binding;
10876
10877 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010878 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010879 ASSERT_VK_SUCCESS(err);
10880
10881 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10882 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10883 pipeline_layout_ci.pNext = NULL;
10884 pipeline_layout_ci.setLayoutCount = 1;
10885 pipeline_layout_ci.pSetLayouts = &ds_layout;
10886
10887 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010888 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010889 ASSERT_VK_SUCCESS(err);
10890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010891 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010892 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 -060010893 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010894 // Create a renderpass that will be incompatible with default renderpass
10895 VkAttachmentReference attach = {};
10896 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10897 VkAttachmentReference color_att = {};
10898 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10899 VkSubpassDescription subpass = {};
10900 subpass.inputAttachmentCount = 1;
10901 subpass.pInputAttachments = &attach;
10902 subpass.colorAttachmentCount = 1;
10903 subpass.pColorAttachments = &color_att;
10904 VkRenderPassCreateInfo rpci = {};
10905 rpci.subpassCount = 1;
10906 rpci.pSubpasses = &subpass;
10907 rpci.attachmentCount = 1;
10908 VkAttachmentDescription attach_desc = {};
10909 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010910 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10911 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010912 rpci.pAttachments = &attach_desc;
10913 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10914 VkRenderPass rp;
10915 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10916 VkPipelineObj pipe(m_device);
10917 pipe.AddShader(&vs);
10918 pipe.AddShader(&fs);
10919 pipe.AddColorAttachment();
10920 VkViewport view_port = {};
10921 m_viewports.push_back(view_port);
10922 pipe.SetViewport(m_viewports);
10923 VkRect2D rect = {};
10924 m_scissors.push_back(rect);
10925 pipe.SetScissor(m_scissors);
10926 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10927
10928 VkCommandBufferInheritanceInfo cbii = {};
10929 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10930 cbii.renderPass = rp;
10931 cbii.subpass = 0;
10932 VkCommandBufferBeginInfo cbbi = {};
10933 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10934 cbbi.pInheritanceInfo = &cbii;
10935 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10936 VkRenderPassBeginInfo rpbi = {};
10937 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10938 rpbi.framebuffer = m_framebuffer;
10939 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010940 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10941 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010944 // Render triangle (the error should trigger on the attempt to draw).
10945 Draw(3, 1, 0, 0);
10946
10947 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010948 m_commandBuffer->EndRenderPass();
10949 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010950
10951 m_errorMonitor->VerifyFound();
10952
10953 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10955 vkDestroyRenderPass(m_device->device(), rp, NULL);
10956}
10957
Mark Youngc89c6312016-03-31 16:03:20 -060010958TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10959 // Create Pipeline where the number of blend attachments doesn't match the
10960 // number of color attachments. In this case, we don't add any color
10961 // blend attachments even though we have a color attachment.
10962 VkResult err;
10963
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010965
10966 ASSERT_NO_FATAL_FAILURE(InitState());
10967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10968 VkDescriptorPoolSize ds_type_count = {};
10969 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10970 ds_type_count.descriptorCount = 1;
10971
10972 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10973 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10974 ds_pool_ci.pNext = NULL;
10975 ds_pool_ci.maxSets = 1;
10976 ds_pool_ci.poolSizeCount = 1;
10977 ds_pool_ci.pPoolSizes = &ds_type_count;
10978
10979 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010980 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010981 ASSERT_VK_SUCCESS(err);
10982
10983 VkDescriptorSetLayoutBinding dsl_binding = {};
10984 dsl_binding.binding = 0;
10985 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10986 dsl_binding.descriptorCount = 1;
10987 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10988 dsl_binding.pImmutableSamplers = NULL;
10989
10990 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10991 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10992 ds_layout_ci.pNext = NULL;
10993 ds_layout_ci.bindingCount = 1;
10994 ds_layout_ci.pBindings = &dsl_binding;
10995
10996 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010997 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010998 ASSERT_VK_SUCCESS(err);
10999
11000 VkDescriptorSet descriptorSet;
11001 VkDescriptorSetAllocateInfo alloc_info = {};
11002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11003 alloc_info.descriptorSetCount = 1;
11004 alloc_info.descriptorPool = ds_pool;
11005 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011007 ASSERT_VK_SUCCESS(err);
11008
11009 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011010 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011011 pipe_ms_state_ci.pNext = NULL;
11012 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11013 pipe_ms_state_ci.sampleShadingEnable = 0;
11014 pipe_ms_state_ci.minSampleShading = 1.0;
11015 pipe_ms_state_ci.pSampleMask = NULL;
11016
11017 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11018 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11019 pipeline_layout_ci.pNext = NULL;
11020 pipeline_layout_ci.setLayoutCount = 1;
11021 pipeline_layout_ci.pSetLayouts = &ds_layout;
11022
11023 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011025 ASSERT_VK_SUCCESS(err);
11026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011027 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011028 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 -060011029 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011030 VkPipelineObj pipe(m_device);
11031 pipe.AddShader(&vs);
11032 pipe.AddShader(&fs);
11033 pipe.SetMSAA(&pipe_ms_state_ci);
11034 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011035 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011036
11037 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11038 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11039 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11040}
Mark Young29927482016-05-04 14:38:51 -060011041
Mark Muellerd4914412016-06-13 17:52:06 -060011042TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011043 TEST_DESCRIPTION(
11044 "Points to a wrong colorAttachment index in a VkClearAttachment "
11045 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011046 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011048
11049 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11050 m_errorMonitor->VerifyFound();
11051}
11052
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011053TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011054 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11055 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011056
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011057 ASSERT_NO_FATAL_FAILURE(InitState());
11058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011059
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011060 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011061 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11062 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011063
11064 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011065 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11066 ds_pool_ci.pNext = NULL;
11067 ds_pool_ci.maxSets = 1;
11068 ds_pool_ci.poolSizeCount = 1;
11069 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011070
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011071 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011073 ASSERT_VK_SUCCESS(err);
11074
Tony Barboureb254902015-07-15 12:50:33 -060011075 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011076 dsl_binding.binding = 0;
11077 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11078 dsl_binding.descriptorCount = 1;
11079 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11080 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011081
Tony Barboureb254902015-07-15 12:50:33 -060011082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11084 ds_layout_ci.pNext = NULL;
11085 ds_layout_ci.bindingCount = 1;
11086 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011087
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011088 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011090 ASSERT_VK_SUCCESS(err);
11091
11092 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011093 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011095 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011096 alloc_info.descriptorPool = ds_pool;
11097 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011098 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011099 ASSERT_VK_SUCCESS(err);
11100
Tony Barboureb254902015-07-15 12:50:33 -060011101 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011102 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011103 pipe_ms_state_ci.pNext = NULL;
11104 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11105 pipe_ms_state_ci.sampleShadingEnable = 0;
11106 pipe_ms_state_ci.minSampleShading = 1.0;
11107 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011108
Tony Barboureb254902015-07-15 12:50:33 -060011109 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011110 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11111 pipeline_layout_ci.pNext = NULL;
11112 pipeline_layout_ci.setLayoutCount = 1;
11113 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011114
11115 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011117 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011119 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011120 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011121 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011122 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011123
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011124 VkPipelineObj pipe(m_device);
11125 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011126 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011127 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011128 m_errorMonitor->SetUnexpectedError(
11129 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11130 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011131 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011132
Tony Barbour552f6c02016-12-21 14:34:07 -070011133 m_commandBuffer->BeginCommandBuffer();
11134 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011135
Karl Schultz6addd812016-02-02 17:17:23 -070011136 // Main thing we care about for this test is that the VkImage obj we're
11137 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011138 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011139 VkClearAttachment color_attachment;
11140 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11141 color_attachment.clearValue.color.float32[0] = 1.0;
11142 color_attachment.clearValue.color.float32[1] = 1.0;
11143 color_attachment.clearValue.color.float32[2] = 1.0;
11144 color_attachment.clearValue.color.float32[3] = 1.0;
11145 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011146 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011147
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011148 // Call for full-sized FB Color attachment prior to issuing a Draw
11149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011150 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011152 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011153
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011154 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11155 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11157 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11158 m_errorMonitor->VerifyFound();
11159
11160 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11161 clear_rect.layerCount = 2;
11162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11163 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011164 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011165
Chia-I Wuf7458c52015-10-26 21:10:41 +080011166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011169}
11170
Karl Schultz6addd812016-02-02 17:17:23 -070011171TEST_F(VkLayerTest, VtxBufferBadIndex) {
11172 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11175 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011176
Tobin Ehlis502480b2015-06-24 15:53:07 -060011177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011178 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011180
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011181 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11183 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011184
11185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11187 ds_pool_ci.pNext = NULL;
11188 ds_pool_ci.maxSets = 1;
11189 ds_pool_ci.poolSizeCount = 1;
11190 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011191
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011192 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011194 ASSERT_VK_SUCCESS(err);
11195
Tony Barboureb254902015-07-15 12:50:33 -060011196 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011197 dsl_binding.binding = 0;
11198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11199 dsl_binding.descriptorCount = 1;
11200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11201 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011202
Tony Barboureb254902015-07-15 12:50:33 -060011203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11205 ds_layout_ci.pNext = NULL;
11206 ds_layout_ci.bindingCount = 1;
11207 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011208
Tobin Ehlis502480b2015-06-24 15:53:07 -060011209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011211 ASSERT_VK_SUCCESS(err);
11212
11213 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011214 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011216 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011217 alloc_info.descriptorPool = ds_pool;
11218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011220 ASSERT_VK_SUCCESS(err);
11221
Tony Barboureb254902015-07-15 12:50:33 -060011222 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011224 pipe_ms_state_ci.pNext = NULL;
11225 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11226 pipe_ms_state_ci.sampleShadingEnable = 0;
11227 pipe_ms_state_ci.minSampleShading = 1.0;
11228 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011229
Tony Barboureb254902015-07-15 12:50:33 -060011230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11232 pipeline_layout_ci.pNext = NULL;
11233 pipeline_layout_ci.setLayoutCount = 1;
11234 pipeline_layout_ci.pSetLayouts = &ds_layout;
11235 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011238 ASSERT_VK_SUCCESS(err);
11239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011241 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 -060011242 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011243 VkPipelineObj pipe(m_device);
11244 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011245 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011246 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011247 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011248 pipe.SetViewport(m_viewports);
11249 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011250 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011251
Tony Barbour552f6c02016-12-21 14:34:07 -070011252 m_commandBuffer->BeginCommandBuffer();
11253 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011254 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011255 // Don't care about actual data, just need to get to draw to flag error
11256 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011257 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011258 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011259 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011260
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011261 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011262
Chia-I Wuf7458c52015-10-26 21:10:41 +080011263 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11264 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11265 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011266}
Mark Muellerdfe37552016-07-07 14:47:42 -060011267
Mark Mueller2ee294f2016-08-04 12:59:48 -060011268TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011269 TEST_DESCRIPTION(
11270 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11271 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011272 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011274 const char *invalid_queueFamilyIndex_message =
11275 "Invalid queue create request in vkCreateDevice(). Invalid "
11276 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011278 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011279
Mark Mueller880fce52016-08-17 15:23:23 -060011280 // The following test fails with recent NVidia drivers.
11281 // By the time core_validation is reached, the NVidia
11282 // driver has sanitized the invalid condition and core_validation
11283 // is not introduced to the failure condition. This is not the case
11284 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011285 // uint32_t count = static_cast<uint32_t>(~0);
11286 // VkPhysicalDevice physical_device;
11287 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11288 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011291 float queue_priority = 0.0;
11292
11293 VkDeviceQueueCreateInfo queue_create_info = {};
11294 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11295 queue_create_info.queueCount = 1;
11296 queue_create_info.pQueuePriorities = &queue_priority;
11297 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11298
11299 VkPhysicalDeviceFeatures features = m_device->phy().features();
11300 VkDevice testDevice;
11301 VkDeviceCreateInfo device_create_info = {};
11302 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11303 device_create_info.queueCreateInfoCount = 1;
11304 device_create_info.pQueueCreateInfos = &queue_create_info;
11305 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011306 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011307 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11308 m_errorMonitor->VerifyFound();
11309
11310 queue_create_info.queueFamilyIndex = 1;
11311
11312 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11313 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11314 for (unsigned i = 0; i < feature_count; i++) {
11315 if (VK_FALSE == feature_array[i]) {
11316 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011318 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011319 m_errorMonitor->SetUnexpectedError(
11320 "You requested features that are unavailable on this device. You should first query feature availability by "
11321 "calling vkGetPhysicalDeviceFeatures().");
11322 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011323 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11324 m_errorMonitor->VerifyFound();
11325 break;
11326 }
11327 }
11328}
11329
Tobin Ehlis16edf082016-11-21 12:33:49 -070011330TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11331 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11332
11333 ASSERT_NO_FATAL_FAILURE(InitState());
11334
11335 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11336 std::vector<VkDeviceQueueCreateInfo> queue_info;
11337 queue_info.reserve(queue_props.size());
11338 std::vector<std::vector<float>> queue_priorities;
11339 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11340 VkDeviceQueueCreateInfo qi{};
11341 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11342 qi.queueFamilyIndex = i;
11343 qi.queueCount = queue_props[i].queueCount;
11344 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11345 qi.pQueuePriorities = queue_priorities[i].data();
11346 queue_info.push_back(qi);
11347 }
11348
11349 std::vector<const char *> device_extension_names;
11350
11351 VkDevice local_device;
11352 VkDeviceCreateInfo device_create_info = {};
11353 auto features = m_device->phy().features();
11354 // Intentionally disable pipeline stats
11355 features.pipelineStatisticsQuery = VK_FALSE;
11356 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11357 device_create_info.pNext = NULL;
11358 device_create_info.queueCreateInfoCount = queue_info.size();
11359 device_create_info.pQueueCreateInfos = queue_info.data();
11360 device_create_info.enabledLayerCount = 0;
11361 device_create_info.ppEnabledLayerNames = NULL;
11362 device_create_info.pEnabledFeatures = &features;
11363 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11364 ASSERT_VK_SUCCESS(err);
11365
11366 VkQueryPoolCreateInfo qpci{};
11367 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11368 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11369 qpci.queryCount = 1;
11370 VkQueryPool query_pool;
11371
11372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11373 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11374 m_errorMonitor->VerifyFound();
11375
11376 vkDestroyDevice(local_device, nullptr);
11377}
11378
Mark Mueller2ee294f2016-08-04 12:59:48 -060011379TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011380 TEST_DESCRIPTION(
11381 "Use an invalid queue index in a vkCmdWaitEvents call."
11382 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011383
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011384 const char *invalid_queue_index =
11385 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11386 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11387 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011389 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011392
11393 ASSERT_NO_FATAL_FAILURE(InitState());
11394
11395 VkEvent event;
11396 VkEventCreateInfo event_create_info{};
11397 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11398 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11399
Mark Mueller2ee294f2016-08-04 12:59:48 -060011400 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011402
Tony Barbour552f6c02016-12-21 14:34:07 -070011403 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011404
11405 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 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 -060011407 ASSERT_TRUE(image.initialized());
11408 VkImageMemoryBarrier img_barrier = {};
11409 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11410 img_barrier.pNext = NULL;
11411 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11412 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11413 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11414 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11415 img_barrier.image = image.handle();
11416 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011417
11418 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11419 // that layer validation catches the case when it is not.
11420 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011421 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11422 img_barrier.subresourceRange.baseArrayLayer = 0;
11423 img_barrier.subresourceRange.baseMipLevel = 0;
11424 img_barrier.subresourceRange.layerCount = 1;
11425 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011426 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11427 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011428 m_errorMonitor->VerifyFound();
11429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011431
11432 VkQueryPool query_pool;
11433 VkQueryPoolCreateInfo query_pool_create_info = {};
11434 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11435 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11436 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011437 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011440 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11441
11442 vkEndCommandBuffer(m_commandBuffer->handle());
11443 m_errorMonitor->VerifyFound();
11444
11445 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11446 vkDestroyEvent(m_device->device(), event, nullptr);
11447}
11448
Mark Muellerdfe37552016-07-07 14:47:42 -060011449TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011450 TEST_DESCRIPTION(
11451 "Submit a command buffer using deleted vertex buffer, "
11452 "delete a buffer twice, use an invalid offset for each "
11453 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011454
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011455 const char *deleted_buffer_in_command_buffer =
11456 "Cannot submit cmd buffer "
11457 "using deleted buffer ";
11458 const char *invalid_offset_message =
11459 "vkBindBufferMemory(): "
11460 "memoryOffset is 0x";
11461 const char *invalid_storage_buffer_offset_message =
11462 "vkBindBufferMemory(): "
11463 "storage memoryOffset "
11464 "is 0x";
11465 const char *invalid_texel_buffer_offset_message =
11466 "vkBindBufferMemory(): "
11467 "texel memoryOffset "
11468 "is 0x";
11469 const char *invalid_uniform_buffer_offset_message =
11470 "vkBindBufferMemory(): "
11471 "uniform memoryOffset "
11472 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011473
11474 ASSERT_NO_FATAL_FAILURE(InitState());
11475 ASSERT_NO_FATAL_FAILURE(InitViewport());
11476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11477
11478 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011480 pipe_ms_state_ci.pNext = NULL;
11481 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11482 pipe_ms_state_ci.sampleShadingEnable = 0;
11483 pipe_ms_state_ci.minSampleShading = 1.0;
11484 pipe_ms_state_ci.pSampleMask = nullptr;
11485
11486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11488 VkPipelineLayout pipeline_layout;
11489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011490 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011491 ASSERT_VK_SUCCESS(err);
11492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011493 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11494 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011495 VkPipelineObj pipe(m_device);
11496 pipe.AddShader(&vs);
11497 pipe.AddShader(&fs);
11498 pipe.AddColorAttachment();
11499 pipe.SetMSAA(&pipe_ms_state_ci);
11500 pipe.SetViewport(m_viewports);
11501 pipe.SetScissor(m_scissors);
11502 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11503
Tony Barbour552f6c02016-12-21 14:34:07 -070011504 m_commandBuffer->BeginCommandBuffer();
11505 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011506 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011507
11508 {
11509 // Create and bind a vertex buffer in a reduced scope, which will cause
11510 // it to be deleted upon leaving this scope
11511 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011512 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011513 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11514 draw_verticies.AddVertexInputToPipe(pipe);
11515 }
11516
11517 Draw(1, 0, 0, 0);
11518
Tony Barbour552f6c02016-12-21 14:34:07 -070011519 m_commandBuffer->EndRenderPass();
11520 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011523 QueueCommandBuffer(false);
11524 m_errorMonitor->VerifyFound();
11525
11526 {
11527 // Create and bind a vertex buffer in a reduced scope, and delete it
11528 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011531 buffer_test.TestDoubleDestroy();
11532 }
11533 m_errorMonitor->VerifyFound();
11534
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011535 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011536 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011537 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011539 m_errorMonitor->SetUnexpectedError(
11540 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11541 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011542 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11543 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011544 m_errorMonitor->VerifyFound();
11545 }
11546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11548 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011549 // Create and bind a memory buffer with an invalid offset again,
11550 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011552 m_errorMonitor->SetUnexpectedError(
11553 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11554 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11556 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011557 m_errorMonitor->VerifyFound();
11558 }
11559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011560 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011561 // Create and bind a memory buffer with an invalid offset again, but
11562 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011564 m_errorMonitor->SetUnexpectedError(
11565 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11566 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011567 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11568 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011569 m_errorMonitor->VerifyFound();
11570 }
11571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011573 // Create and bind a memory buffer with an invalid offset again, but
11574 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011576 m_errorMonitor->SetUnexpectedError(
11577 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11578 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11580 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011581 m_errorMonitor->VerifyFound();
11582 }
11583
11584 {
11585 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011587 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11588 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11590 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011591 m_errorMonitor->VerifyFound();
11592 }
11593
11594 {
11595 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11598 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011599 }
11600 m_errorMonitor->VerifyFound();
11601
11602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11603}
11604
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011605// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11606TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011607 TEST_DESCRIPTION(
11608 "Hit all possible validation checks associated with the "
11609 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11610 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011611 // 3 in ValidateCmdBufImageLayouts
11612 // * -1 Attempt to submit cmd buf w/ deleted image
11613 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11614 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011615
11616 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011617 auto depth_format = find_depth_stencil_format(m_device);
11618 if (!depth_format) {
11619 printf(" No Depth + Stencil format found. Skipped.\n");
11620 return;
11621 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011622 // Create src & dst images to use for copy operations
11623 VkImage src_image;
11624 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011625 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011626
11627 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11628 const int32_t tex_width = 32;
11629 const int32_t tex_height = 32;
11630
11631 VkImageCreateInfo image_create_info = {};
11632 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11633 image_create_info.pNext = NULL;
11634 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11635 image_create_info.format = tex_format;
11636 image_create_info.extent.width = tex_width;
11637 image_create_info.extent.height = tex_height;
11638 image_create_info.extent.depth = 1;
11639 image_create_info.mipLevels = 1;
11640 image_create_info.arrayLayers = 4;
11641 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11642 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11643 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011644 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011645 image_create_info.flags = 0;
11646
11647 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11648 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011649 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11651 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011652 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11653 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11654 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11655 ASSERT_VK_SUCCESS(err);
11656
11657 // Allocate memory
11658 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011659 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011660 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011661 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11662 mem_alloc.pNext = NULL;
11663 mem_alloc.allocationSize = 0;
11664 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011665
11666 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011667 mem_alloc.allocationSize = img_mem_reqs.size;
11668 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011669 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011670 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011671 ASSERT_VK_SUCCESS(err);
11672
11673 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011674 mem_alloc.allocationSize = img_mem_reqs.size;
11675 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011676 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011677 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011678 ASSERT_VK_SUCCESS(err);
11679
11680 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011681 mem_alloc.allocationSize = img_mem_reqs.size;
11682 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011683 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011684 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011685 ASSERT_VK_SUCCESS(err);
11686
11687 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11688 ASSERT_VK_SUCCESS(err);
11689 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11690 ASSERT_VK_SUCCESS(err);
11691 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11692 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011693
Tony Barbour552f6c02016-12-21 14:34:07 -070011694 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011695 VkImageCopy copy_region;
11696 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11697 copy_region.srcSubresource.mipLevel = 0;
11698 copy_region.srcSubresource.baseArrayLayer = 0;
11699 copy_region.srcSubresource.layerCount = 1;
11700 copy_region.srcOffset.x = 0;
11701 copy_region.srcOffset.y = 0;
11702 copy_region.srcOffset.z = 0;
11703 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11704 copy_region.dstSubresource.mipLevel = 0;
11705 copy_region.dstSubresource.baseArrayLayer = 0;
11706 copy_region.dstSubresource.layerCount = 1;
11707 copy_region.dstOffset.x = 0;
11708 copy_region.dstOffset.y = 0;
11709 copy_region.dstOffset.z = 0;
11710 copy_region.extent.width = 1;
11711 copy_region.extent.height = 1;
11712 copy_region.extent.depth = 1;
11713
11714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11715 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011716 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011717 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 -060011718 m_errorMonitor->VerifyFound();
11719 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11721 "Cannot copy from an image whose source layout is "
11722 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11723 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011724 m_errorMonitor->SetUnexpectedError(
11725 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011726 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 -060011727 m_errorMonitor->VerifyFound();
11728 // Final src error is due to bad layout type
11729 m_errorMonitor->SetDesiredFailureMsg(
11730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11731 "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 -070011732 m_errorMonitor->SetUnexpectedError(
11733 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11734 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011735 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 -060011736 m_errorMonitor->VerifyFound();
11737 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11739 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011740 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011741 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 -060011742 m_errorMonitor->VerifyFound();
11743 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11745 "Cannot copy from an image whose dest layout is "
11746 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11747 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011748 m_errorMonitor->SetUnexpectedError(
11749 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011750 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 -060011751 m_errorMonitor->VerifyFound();
11752 m_errorMonitor->SetDesiredFailureMsg(
11753 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11754 "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 -070011755 m_errorMonitor->SetUnexpectedError(
11756 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11757 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011758 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 -060011759 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011760
Cort3b021012016-12-07 12:00:57 -080011761 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11762 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11763 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11764 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11765 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11766 transfer_dst_image_barrier[0].srcAccessMask = 0;
11767 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11768 transfer_dst_image_barrier[0].image = dst_image;
11769 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11770 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11771 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11772 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11773 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11774 transfer_dst_image_barrier[0].image = depth_image;
11775 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11776 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11777 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11778
11779 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011780 VkClearColorValue color_clear_value = {};
11781 VkImageSubresourceRange clear_range;
11782 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11783 clear_range.baseMipLevel = 0;
11784 clear_range.baseArrayLayer = 0;
11785 clear_range.layerCount = 1;
11786 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011787
Cort3b021012016-12-07 12:00:57 -080011788 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11789 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011792 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011793 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011794 // Fail due to provided layout not matching actual current layout for color clear.
11795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011796 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011797 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011798
Cort530cf382016-12-08 09:59:47 -080011799 VkClearDepthStencilValue depth_clear_value = {};
11800 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011801
11802 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11803 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011806 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011807 m_errorMonitor->VerifyFound();
11808 // Fail due to provided layout not matching actual current layout for depth clear.
11809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011810 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011811 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011812
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011813 // Now cause error due to bad image layout transition in PipelineBarrier
11814 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011815 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011816 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011817 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011818 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011819 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11820 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011821 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11823 "You cannot transition the layout of aspect 1 from "
11824 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11825 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011826 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11827 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011828 m_errorMonitor->VerifyFound();
11829
11830 // Finally some layout errors at RenderPass create time
11831 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11832 VkAttachmentReference attach = {};
11833 // perf warning for GENERAL layout w/ non-DS input attachment
11834 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11835 VkSubpassDescription subpass = {};
11836 subpass.inputAttachmentCount = 1;
11837 subpass.pInputAttachments = &attach;
11838 VkRenderPassCreateInfo rpci = {};
11839 rpci.subpassCount = 1;
11840 rpci.pSubpasses = &subpass;
11841 rpci.attachmentCount = 1;
11842 VkAttachmentDescription attach_desc = {};
11843 attach_desc.format = VK_FORMAT_UNDEFINED;
11844 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011845 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011846 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11848 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011849 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11850 m_errorMonitor->VerifyFound();
11851 // error w/ non-general layout
11852 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11853
11854 m_errorMonitor->SetDesiredFailureMsg(
11855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11856 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11857 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11858 m_errorMonitor->VerifyFound();
11859 subpass.inputAttachmentCount = 0;
11860 subpass.colorAttachmentCount = 1;
11861 subpass.pColorAttachments = &attach;
11862 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11863 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11865 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011866 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11867 m_errorMonitor->VerifyFound();
11868 // error w/ non-color opt or GENERAL layout for color attachment
11869 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11870 m_errorMonitor->SetDesiredFailureMsg(
11871 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11872 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11873 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11874 m_errorMonitor->VerifyFound();
11875 subpass.colorAttachmentCount = 0;
11876 subpass.pDepthStencilAttachment = &attach;
11877 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11878 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11880 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011881 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11882 m_errorMonitor->VerifyFound();
11883 // error w/ non-ds opt or GENERAL layout for color attachment
11884 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11886 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11887 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011888 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11889 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011890 // For this error we need a valid renderpass so create default one
11891 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11892 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070011893 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011894 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11895 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11896 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11897 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11898 // Can't do a CLEAR load on READ_ONLY initialLayout
11899 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11900 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11901 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11903 " with invalid first layout "
11904 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11905 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11907 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011908
Cort3b021012016-12-07 12:00:57 -080011909 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11910 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11911 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011912 vkDestroyImage(m_device->device(), src_image, NULL);
11913 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011914 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011915}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011916
Tobin Ehlise0936662016-10-11 08:10:51 -060011917TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11918 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11919 VkResult err;
11920
11921 ASSERT_NO_FATAL_FAILURE(InitState());
11922
11923 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11924 VkImageTiling tiling;
11925 VkFormatProperties format_properties;
11926 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11927 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11928 tiling = VK_IMAGE_TILING_LINEAR;
11929 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11930 tiling = VK_IMAGE_TILING_OPTIMAL;
11931 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011932 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011933 return;
11934 }
11935
11936 VkDescriptorPoolSize ds_type = {};
11937 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11938 ds_type.descriptorCount = 1;
11939
11940 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11941 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11942 ds_pool_ci.maxSets = 1;
11943 ds_pool_ci.poolSizeCount = 1;
11944 ds_pool_ci.pPoolSizes = &ds_type;
11945 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11946
11947 VkDescriptorPool ds_pool;
11948 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11949 ASSERT_VK_SUCCESS(err);
11950
11951 VkDescriptorSetLayoutBinding dsl_binding = {};
11952 dsl_binding.binding = 0;
11953 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11954 dsl_binding.descriptorCount = 1;
11955 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11956 dsl_binding.pImmutableSamplers = NULL;
11957
11958 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11959 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11960 ds_layout_ci.pNext = NULL;
11961 ds_layout_ci.bindingCount = 1;
11962 ds_layout_ci.pBindings = &dsl_binding;
11963
11964 VkDescriptorSetLayout ds_layout;
11965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11966 ASSERT_VK_SUCCESS(err);
11967
11968 VkDescriptorSetAllocateInfo alloc_info = {};
11969 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11970 alloc_info.descriptorSetCount = 1;
11971 alloc_info.descriptorPool = ds_pool;
11972 alloc_info.pSetLayouts = &ds_layout;
11973 VkDescriptorSet descriptor_set;
11974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11975 ASSERT_VK_SUCCESS(err);
11976
11977 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11978 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11979 pipeline_layout_ci.pNext = NULL;
11980 pipeline_layout_ci.setLayoutCount = 1;
11981 pipeline_layout_ci.pSetLayouts = &ds_layout;
11982 VkPipelineLayout pipeline_layout;
11983 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 VkImageObj image(m_device);
11987 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11988 ASSERT_TRUE(image.initialized());
11989 VkImageView view = image.targetView(tex_format);
11990
11991 VkDescriptorImageInfo image_info = {};
11992 image_info.imageView = view;
11993 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11994
11995 VkWriteDescriptorSet descriptor_write = {};
11996 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11997 descriptor_write.dstSet = descriptor_set;
11998 descriptor_write.dstBinding = 0;
11999 descriptor_write.descriptorCount = 1;
12000 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12001 descriptor_write.pImageInfo = &image_info;
12002
12003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12004 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12005 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12006 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12007 m_errorMonitor->VerifyFound();
12008
12009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12011 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12012 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12013}
12014
Mark Mueller93b938f2016-08-18 10:27:40 -060012015TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012016 TEST_DESCRIPTION(
12017 "Use vkCmdExecuteCommands with invalid state "
12018 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012019
12020 ASSERT_NO_FATAL_FAILURE(InitState());
12021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12022
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012023 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012024 const char *simultaneous_use_message2 =
12025 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12026 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012027
12028 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012029 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012030 command_buffer_allocate_info.commandPool = m_commandPool;
12031 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12032 command_buffer_allocate_info.commandBufferCount = 1;
12033
12034 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012035 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012036 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12037 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012038 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012039 command_buffer_inheritance_info.renderPass = m_renderPass;
12040 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012041
Mark Mueller93b938f2016-08-18 10:27:40 -060012042 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 command_buffer_begin_info.flags =
12044 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012045 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12046
12047 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12048 vkEndCommandBuffer(secondary_command_buffer);
12049
Mark Mueller93b938f2016-08-18 10:27:40 -060012050 VkSubmitInfo submit_info = {};
12051 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12052 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012053 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012054
Mark Mueller4042b652016-09-05 22:52:21 -060012055 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12058 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012059 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012060 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012061 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12062 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012063
Dave Houltonfbf52152017-01-06 12:55:29 -070012064 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012065 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012066 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012067
Mark Mueller4042b652016-09-05 22:52:21 -060012068 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012069 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12070 m_errorMonitor->SetUnexpectedError(
12071 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12072 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012073 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012074 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12077 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012078 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012079 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12080 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012081
12082 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012083
12084 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012085}
12086
Tony Barbour626994c2017-02-08 15:29:37 -070012087TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12088 TEST_DESCRIPTION(
12089 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12090 "errors");
12091 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12092 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12093 ASSERT_NO_FATAL_FAILURE(InitState());
12094
12095 VkCommandBuffer cmd_bufs[2];
12096 VkCommandBufferAllocateInfo alloc_info;
12097 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12098 alloc_info.pNext = NULL;
12099 alloc_info.commandBufferCount = 2;
12100 alloc_info.commandPool = m_commandPool;
12101 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12102 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12103
12104 VkCommandBufferBeginInfo cb_binfo;
12105 cb_binfo.pNext = NULL;
12106 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12107 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12108 cb_binfo.flags = 0;
12109 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12110 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12111 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12112 vkEndCommandBuffer(cmd_bufs[0]);
12113 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12114
12115 VkSubmitInfo submit_info = {};
12116 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12117 submit_info.commandBufferCount = 2;
12118 submit_info.pCommandBuffers = duplicates;
12119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12121 m_errorMonitor->VerifyFound();
12122 vkQueueWaitIdle(m_device->m_queue);
12123
12124 // Set one time use and now look for one time submit
12125 duplicates[0] = duplicates[1] = cmd_bufs[1];
12126 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12127 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12128 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12129 vkEndCommandBuffer(cmd_bufs[1]);
12130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12131 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12132 m_errorMonitor->VerifyFound();
12133 vkQueueWaitIdle(m_device->m_queue);
12134}
12135
Tobin Ehlisb093da82017-01-19 12:05:27 -070012136TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012137 TEST_DESCRIPTION(
12138 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12139 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012140
12141 ASSERT_NO_FATAL_FAILURE(InitState());
12142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12143
12144 std::vector<const char *> device_extension_names;
12145 auto features = m_device->phy().features();
12146 // Make sure gs & ts are disabled
12147 features.geometryShader = false;
12148 features.tessellationShader = false;
12149 // The sacrificial device object
12150 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12151
12152 VkCommandPoolCreateInfo pool_create_info{};
12153 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12154 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12155
12156 VkCommandPool command_pool;
12157 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12158
12159 VkCommandBufferAllocateInfo cmd = {};
12160 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12161 cmd.pNext = NULL;
12162 cmd.commandPool = command_pool;
12163 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12164 cmd.commandBufferCount = 1;
12165
12166 VkCommandBuffer cmd_buffer;
12167 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12168 ASSERT_VK_SUCCESS(err);
12169
12170 VkEvent event;
12171 VkEventCreateInfo evci = {};
12172 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12173 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12174 ASSERT_VK_SUCCESS(result);
12175
12176 VkCommandBufferBeginInfo cbbi = {};
12177 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12178 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12180 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12181 m_errorMonitor->VerifyFound();
12182
12183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12184 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12185 m_errorMonitor->VerifyFound();
12186
12187 vkDestroyEvent(test_device.handle(), event, NULL);
12188 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12189}
12190
Mark Mueller917f6bc2016-08-30 10:57:19 -060012191TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012192 TEST_DESCRIPTION(
12193 "Use vkCmdExecuteCommands with invalid state "
12194 "in primary and secondary command buffers. "
12195 "Delete objects that are inuse. Call VkQueueSubmit "
12196 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012197
12198 ASSERT_NO_FATAL_FAILURE(InitState());
12199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12200
Tony Barbour552f6c02016-12-21 14:34:07 -070012201 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012202
12203 VkEvent event;
12204 VkEventCreateInfo event_create_info = {};
12205 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12206 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012208
Tony Barbour552f6c02016-12-21 14:34:07 -070012209 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012210 vkDestroyEvent(m_device->device(), event, nullptr);
12211
12212 VkSubmitInfo submit_info = {};
12213 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12214 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012217 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12218 m_errorMonitor->VerifyFound();
12219
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012220 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012221 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12222
12223 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12224
Mark Mueller917f6bc2016-08-30 10:57:19 -060012225 VkSemaphoreCreateInfo semaphore_create_info = {};
12226 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12227 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012228 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012229 VkFenceCreateInfo fence_create_info = {};
12230 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12231 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012232 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012233
12234 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012235 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012236 descriptor_pool_type_count.descriptorCount = 1;
12237
12238 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12239 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12240 descriptor_pool_create_info.maxSets = 1;
12241 descriptor_pool_create_info.poolSizeCount = 1;
12242 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012243 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012244
12245 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012247
12248 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012249 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012250 descriptorset_layout_binding.descriptorCount = 1;
12251 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12252
12253 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012255 descriptorset_layout_create_info.bindingCount = 1;
12256 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12257
12258 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012259 ASSERT_VK_SUCCESS(
12260 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012261
12262 VkDescriptorSet descriptorset;
12263 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012264 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012265 descriptorset_allocate_info.descriptorSetCount = 1;
12266 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12267 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012268 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012269
Mark Mueller4042b652016-09-05 22:52:21 -060012270 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12271
12272 VkDescriptorBufferInfo buffer_info = {};
12273 buffer_info.buffer = buffer_test.GetBuffer();
12274 buffer_info.offset = 0;
12275 buffer_info.range = 1024;
12276
12277 VkWriteDescriptorSet write_descriptor_set = {};
12278 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12279 write_descriptor_set.dstSet = descriptorset;
12280 write_descriptor_set.descriptorCount = 1;
12281 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12282 write_descriptor_set.pBufferInfo = &buffer_info;
12283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012284 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12287 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012288
12289 VkPipelineObj pipe(m_device);
12290 pipe.AddColorAttachment();
12291 pipe.AddShader(&vs);
12292 pipe.AddShader(&fs);
12293
12294 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012295 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012296 pipeline_layout_create_info.setLayoutCount = 1;
12297 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12298
12299 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012301
12302 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12303
Tony Barbour552f6c02016-12-21 14:34:07 -070012304 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012307 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12308 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12309 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012310
Tony Barbour552f6c02016-12-21 14:34:07 -070012311 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312
Mark Mueller917f6bc2016-08-30 10:57:19 -060012313 submit_info.signalSemaphoreCount = 1;
12314 submit_info.pSignalSemaphores = &semaphore;
12315 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012316 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012317
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012319 vkDestroyEvent(m_device->device(), event, nullptr);
12320 m_errorMonitor->VerifyFound();
12321
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012323 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12324 m_errorMonitor->VerifyFound();
12325
Jeremy Hayes08369882017-02-02 10:31:06 -070012326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012327 vkDestroyFence(m_device->device(), fence, nullptr);
12328 m_errorMonitor->VerifyFound();
12329
Tobin Ehlis122207b2016-09-01 08:50:06 -070012330 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012331 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12332 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012333 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012334 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12335 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012336 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012337 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12338 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012339 vkDestroyEvent(m_device->device(), event, nullptr);
12340 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012341 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012342 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12343}
12344
Tobin Ehlis2adda372016-09-01 08:51:06 -070012345TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12346 TEST_DESCRIPTION("Delete in-use query pool.");
12347
12348 ASSERT_NO_FATAL_FAILURE(InitState());
12349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12350
12351 VkQueryPool query_pool;
12352 VkQueryPoolCreateInfo query_pool_ci{};
12353 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12354 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12355 query_pool_ci.queryCount = 1;
12356 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012357 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012358 // Reset query pool to create binding with cmd buffer
12359 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12360
Tony Barbour552f6c02016-12-21 14:34:07 -070012361 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012362
12363 VkSubmitInfo submit_info = {};
12364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12365 submit_info.commandBufferCount = 1;
12366 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12367 // Submit cmd buffer and then destroy query pool while in-flight
12368 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12369
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012371 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12372 m_errorMonitor->VerifyFound();
12373
12374 vkQueueWaitIdle(m_device->m_queue);
12375 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012376 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12377 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012378 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12379}
12380
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012381TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12382 TEST_DESCRIPTION("Delete in-use pipeline.");
12383
12384 ASSERT_NO_FATAL_FAILURE(InitState());
12385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12386
12387 // Empty pipeline layout used for binding PSO
12388 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12389 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12390 pipeline_layout_ci.setLayoutCount = 0;
12391 pipeline_layout_ci.pSetLayouts = NULL;
12392
12393 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012395 ASSERT_VK_SUCCESS(err);
12396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012398 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12400 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012401 // Store pipeline handle so we can actually delete it before test finishes
12402 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012403 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012404 VkPipelineObj pipe(m_device);
12405 pipe.AddShader(&vs);
12406 pipe.AddShader(&fs);
12407 pipe.AddColorAttachment();
12408 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12409 delete_this_pipeline = pipe.handle();
12410
Tony Barbour552f6c02016-12-21 14:34:07 -070012411 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012412 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012413 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012414
Tony Barbour552f6c02016-12-21 14:34:07 -070012415 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012416
12417 VkSubmitInfo submit_info = {};
12418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12419 submit_info.commandBufferCount = 1;
12420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12421 // Submit cmd buffer and then pipeline destroyed while in-flight
12422 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012423 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012424 m_errorMonitor->VerifyFound();
12425 // Make sure queue finished and then actually delete pipeline
12426 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012427 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12428 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012429 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12430 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12431}
12432
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012433TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12434 TEST_DESCRIPTION("Delete in-use imageView.");
12435
12436 ASSERT_NO_FATAL_FAILURE(InitState());
12437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12438
12439 VkDescriptorPoolSize ds_type_count;
12440 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12441 ds_type_count.descriptorCount = 1;
12442
12443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12445 ds_pool_ci.maxSets = 1;
12446 ds_pool_ci.poolSizeCount = 1;
12447 ds_pool_ci.pPoolSizes = &ds_type_count;
12448
12449 VkDescriptorPool ds_pool;
12450 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12451 ASSERT_VK_SUCCESS(err);
12452
12453 VkSamplerCreateInfo sampler_ci = {};
12454 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12455 sampler_ci.pNext = NULL;
12456 sampler_ci.magFilter = VK_FILTER_NEAREST;
12457 sampler_ci.minFilter = VK_FILTER_NEAREST;
12458 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12459 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12460 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12461 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12462 sampler_ci.mipLodBias = 1.0;
12463 sampler_ci.anisotropyEnable = VK_FALSE;
12464 sampler_ci.maxAnisotropy = 1;
12465 sampler_ci.compareEnable = VK_FALSE;
12466 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12467 sampler_ci.minLod = 1.0;
12468 sampler_ci.maxLod = 1.0;
12469 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12470 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12471 VkSampler sampler;
12472
12473 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12474 ASSERT_VK_SUCCESS(err);
12475
12476 VkDescriptorSetLayoutBinding layout_binding;
12477 layout_binding.binding = 0;
12478 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12479 layout_binding.descriptorCount = 1;
12480 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12481 layout_binding.pImmutableSamplers = NULL;
12482
12483 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12484 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12485 ds_layout_ci.bindingCount = 1;
12486 ds_layout_ci.pBindings = &layout_binding;
12487 VkDescriptorSetLayout ds_layout;
12488 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12489 ASSERT_VK_SUCCESS(err);
12490
12491 VkDescriptorSetAllocateInfo alloc_info = {};
12492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12493 alloc_info.descriptorSetCount = 1;
12494 alloc_info.descriptorPool = ds_pool;
12495 alloc_info.pSetLayouts = &ds_layout;
12496 VkDescriptorSet descriptor_set;
12497 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12498 ASSERT_VK_SUCCESS(err);
12499
12500 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12501 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12502 pipeline_layout_ci.pNext = NULL;
12503 pipeline_layout_ci.setLayoutCount = 1;
12504 pipeline_layout_ci.pSetLayouts = &ds_layout;
12505
12506 VkPipelineLayout pipeline_layout;
12507 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12508 ASSERT_VK_SUCCESS(err);
12509
12510 VkImageObj image(m_device);
12511 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12512 ASSERT_TRUE(image.initialized());
12513
12514 VkImageView view;
12515 VkImageViewCreateInfo ivci = {};
12516 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12517 ivci.image = image.handle();
12518 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12519 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12520 ivci.subresourceRange.layerCount = 1;
12521 ivci.subresourceRange.baseMipLevel = 0;
12522 ivci.subresourceRange.levelCount = 1;
12523 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12524
12525 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12526 ASSERT_VK_SUCCESS(err);
12527
12528 VkDescriptorImageInfo image_info{};
12529 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12530 image_info.imageView = view;
12531 image_info.sampler = sampler;
12532
12533 VkWriteDescriptorSet descriptor_write = {};
12534 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12535 descriptor_write.dstSet = descriptor_set;
12536 descriptor_write.dstBinding = 0;
12537 descriptor_write.descriptorCount = 1;
12538 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12539 descriptor_write.pImageInfo = &image_info;
12540
12541 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12542
12543 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012544 char const *vsSource =
12545 "#version 450\n"
12546 "\n"
12547 "out gl_PerVertex { \n"
12548 " vec4 gl_Position;\n"
12549 "};\n"
12550 "void main(){\n"
12551 " gl_Position = vec4(1);\n"
12552 "}\n";
12553 char const *fsSource =
12554 "#version 450\n"
12555 "\n"
12556 "layout(set=0, binding=0) uniform sampler2D s;\n"
12557 "layout(location=0) out vec4 x;\n"
12558 "void main(){\n"
12559 " x = texture(s, vec2(1));\n"
12560 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012561 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12562 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12563 VkPipelineObj pipe(m_device);
12564 pipe.AddShader(&vs);
12565 pipe.AddShader(&fs);
12566 pipe.AddColorAttachment();
12567 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12568
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012570
Tony Barbour552f6c02016-12-21 14:34:07 -070012571 m_commandBuffer->BeginCommandBuffer();
12572 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012573 // Bind pipeline to cmd buffer
12574 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12575 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12576 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012577
12578 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12579 VkRect2D scissor = {{0, 0}, {16, 16}};
12580 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12581 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12582
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012583 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012584 m_commandBuffer->EndRenderPass();
12585 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012586 // Submit cmd buffer then destroy sampler
12587 VkSubmitInfo submit_info = {};
12588 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12589 submit_info.commandBufferCount = 1;
12590 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12591 // Submit cmd buffer and then destroy imageView while in-flight
12592 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12593
12594 vkDestroyImageView(m_device->device(), view, nullptr);
12595 m_errorMonitor->VerifyFound();
12596 vkQueueWaitIdle(m_device->m_queue);
12597 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012598 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12599 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012600 vkDestroyImageView(m_device->device(), view, NULL);
12601 vkDestroySampler(m_device->device(), sampler, nullptr);
12602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12605}
12606
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012607TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12608 TEST_DESCRIPTION("Delete in-use bufferView.");
12609
12610 ASSERT_NO_FATAL_FAILURE(InitState());
12611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12612
12613 VkDescriptorPoolSize ds_type_count;
12614 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12615 ds_type_count.descriptorCount = 1;
12616
12617 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12618 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12619 ds_pool_ci.maxSets = 1;
12620 ds_pool_ci.poolSizeCount = 1;
12621 ds_pool_ci.pPoolSizes = &ds_type_count;
12622
12623 VkDescriptorPool ds_pool;
12624 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12625 ASSERT_VK_SUCCESS(err);
12626
12627 VkDescriptorSetLayoutBinding layout_binding;
12628 layout_binding.binding = 0;
12629 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12630 layout_binding.descriptorCount = 1;
12631 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12632 layout_binding.pImmutableSamplers = NULL;
12633
12634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12636 ds_layout_ci.bindingCount = 1;
12637 ds_layout_ci.pBindings = &layout_binding;
12638 VkDescriptorSetLayout ds_layout;
12639 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12640 ASSERT_VK_SUCCESS(err);
12641
12642 VkDescriptorSetAllocateInfo alloc_info = {};
12643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12644 alloc_info.descriptorSetCount = 1;
12645 alloc_info.descriptorPool = ds_pool;
12646 alloc_info.pSetLayouts = &ds_layout;
12647 VkDescriptorSet descriptor_set;
12648 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12649 ASSERT_VK_SUCCESS(err);
12650
12651 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12652 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12653 pipeline_layout_ci.pNext = NULL;
12654 pipeline_layout_ci.setLayoutCount = 1;
12655 pipeline_layout_ci.pSetLayouts = &ds_layout;
12656
12657 VkPipelineLayout pipeline_layout;
12658 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12659 ASSERT_VK_SUCCESS(err);
12660
12661 VkBuffer buffer;
12662 uint32_t queue_family_index = 0;
12663 VkBufferCreateInfo buffer_create_info = {};
12664 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12665 buffer_create_info.size = 1024;
12666 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12667 buffer_create_info.queueFamilyIndexCount = 1;
12668 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12669
12670 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12671 ASSERT_VK_SUCCESS(err);
12672
12673 VkMemoryRequirements memory_reqs;
12674 VkDeviceMemory buffer_memory;
12675
12676 VkMemoryAllocateInfo memory_info = {};
12677 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12678 memory_info.allocationSize = 0;
12679 memory_info.memoryTypeIndex = 0;
12680
12681 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12682 memory_info.allocationSize = memory_reqs.size;
12683 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12684 ASSERT_TRUE(pass);
12685
12686 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12687 ASSERT_VK_SUCCESS(err);
12688 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12689 ASSERT_VK_SUCCESS(err);
12690
12691 VkBufferView view;
12692 VkBufferViewCreateInfo bvci = {};
12693 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12694 bvci.buffer = buffer;
12695 bvci.format = VK_FORMAT_R8_UNORM;
12696 bvci.range = VK_WHOLE_SIZE;
12697
12698 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12699 ASSERT_VK_SUCCESS(err);
12700
12701 VkWriteDescriptorSet descriptor_write = {};
12702 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12703 descriptor_write.dstSet = descriptor_set;
12704 descriptor_write.dstBinding = 0;
12705 descriptor_write.descriptorCount = 1;
12706 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12707 descriptor_write.pTexelBufferView = &view;
12708
12709 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12710
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012711 char const *vsSource =
12712 "#version 450\n"
12713 "\n"
12714 "out gl_PerVertex { \n"
12715 " vec4 gl_Position;\n"
12716 "};\n"
12717 "void main(){\n"
12718 " gl_Position = vec4(1);\n"
12719 "}\n";
12720 char const *fsSource =
12721 "#version 450\n"
12722 "\n"
12723 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12724 "layout(location=0) out vec4 x;\n"
12725 "void main(){\n"
12726 " x = imageLoad(s, 0);\n"
12727 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012728 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12729 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12730 VkPipelineObj pipe(m_device);
12731 pipe.AddShader(&vs);
12732 pipe.AddShader(&fs);
12733 pipe.AddColorAttachment();
12734 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12735
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012737
Tony Barbour552f6c02016-12-21 14:34:07 -070012738 m_commandBuffer->BeginCommandBuffer();
12739 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012740 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12741 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12742 VkRect2D scissor = {{0, 0}, {16, 16}};
12743 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12744 // Bind pipeline to cmd buffer
12745 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12746 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12747 &descriptor_set, 0, nullptr);
12748 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012749 m_commandBuffer->EndRenderPass();
12750 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012751
12752 VkSubmitInfo submit_info = {};
12753 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12754 submit_info.commandBufferCount = 1;
12755 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12756 // Submit cmd buffer and then destroy bufferView while in-flight
12757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12758
12759 vkDestroyBufferView(m_device->device(), view, nullptr);
12760 m_errorMonitor->VerifyFound();
12761 vkQueueWaitIdle(m_device->m_queue);
12762 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012763 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12764 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012765 vkDestroyBufferView(m_device->device(), view, NULL);
12766 vkDestroyBuffer(m_device->device(), buffer, NULL);
12767 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12768 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12769 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12770 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12771}
12772
Tobin Ehlis209532e2016-09-07 13:52:18 -060012773TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12774 TEST_DESCRIPTION("Delete in-use sampler.");
12775
12776 ASSERT_NO_FATAL_FAILURE(InitState());
12777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12778
12779 VkDescriptorPoolSize ds_type_count;
12780 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12781 ds_type_count.descriptorCount = 1;
12782
12783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12785 ds_pool_ci.maxSets = 1;
12786 ds_pool_ci.poolSizeCount = 1;
12787 ds_pool_ci.pPoolSizes = &ds_type_count;
12788
12789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012790 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012791 ASSERT_VK_SUCCESS(err);
12792
12793 VkSamplerCreateInfo sampler_ci = {};
12794 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12795 sampler_ci.pNext = NULL;
12796 sampler_ci.magFilter = VK_FILTER_NEAREST;
12797 sampler_ci.minFilter = VK_FILTER_NEAREST;
12798 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12799 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12800 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12801 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12802 sampler_ci.mipLodBias = 1.0;
12803 sampler_ci.anisotropyEnable = VK_FALSE;
12804 sampler_ci.maxAnisotropy = 1;
12805 sampler_ci.compareEnable = VK_FALSE;
12806 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12807 sampler_ci.minLod = 1.0;
12808 sampler_ci.maxLod = 1.0;
12809 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12810 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12811 VkSampler sampler;
12812
12813 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12814 ASSERT_VK_SUCCESS(err);
12815
12816 VkDescriptorSetLayoutBinding layout_binding;
12817 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012818 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012819 layout_binding.descriptorCount = 1;
12820 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12821 layout_binding.pImmutableSamplers = NULL;
12822
12823 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12824 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12825 ds_layout_ci.bindingCount = 1;
12826 ds_layout_ci.pBindings = &layout_binding;
12827 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012829 ASSERT_VK_SUCCESS(err);
12830
12831 VkDescriptorSetAllocateInfo alloc_info = {};
12832 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12833 alloc_info.descriptorSetCount = 1;
12834 alloc_info.descriptorPool = ds_pool;
12835 alloc_info.pSetLayouts = &ds_layout;
12836 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012838 ASSERT_VK_SUCCESS(err);
12839
12840 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12841 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12842 pipeline_layout_ci.pNext = NULL;
12843 pipeline_layout_ci.setLayoutCount = 1;
12844 pipeline_layout_ci.pSetLayouts = &ds_layout;
12845
12846 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012847 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012848 ASSERT_VK_SUCCESS(err);
12849
12850 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012851 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 -060012852 ASSERT_TRUE(image.initialized());
12853
12854 VkImageView view;
12855 VkImageViewCreateInfo ivci = {};
12856 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12857 ivci.image = image.handle();
12858 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12859 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12860 ivci.subresourceRange.layerCount = 1;
12861 ivci.subresourceRange.baseMipLevel = 0;
12862 ivci.subresourceRange.levelCount = 1;
12863 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12864
12865 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12866 ASSERT_VK_SUCCESS(err);
12867
12868 VkDescriptorImageInfo image_info{};
12869 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12870 image_info.imageView = view;
12871 image_info.sampler = sampler;
12872
12873 VkWriteDescriptorSet descriptor_write = {};
12874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12875 descriptor_write.dstSet = descriptor_set;
12876 descriptor_write.dstBinding = 0;
12877 descriptor_write.descriptorCount = 1;
12878 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12879 descriptor_write.pImageInfo = &image_info;
12880
12881 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12882
12883 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012884 char const *vsSource =
12885 "#version 450\n"
12886 "\n"
12887 "out gl_PerVertex { \n"
12888 " vec4 gl_Position;\n"
12889 "};\n"
12890 "void main(){\n"
12891 " gl_Position = vec4(1);\n"
12892 "}\n";
12893 char const *fsSource =
12894 "#version 450\n"
12895 "\n"
12896 "layout(set=0, binding=0) uniform sampler2D s;\n"
12897 "layout(location=0) out vec4 x;\n"
12898 "void main(){\n"
12899 " x = texture(s, vec2(1));\n"
12900 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012901 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12902 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12903 VkPipelineObj pipe(m_device);
12904 pipe.AddShader(&vs);
12905 pipe.AddShader(&fs);
12906 pipe.AddColorAttachment();
12907 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12908
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012910
Tony Barbour552f6c02016-12-21 14:34:07 -070012911 m_commandBuffer->BeginCommandBuffer();
12912 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012913 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012914 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12915 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12916 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012917
12918 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12919 VkRect2D scissor = {{0, 0}, {16, 16}};
12920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12921 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12922
Tobin Ehlis209532e2016-09-07 13:52:18 -060012923 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012924 m_commandBuffer->EndRenderPass();
12925 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012926 // Submit cmd buffer then destroy sampler
12927 VkSubmitInfo submit_info = {};
12928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12929 submit_info.commandBufferCount = 1;
12930 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12931 // Submit cmd buffer and then destroy sampler while in-flight
12932 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12933
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012934 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012935 m_errorMonitor->VerifyFound();
12936 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012937
Tobin Ehlis209532e2016-09-07 13:52:18 -060012938 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012939 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12940 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012941 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012942 vkDestroyImageView(m_device->device(), view, NULL);
12943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12946}
12947
Mark Mueller1cd9f412016-08-25 13:23:52 -060012948TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012949 TEST_DESCRIPTION(
12950 "Call VkQueueSubmit with a semaphore that is already "
12951 "signaled but not waited on by the queue. Wait on a "
12952 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012953
12954 ASSERT_NO_FATAL_FAILURE(InitState());
12955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 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 -070012958 const char *invalid_fence_wait_message =
12959 " which has not been submitted on a Queue or during "
12960 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012961
Tony Barbour552f6c02016-12-21 14:34:07 -070012962 m_commandBuffer->BeginCommandBuffer();
12963 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012964
12965 VkSemaphoreCreateInfo semaphore_create_info = {};
12966 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12967 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012968 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012969 VkSubmitInfo submit_info = {};
12970 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12971 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012972 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012973 submit_info.signalSemaphoreCount = 1;
12974 submit_info.pSignalSemaphores = &semaphore;
12975 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012976 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012977 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012978 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012979 m_commandBuffer->BeginCommandBuffer();
12980 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012982 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12983 m_errorMonitor->VerifyFound();
12984
Mark Mueller1cd9f412016-08-25 13:23:52 -060012985 VkFenceCreateInfo fence_create_info = {};
12986 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12987 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012991 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12992 m_errorMonitor->VerifyFound();
12993
Mark Mueller4042b652016-09-05 22:52:21 -060012994 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012995 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012996 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12997}
12998
Tobin Ehlis4af23302016-07-19 10:50:30 -060012999TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013000 TEST_DESCRIPTION(
13001 "Bind a secondary command buffer with with a framebuffer "
13002 "that does not match the framebuffer for the active "
13003 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013004 ASSERT_NO_FATAL_FAILURE(InitState());
13005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13006
13007 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 VkAttachmentDescription attachment = {0,
13009 VK_FORMAT_B8G8R8A8_UNORM,
13010 VK_SAMPLE_COUNT_1_BIT,
13011 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13012 VK_ATTACHMENT_STORE_OP_STORE,
13013 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13014 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13015 VK_IMAGE_LAYOUT_UNDEFINED,
13016 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013018 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013020 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013022 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013023
13024 VkRenderPass rp;
13025 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13026 ASSERT_VK_SUCCESS(err);
13027
13028 // A compatible framebuffer.
13029 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013030 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 -060013031 ASSERT_TRUE(image.initialized());
13032
13033 VkImageViewCreateInfo ivci = {
13034 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13035 nullptr,
13036 0,
13037 image.handle(),
13038 VK_IMAGE_VIEW_TYPE_2D,
13039 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13041 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013042 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13043 };
13044 VkImageView view;
13045 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13046 ASSERT_VK_SUCCESS(err);
13047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013049 VkFramebuffer fb;
13050 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13051 ASSERT_VK_SUCCESS(err);
13052
13053 VkCommandBufferAllocateInfo cbai = {};
13054 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13055 cbai.commandPool = m_commandPool;
13056 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13057 cbai.commandBufferCount = 1;
13058
13059 VkCommandBuffer sec_cb;
13060 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13061 ASSERT_VK_SUCCESS(err);
13062 VkCommandBufferBeginInfo cbbi = {};
13063 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013064 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013065 cbii.renderPass = renderPass();
13066 cbii.framebuffer = fb;
13067 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13068 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 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 -060013070 cbbi.pInheritanceInfo = &cbii;
13071 vkBeginCommandBuffer(sec_cb, &cbbi);
13072 vkEndCommandBuffer(sec_cb);
13073
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013074 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013075 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13076 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013079 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013080 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13081 m_errorMonitor->VerifyFound();
13082 // Cleanup
13083 vkDestroyImageView(m_device->device(), view, NULL);
13084 vkDestroyRenderPass(m_device->device(), rp, NULL);
13085 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13086}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013087
13088TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013089 TEST_DESCRIPTION(
13090 "If logicOp is available on the device, set it to an "
13091 "invalid value. If logicOp is not available, attempt to "
13092 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013093 ASSERT_NO_FATAL_FAILURE(InitState());
13094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13095
13096 auto features = m_device->phy().features();
13097 // Set the expected error depending on whether or not logicOp available
13098 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13100 "If logic operations feature not "
13101 "enabled, logicOpEnable must be "
13102 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013103 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013105 }
13106 // Create a pipeline using logicOp
13107 VkResult err;
13108
13109 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13110 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13111
13112 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013113 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013114 ASSERT_VK_SUCCESS(err);
13115
13116 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13117 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13118 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013119 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013120 vp_state_ci.pViewports = &vp;
13121 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013122 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013123 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013124
13125 VkPipelineShaderStageCreateInfo shaderStages[2];
13126 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13129 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013130 shaderStages[0] = vs.GetStageCreateInfo();
13131 shaderStages[1] = fs.GetStageCreateInfo();
13132
13133 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13134 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13135
13136 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13137 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13138 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13139
13140 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13141 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013142 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013143
13144 VkPipelineColorBlendAttachmentState att = {};
13145 att.blendEnable = VK_FALSE;
13146 att.colorWriteMask = 0xf;
13147
13148 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13149 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13150 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13151 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013152 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013153 cb_ci.attachmentCount = 1;
13154 cb_ci.pAttachments = &att;
13155
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013156 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13157 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13158 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13159
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013160 VkGraphicsPipelineCreateInfo gp_ci = {};
13161 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13162 gp_ci.stageCount = 2;
13163 gp_ci.pStages = shaderStages;
13164 gp_ci.pVertexInputState = &vi_ci;
13165 gp_ci.pInputAssemblyState = &ia_ci;
13166 gp_ci.pViewportState = &vp_state_ci;
13167 gp_ci.pRasterizationState = &rs_ci;
13168 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013169 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013170 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13171 gp_ci.layout = pipeline_layout;
13172 gp_ci.renderPass = renderPass();
13173
13174 VkPipelineCacheCreateInfo pc_ci = {};
13175 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13176
13177 VkPipeline pipeline;
13178 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013180 ASSERT_VK_SUCCESS(err);
13181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013182 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013183 m_errorMonitor->VerifyFound();
13184 if (VK_SUCCESS == err) {
13185 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13186 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013187 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13188 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13189}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013190
Mike Stroyanaccf7692015-05-12 16:00:45 -060013191#if GTEST_IS_THREADSAFE
13192struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013193 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194 VkEvent event;
13195 bool bailout;
13196};
13197
Karl Schultz6addd812016-02-02 17:17:23 -070013198extern "C" void *AddToCommandBuffer(void *arg) {
13199 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013200
Mike Stroyana6d14942016-07-13 15:10:05 -060013201 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013202 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013203 if (data->bailout) {
13204 break;
13205 }
13206 }
13207 return NULL;
13208}
13209
Karl Schultz6addd812016-02-02 17:17:23 -070013210TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013211 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013214
Mike Stroyanaccf7692015-05-12 16:00:45 -060013215 ASSERT_NO_FATAL_FAILURE(InitState());
13216 ASSERT_NO_FATAL_FAILURE(InitViewport());
13217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13218
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013219 // Calls AllocateCommandBuffers
13220 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013221
13222 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013223 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013224
13225 VkEventCreateInfo event_info;
13226 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227 VkResult err;
13228
13229 memset(&event_info, 0, sizeof(event_info));
13230 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13231
Chia-I Wuf7458c52015-10-26 21:10:41 +080013232 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233 ASSERT_VK_SUCCESS(err);
13234
Mike Stroyanaccf7692015-05-12 16:00:45 -060013235 err = vkResetEvent(device(), event);
13236 ASSERT_VK_SUCCESS(err);
13237
13238 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013239 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013240 data.event = event;
13241 data.bailout = false;
13242 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013243
13244 // First do some correct operations using multiple threads.
13245 // Add many entries to command buffer from another thread.
13246 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13247 // Make non-conflicting calls from this thread at the same time.
13248 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013249 uint32_t count;
13250 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013251 }
13252 test_platform_thread_join(thread, NULL);
13253
13254 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013255 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013256 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013257 // Add many entries to command buffer from this thread at the same time.
13258 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013259
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013260 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013261 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013262
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013263 m_errorMonitor->SetBailout(NULL);
13264
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013265 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013266
Chia-I Wuf7458c52015-10-26 21:10:41 +080013267 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013268}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013269#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013270
Karl Schultz6addd812016-02-02 17:17:23 -070013271TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013272 TEST_DESCRIPTION(
13273 "Test that an error is produced for a spirv module "
13274 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013277
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013278 ASSERT_NO_FATAL_FAILURE(InitState());
13279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13280
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013281 VkShaderModule module;
13282 VkShaderModuleCreateInfo moduleCreateInfo;
13283 struct icd_spv_header spv;
13284
13285 spv.magic = ICD_SPV_MAGIC;
13286 spv.version = ICD_SPV_VERSION;
13287 spv.gen_magic = 0;
13288
13289 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13290 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013291 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292 moduleCreateInfo.codeSize = 4;
13293 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013294 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013296 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013297}
13298
Karl Schultz6addd812016-02-02 17:17:23 -070013299TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013300 TEST_DESCRIPTION(
13301 "Test that an error is produced for a spirv module "
13302 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013305
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013306 ASSERT_NO_FATAL_FAILURE(InitState());
13307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13308
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013309 VkShaderModule module;
13310 VkShaderModuleCreateInfo moduleCreateInfo;
13311 struct icd_spv_header spv;
13312
13313 spv.magic = ~ICD_SPV_MAGIC;
13314 spv.version = ICD_SPV_VERSION;
13315 spv.gen_magic = 0;
13316
13317 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13318 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013319 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013320 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13321 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013322 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013324 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013325}
13326
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013327#if 0
13328// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013329TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013331 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013332
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013333 ASSERT_NO_FATAL_FAILURE(InitState());
13334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13335
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013336 VkShaderModule module;
13337 VkShaderModuleCreateInfo moduleCreateInfo;
13338 struct icd_spv_header spv;
13339
13340 spv.magic = ICD_SPV_MAGIC;
13341 spv.version = ~ICD_SPV_VERSION;
13342 spv.gen_magic = 0;
13343
13344 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13345 moduleCreateInfo.pNext = NULL;
13346
Karl Schultz6addd812016-02-02 17:17:23 -070013347 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013348 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13349 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013350 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013352 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013353}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013354#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013355
Karl Schultz6addd812016-02-02 17:17:23 -070013356TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013357 TEST_DESCRIPTION(
13358 "Test that a warning is produced for a vertex output that "
13359 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013361
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013364
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013365 char const *vsSource =
13366 "#version 450\n"
13367 "\n"
13368 "layout(location=0) out float x;\n"
13369 "out gl_PerVertex {\n"
13370 " vec4 gl_Position;\n"
13371 "};\n"
13372 "void main(){\n"
13373 " gl_Position = vec4(1);\n"
13374 " x = 0;\n"
13375 "}\n";
13376 char const *fsSource =
13377 "#version 450\n"
13378 "\n"
13379 "layout(location=0) out vec4 color;\n"
13380 "void main(){\n"
13381 " color = vec4(1);\n"
13382 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013383
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013386
13387 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013388 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013389 pipe.AddShader(&vs);
13390 pipe.AddShader(&fs);
13391
Chris Forbes9f7ff632015-05-25 11:13:08 +120013392 VkDescriptorSetObj descriptorSet(m_device);
13393 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013394 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013395
Tony Barbour5781e8f2015-08-04 16:23:11 -060013396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013398 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013399}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013400
Mark Mueller098c9cb2016-09-08 09:01:57 -060013401TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13402 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13403
13404 ASSERT_NO_FATAL_FAILURE(InitState());
13405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13406
13407 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013408 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013409
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013410 char const *vsSource =
13411 "#version 450\n"
13412 "\n"
13413 "out gl_PerVertex {\n"
13414 " vec4 gl_Position;\n"
13415 "};\n"
13416 "void main(){\n"
13417 " gl_Position = vec4(1);\n"
13418 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013419
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013420 char const *fsSource =
13421 "#version 450\n"
13422 "\n"
13423 "layout (constant_id = 0) const float r = 0.0f;\n"
13424 "layout(location = 0) out vec4 uFragColor;\n"
13425 "void main(){\n"
13426 " uFragColor = vec4(r,1,0,1);\n"
13427 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013428
13429 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13430 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13431
13432 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13433 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13434
13435 VkPipelineLayout pipeline_layout;
13436 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13437
13438 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13439 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13440 vp_state_create_info.viewportCount = 1;
13441 VkViewport viewport = {};
13442 vp_state_create_info.pViewports = &viewport;
13443 vp_state_create_info.scissorCount = 1;
13444 VkRect2D scissors = {};
13445 vp_state_create_info.pScissors = &scissors;
13446
13447 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13448
13449 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13450 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13451 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13452 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13453
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013454 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013455
13456 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13457 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13458
13459 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13460 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13461 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13462
13463 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13464 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13465 rasterization_state_create_info.pNext = nullptr;
13466 rasterization_state_create_info.lineWidth = 1.0f;
13467 rasterization_state_create_info.rasterizerDiscardEnable = true;
13468
13469 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13470 color_blend_attachment_state.blendEnable = VK_FALSE;
13471 color_blend_attachment_state.colorWriteMask = 0xf;
13472
13473 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13474 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13475 color_blend_state_create_info.attachmentCount = 1;
13476 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13477
13478 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13479 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13480 graphicspipe_create_info.stageCount = 2;
13481 graphicspipe_create_info.pStages = shader_stage_create_info;
13482 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13483 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13484 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13485 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13486 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13487 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13488 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13489 graphicspipe_create_info.layout = pipeline_layout;
13490 graphicspipe_create_info.renderPass = renderPass();
13491
13492 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13493 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13494
13495 VkPipelineCache pipelineCache;
13496 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13497
13498 // This structure maps constant ids to data locations.
13499 const VkSpecializationMapEntry entry =
13500 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013501 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013502
13503 uint32_t data = 1;
13504
13505 // Set up the info describing spec map and data
13506 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013507 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013508 };
13509 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13510
13511 VkPipeline pipeline;
13512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13513 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13514 m_errorMonitor->VerifyFound();
13515
13516 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13517 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13518}
13519
13520TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13521 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13522
13523 ASSERT_NO_FATAL_FAILURE(InitState());
13524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13525
13526 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13527
13528 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13529 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13530 descriptor_pool_type_count[0].descriptorCount = 1;
13531 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13532 descriptor_pool_type_count[1].descriptorCount = 1;
13533
13534 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13535 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13536 descriptor_pool_create_info.maxSets = 1;
13537 descriptor_pool_create_info.poolSizeCount = 2;
13538 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13539 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13540
13541 VkDescriptorPool descriptorset_pool;
13542 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13543
13544 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13545 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13546 descriptorset_layout_binding.descriptorCount = 1;
13547 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13548
13549 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13550 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13551 descriptorset_layout_create_info.bindingCount = 1;
13552 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13553
13554 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013555 ASSERT_VK_SUCCESS(
13556 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013557
13558 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13559 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13560 descriptorset_allocate_info.descriptorSetCount = 1;
13561 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13562 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13563 VkDescriptorSet descriptorset;
13564 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13565
13566 // Challenge core_validation with a non uniform buffer type.
13567 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013569 char const *vsSource =
13570 "#version 450\n"
13571 "\n"
13572 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13573 " mat4 mvp;\n"
13574 "} ubuf;\n"
13575 "out gl_PerVertex {\n"
13576 " vec4 gl_Position;\n"
13577 "};\n"
13578 "void main(){\n"
13579 " gl_Position = ubuf.mvp * vec4(1);\n"
13580 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013581
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013582 char const *fsSource =
13583 "#version 450\n"
13584 "\n"
13585 "layout(location = 0) out vec4 uFragColor;\n"
13586 "void main(){\n"
13587 " uFragColor = vec4(0,1,0,1);\n"
13588 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013589
13590 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13591 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13592
13593 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13594 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13595 pipeline_layout_create_info.setLayoutCount = 1;
13596 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13597
13598 VkPipelineLayout pipeline_layout;
13599 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13600
13601 VkPipelineObj pipe(m_device);
13602 pipe.AddColorAttachment();
13603 pipe.AddShader(&vs);
13604 pipe.AddShader(&fs);
13605
13606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13607 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13608 m_errorMonitor->VerifyFound();
13609
13610 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13611 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13612 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13613}
13614
13615TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13616 TEST_DESCRIPTION(
13617 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13618
13619 ASSERT_NO_FATAL_FAILURE(InitState());
13620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13621
13622 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13623
13624 VkDescriptorPoolSize descriptor_pool_type_count = {};
13625 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13626 descriptor_pool_type_count.descriptorCount = 1;
13627
13628 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13629 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13630 descriptor_pool_create_info.maxSets = 1;
13631 descriptor_pool_create_info.poolSizeCount = 1;
13632 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13633 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13634
13635 VkDescriptorPool descriptorset_pool;
13636 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13637
13638 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13639 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13640 descriptorset_layout_binding.descriptorCount = 1;
13641 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13642 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13643
13644 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13645 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13646 descriptorset_layout_create_info.bindingCount = 1;
13647 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13648
13649 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013650 ASSERT_VK_SUCCESS(
13651 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013652
13653 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13654 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13655 descriptorset_allocate_info.descriptorSetCount = 1;
13656 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13657 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13658 VkDescriptorSet descriptorset;
13659 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13660
13661 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13662
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013663 char const *vsSource =
13664 "#version 450\n"
13665 "\n"
13666 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13667 " mat4 mvp;\n"
13668 "} ubuf;\n"
13669 "out gl_PerVertex {\n"
13670 " vec4 gl_Position;\n"
13671 "};\n"
13672 "void main(){\n"
13673 " gl_Position = ubuf.mvp * vec4(1);\n"
13674 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013675
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013676 char const *fsSource =
13677 "#version 450\n"
13678 "\n"
13679 "layout(location = 0) out vec4 uFragColor;\n"
13680 "void main(){\n"
13681 " uFragColor = vec4(0,1,0,1);\n"
13682 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013683
13684 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13685 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13686
13687 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13688 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13689 pipeline_layout_create_info.setLayoutCount = 1;
13690 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13691
13692 VkPipelineLayout pipeline_layout;
13693 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13694
13695 VkPipelineObj pipe(m_device);
13696 pipe.AddColorAttachment();
13697 pipe.AddShader(&vs);
13698 pipe.AddShader(&fs);
13699
13700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13702 m_errorMonitor->VerifyFound();
13703
13704 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13705 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13706 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13707}
13708
13709TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013710 TEST_DESCRIPTION(
13711 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13712 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013713
13714 ASSERT_NO_FATAL_FAILURE(InitState());
13715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13716
13717 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013718 "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 -060013719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013720 char const *vsSource =
13721 "#version 450\n"
13722 "\n"
13723 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13724 "out gl_PerVertex {\n"
13725 " vec4 gl_Position;\n"
13726 "};\n"
13727 "void main(){\n"
13728 " gl_Position = vec4(consts.x);\n"
13729 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013731 char const *fsSource =
13732 "#version 450\n"
13733 "\n"
13734 "layout(location = 0) out vec4 uFragColor;\n"
13735 "void main(){\n"
13736 " uFragColor = vec4(0,1,0,1);\n"
13737 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013738
13739 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13740 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13741
13742 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13743 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13744
13745 // Set up a push constant range
13746 VkPushConstantRange push_constant_ranges = {};
13747 // Set to the wrong stage to challenge core_validation
13748 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13749 push_constant_ranges.size = 4;
13750
13751 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13752 pipeline_layout_create_info.pushConstantRangeCount = 1;
13753
13754 VkPipelineLayout pipeline_layout;
13755 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13756
13757 VkPipelineObj pipe(m_device);
13758 pipe.AddColorAttachment();
13759 pipe.AddShader(&vs);
13760 pipe.AddShader(&fs);
13761
13762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13763 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13764 m_errorMonitor->VerifyFound();
13765
13766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13767}
13768
13769TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13770 TEST_DESCRIPTION(
13771 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13772
13773 ASSERT_NO_FATAL_FAILURE(InitState());
13774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13775
13776 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013777 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013778
13779 // Some awkward steps are required to test with custom device features.
13780 std::vector<const char *> device_extension_names;
13781 auto features = m_device->phy().features();
13782 // Disable support for 64 bit floats
13783 features.shaderFloat64 = false;
13784 // The sacrificial device object
13785 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13786
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013787 char const *vsSource =
13788 "#version 450\n"
13789 "\n"
13790 "out gl_PerVertex {\n"
13791 " vec4 gl_Position;\n"
13792 "};\n"
13793 "void main(){\n"
13794 " gl_Position = vec4(1);\n"
13795 "}\n";
13796 char const *fsSource =
13797 "#version 450\n"
13798 "\n"
13799 "layout(location=0) out vec4 color;\n"
13800 "void main(){\n"
13801 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13802 " color = vec4(green);\n"
13803 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013804
13805 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13806 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13807
13808 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013809
13810 VkPipelineObj pipe(&test_device);
13811 pipe.AddColorAttachment();
13812 pipe.AddShader(&vs);
13813 pipe.AddShader(&fs);
13814
13815 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13816 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13817 VkPipelineLayout pipeline_layout;
13818 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13819
13820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13821 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13822 m_errorMonitor->VerifyFound();
13823
13824 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13825}
13826
13827TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13828 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13829
13830 ASSERT_NO_FATAL_FAILURE(InitState());
13831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13832
13833 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13834
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013835 char const *vsSource =
13836 "#version 450\n"
13837 "\n"
13838 "out gl_PerVertex {\n"
13839 " vec4 gl_Position;\n"
13840 "};\n"
13841 "layout(xfb_buffer = 1) out;"
13842 "void main(){\n"
13843 " gl_Position = vec4(1);\n"
13844 "}\n";
13845 char const *fsSource =
13846 "#version 450\n"
13847 "\n"
13848 "layout(location=0) out vec4 color;\n"
13849 "void main(){\n"
13850 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13851 " color = vec4(green);\n"
13852 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013853
13854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13856
13857 VkPipelineObj pipe(m_device);
13858 pipe.AddColorAttachment();
13859 pipe.AddShader(&vs);
13860 pipe.AddShader(&fs);
13861
13862 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13863 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13864 VkPipelineLayout pipeline_layout;
13865 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13866
13867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13868 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13869 m_errorMonitor->VerifyFound();
13870
13871 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13872}
13873
Karl Schultz6addd812016-02-02 17:17:23 -070013874TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013875 TEST_DESCRIPTION(
13876 "Test that an error is produced for a fragment shader input "
13877 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013880
Chris Forbes59cb88d2015-05-25 11:13:13 +120013881 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013883
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013884 char const *vsSource =
13885 "#version 450\n"
13886 "\n"
13887 "out gl_PerVertex {\n"
13888 " vec4 gl_Position;\n"
13889 "};\n"
13890 "void main(){\n"
13891 " gl_Position = vec4(1);\n"
13892 "}\n";
13893 char const *fsSource =
13894 "#version 450\n"
13895 "\n"
13896 "layout(location=0) in float x;\n"
13897 "layout(location=0) out vec4 color;\n"
13898 "void main(){\n"
13899 " color = vec4(x);\n"
13900 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013901
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013902 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13903 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013904
13905 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013906 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013907 pipe.AddShader(&vs);
13908 pipe.AddShader(&fs);
13909
Chris Forbes59cb88d2015-05-25 11:13:13 +120013910 VkDescriptorSetObj descriptorSet(m_device);
13911 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013912 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013913
Tony Barbour5781e8f2015-08-04 16:23:11 -060013914 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013915
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013916 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013917}
13918
Karl Schultz6addd812016-02-02 17:17:23 -070013919TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013920 TEST_DESCRIPTION(
13921 "Test that an error is produced for a fragment shader input "
13922 "within an interace block, which is not present in the outputs "
13923 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013925
13926 ASSERT_NO_FATAL_FAILURE(InitState());
13927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13928
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013929 char const *vsSource =
13930 "#version 450\n"
13931 "\n"
13932 "out gl_PerVertex {\n"
13933 " vec4 gl_Position;\n"
13934 "};\n"
13935 "void main(){\n"
13936 " gl_Position = vec4(1);\n"
13937 "}\n";
13938 char const *fsSource =
13939 "#version 450\n"
13940 "\n"
13941 "in block { layout(location=0) float x; } ins;\n"
13942 "layout(location=0) out vec4 color;\n"
13943 "void main(){\n"
13944 " color = vec4(ins.x);\n"
13945 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013946
13947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13949
13950 VkPipelineObj pipe(m_device);
13951 pipe.AddColorAttachment();
13952 pipe.AddShader(&vs);
13953 pipe.AddShader(&fs);
13954
13955 VkDescriptorSetObj descriptorSet(m_device);
13956 descriptorSet.AppendDummy();
13957 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13958
13959 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13960
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013961 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013962}
13963
Karl Schultz6addd812016-02-02 17:17:23 -070013964TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013965 TEST_DESCRIPTION(
13966 "Test that an error is produced for mismatched array sizes "
13967 "across the vertex->fragment shader interface");
13968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13969 "Type mismatch on location 0.0: 'ptr to "
13970 "output arr[2] of float32' vs 'ptr to "
13971 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013972
13973 ASSERT_NO_FATAL_FAILURE(InitState());
13974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13975
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013976 char const *vsSource =
13977 "#version 450\n"
13978 "\n"
13979 "layout(location=0) out float x[2];\n"
13980 "out gl_PerVertex {\n"
13981 " vec4 gl_Position;\n"
13982 "};\n"
13983 "void main(){\n"
13984 " x[0] = 0; x[1] = 0;\n"
13985 " gl_Position = vec4(1);\n"
13986 "}\n";
13987 char const *fsSource =
13988 "#version 450\n"
13989 "\n"
13990 "layout(location=0) in float x[1];\n"
13991 "layout(location=0) out vec4 color;\n"
13992 "void main(){\n"
13993 " color = vec4(x[0]);\n"
13994 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013995
13996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13998
13999 VkPipelineObj pipe(m_device);
14000 pipe.AddColorAttachment();
14001 pipe.AddShader(&vs);
14002 pipe.AddShader(&fs);
14003
14004 VkDescriptorSetObj descriptorSet(m_device);
14005 descriptorSet.AppendDummy();
14006 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14007
14008 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014010 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014011}
14012
Karl Schultz6addd812016-02-02 17:17:23 -070014013TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014014 TEST_DESCRIPTION(
14015 "Test that an error is produced for mismatched types across "
14016 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014018
Chris Forbesb56af562015-05-25 11:13:17 +120014019 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014021
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014022 char const *vsSource =
14023 "#version 450\n"
14024 "\n"
14025 "layout(location=0) out int x;\n"
14026 "out gl_PerVertex {\n"
14027 " vec4 gl_Position;\n"
14028 "};\n"
14029 "void main(){\n"
14030 " x = 0;\n"
14031 " gl_Position = vec4(1);\n"
14032 "}\n";
14033 char const *fsSource =
14034 "#version 450\n"
14035 "\n"
14036 "layout(location=0) in float x;\n" /* VS writes int */
14037 "layout(location=0) out vec4 color;\n"
14038 "void main(){\n"
14039 " color = vec4(x);\n"
14040 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014041
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014044
14045 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014046 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014047 pipe.AddShader(&vs);
14048 pipe.AddShader(&fs);
14049
Chris Forbesb56af562015-05-25 11:13:17 +120014050 VkDescriptorSetObj descriptorSet(m_device);
14051 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014052 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014053
Tony Barbour5781e8f2015-08-04 16:23:11 -060014054 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014055
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014056 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014057}
14058
Karl Schultz6addd812016-02-02 17:17:23 -070014059TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014060 TEST_DESCRIPTION(
14061 "Test that an error is produced for mismatched types across "
14062 "the vertex->fragment shader interface, when the variable is contained within "
14063 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014065
14066 ASSERT_NO_FATAL_FAILURE(InitState());
14067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14068
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014069 char const *vsSource =
14070 "#version 450\n"
14071 "\n"
14072 "out block { layout(location=0) int x; } outs;\n"
14073 "out gl_PerVertex {\n"
14074 " vec4 gl_Position;\n"
14075 "};\n"
14076 "void main(){\n"
14077 " outs.x = 0;\n"
14078 " gl_Position = vec4(1);\n"
14079 "}\n";
14080 char const *fsSource =
14081 "#version 450\n"
14082 "\n"
14083 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14084 "layout(location=0) out vec4 color;\n"
14085 "void main(){\n"
14086 " color = vec4(ins.x);\n"
14087 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014088
14089 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14090 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14091
14092 VkPipelineObj pipe(m_device);
14093 pipe.AddColorAttachment();
14094 pipe.AddShader(&vs);
14095 pipe.AddShader(&fs);
14096
14097 VkDescriptorSetObj descriptorSet(m_device);
14098 descriptorSet.AppendDummy();
14099 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14100
14101 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14102
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014103 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014104}
14105
14106TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014107 TEST_DESCRIPTION(
14108 "Test that an error is produced for location mismatches across "
14109 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14110 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 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 +130014112
14113 ASSERT_NO_FATAL_FAILURE(InitState());
14114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14115
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014116 char const *vsSource =
14117 "#version 450\n"
14118 "\n"
14119 "out block { layout(location=1) float x; } outs;\n"
14120 "out gl_PerVertex {\n"
14121 " vec4 gl_Position;\n"
14122 "};\n"
14123 "void main(){\n"
14124 " outs.x = 0;\n"
14125 " gl_Position = vec4(1);\n"
14126 "}\n";
14127 char const *fsSource =
14128 "#version 450\n"
14129 "\n"
14130 "in block { layout(location=0) float x; } ins;\n"
14131 "layout(location=0) out vec4 color;\n"
14132 "void main(){\n"
14133 " color = vec4(ins.x);\n"
14134 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014135
14136 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14137 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14138
14139 VkPipelineObj pipe(m_device);
14140 pipe.AddColorAttachment();
14141 pipe.AddShader(&vs);
14142 pipe.AddShader(&fs);
14143
14144 VkDescriptorSetObj descriptorSet(m_device);
14145 descriptorSet.AppendDummy();
14146 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14147
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014148 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014149 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14150
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014151 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014152}
14153
14154TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014155 TEST_DESCRIPTION(
14156 "Test that an error is produced for component mismatches across the "
14157 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14158 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 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 +130014160
14161 ASSERT_NO_FATAL_FAILURE(InitState());
14162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14163
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014164 char const *vsSource =
14165 "#version 450\n"
14166 "\n"
14167 "out block { layout(location=0, component=0) float x; } outs;\n"
14168 "out gl_PerVertex {\n"
14169 " vec4 gl_Position;\n"
14170 "};\n"
14171 "void main(){\n"
14172 " outs.x = 0;\n"
14173 " gl_Position = vec4(1);\n"
14174 "}\n";
14175 char const *fsSource =
14176 "#version 450\n"
14177 "\n"
14178 "in block { layout(location=0, component=1) float x; } ins;\n"
14179 "layout(location=0) out vec4 color;\n"
14180 "void main(){\n"
14181 " color = vec4(ins.x);\n"
14182 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014183
14184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14185 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14186
14187 VkPipelineObj pipe(m_device);
14188 pipe.AddColorAttachment();
14189 pipe.AddShader(&vs);
14190 pipe.AddShader(&fs);
14191
14192 VkDescriptorSetObj descriptorSet(m_device);
14193 descriptorSet.AppendDummy();
14194 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14195
14196 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14197
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014198 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014199}
14200
Chris Forbes1f3b0152016-11-30 12:48:40 +130014201TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14202 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14203
14204 ASSERT_NO_FATAL_FAILURE(InitState());
14205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14206
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014207 char const *vsSource =
14208 "#version 450\n"
14209 "layout(location=0) out mediump float x;\n"
14210 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14211 char const *fsSource =
14212 "#version 450\n"
14213 "layout(location=0) in highp float x;\n"
14214 "layout(location=0) out vec4 color;\n"
14215 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014216
14217 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14218 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14219
14220 VkPipelineObj pipe(m_device);
14221 pipe.AddColorAttachment();
14222 pipe.AddShader(&vs);
14223 pipe.AddShader(&fs);
14224
14225 VkDescriptorSetObj descriptorSet(m_device);
14226 descriptorSet.AppendDummy();
14227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14228
14229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14230
14231 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14232
14233 m_errorMonitor->VerifyFound();
14234}
14235
Chris Forbes870a39e2016-11-30 12:55:56 +130014236TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14237 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14238
14239 ASSERT_NO_FATAL_FAILURE(InitState());
14240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 char const *vsSource =
14243 "#version 450\n"
14244 "out block { layout(location=0) mediump float x; };\n"
14245 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14246 char const *fsSource =
14247 "#version 450\n"
14248 "in block { layout(location=0) highp float x; };\n"
14249 "layout(location=0) out vec4 color;\n"
14250 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014251
14252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14254
14255 VkPipelineObj pipe(m_device);
14256 pipe.AddColorAttachment();
14257 pipe.AddShader(&vs);
14258 pipe.AddShader(&fs);
14259
14260 VkDescriptorSetObj descriptorSet(m_device);
14261 descriptorSet.AppendDummy();
14262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14263
14264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14265
14266 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14267
14268 m_errorMonitor->VerifyFound();
14269}
14270
Karl Schultz6addd812016-02-02 17:17:23 -070014271TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014272 TEST_DESCRIPTION(
14273 "Test that a warning is produced for a vertex attribute which is "
14274 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014276
Chris Forbesde136e02015-05-25 11:13:28 +120014277 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014279
14280 VkVertexInputBindingDescription input_binding;
14281 memset(&input_binding, 0, sizeof(input_binding));
14282
14283 VkVertexInputAttributeDescription input_attrib;
14284 memset(&input_attrib, 0, sizeof(input_attrib));
14285 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14286
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014287 char const *vsSource =
14288 "#version 450\n"
14289 "\n"
14290 "out gl_PerVertex {\n"
14291 " vec4 gl_Position;\n"
14292 "};\n"
14293 "void main(){\n"
14294 " gl_Position = vec4(1);\n"
14295 "}\n";
14296 char const *fsSource =
14297 "#version 450\n"
14298 "\n"
14299 "layout(location=0) out vec4 color;\n"
14300 "void main(){\n"
14301 " color = vec4(1);\n"
14302 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014303
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014304 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14305 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014306
14307 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014308 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014309 pipe.AddShader(&vs);
14310 pipe.AddShader(&fs);
14311
14312 pipe.AddVertexInputBindings(&input_binding, 1);
14313 pipe.AddVertexInputAttribs(&input_attrib, 1);
14314
Chris Forbesde136e02015-05-25 11:13:28 +120014315 VkDescriptorSetObj descriptorSet(m_device);
14316 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014317 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014318
Tony Barbour5781e8f2015-08-04 16:23:11 -060014319 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014320
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014321 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014322}
14323
Karl Schultz6addd812016-02-02 17:17:23 -070014324TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014325 TEST_DESCRIPTION(
14326 "Test that a warning is produced for a location mismatch on "
14327 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014329
14330 ASSERT_NO_FATAL_FAILURE(InitState());
14331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14332
14333 VkVertexInputBindingDescription input_binding;
14334 memset(&input_binding, 0, sizeof(input_binding));
14335
14336 VkVertexInputAttributeDescription input_attrib;
14337 memset(&input_attrib, 0, sizeof(input_attrib));
14338 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14339
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014340 char const *vsSource =
14341 "#version 450\n"
14342 "\n"
14343 "layout(location=1) in float x;\n"
14344 "out gl_PerVertex {\n"
14345 " vec4 gl_Position;\n"
14346 "};\n"
14347 "void main(){\n"
14348 " gl_Position = vec4(x);\n"
14349 "}\n";
14350 char const *fsSource =
14351 "#version 450\n"
14352 "\n"
14353 "layout(location=0) out vec4 color;\n"
14354 "void main(){\n"
14355 " color = vec4(1);\n"
14356 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014357
14358 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14359 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14360
14361 VkPipelineObj pipe(m_device);
14362 pipe.AddColorAttachment();
14363 pipe.AddShader(&vs);
14364 pipe.AddShader(&fs);
14365
14366 pipe.AddVertexInputBindings(&input_binding, 1);
14367 pipe.AddVertexInputAttribs(&input_attrib, 1);
14368
14369 VkDescriptorSetObj descriptorSet(m_device);
14370 descriptorSet.AppendDummy();
14371 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14372
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014373 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014374 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014376 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014377}
14378
Karl Schultz6addd812016-02-02 17:17:23 -070014379TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014380 TEST_DESCRIPTION(
14381 "Test that an error is produced for a vertex shader input which is not "
14382 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14384 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014385
Chris Forbes62e8e502015-05-25 11:13:29 +120014386 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014388
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014389 char const *vsSource =
14390 "#version 450\n"
14391 "\n"
14392 "layout(location=0) in vec4 x;\n" /* not provided */
14393 "out gl_PerVertex {\n"
14394 " vec4 gl_Position;\n"
14395 "};\n"
14396 "void main(){\n"
14397 " gl_Position = x;\n"
14398 "}\n";
14399 char const *fsSource =
14400 "#version 450\n"
14401 "\n"
14402 "layout(location=0) out vec4 color;\n"
14403 "void main(){\n"
14404 " color = vec4(1);\n"
14405 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014406
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014407 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14408 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014409
14410 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014411 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014412 pipe.AddShader(&vs);
14413 pipe.AddShader(&fs);
14414
Chris Forbes62e8e502015-05-25 11:13:29 +120014415 VkDescriptorSetObj descriptorSet(m_device);
14416 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014418
Tony Barbour5781e8f2015-08-04 16:23:11 -060014419 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014421 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014422}
14423
Karl Schultz6addd812016-02-02 17:17:23 -070014424TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014425 TEST_DESCRIPTION(
14426 "Test that an error is produced for a mismatch between the "
14427 "fundamental type (float/int/uint) of an attribute and the "
14428 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014429 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 -060014430
Chris Forbesc97d98e2015-05-25 11:13:31 +120014431 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014433
14434 VkVertexInputBindingDescription input_binding;
14435 memset(&input_binding, 0, sizeof(input_binding));
14436
14437 VkVertexInputAttributeDescription input_attrib;
14438 memset(&input_attrib, 0, sizeof(input_attrib));
14439 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14440
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014441 char const *vsSource =
14442 "#version 450\n"
14443 "\n"
14444 "layout(location=0) in int x;\n" /* attrib provided float */
14445 "out gl_PerVertex {\n"
14446 " vec4 gl_Position;\n"
14447 "};\n"
14448 "void main(){\n"
14449 " gl_Position = vec4(x);\n"
14450 "}\n";
14451 char const *fsSource =
14452 "#version 450\n"
14453 "\n"
14454 "layout(location=0) out vec4 color;\n"
14455 "void main(){\n"
14456 " color = vec4(1);\n"
14457 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014458
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014461
14462 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014463 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014464 pipe.AddShader(&vs);
14465 pipe.AddShader(&fs);
14466
14467 pipe.AddVertexInputBindings(&input_binding, 1);
14468 pipe.AddVertexInputAttribs(&input_attrib, 1);
14469
Chris Forbesc97d98e2015-05-25 11:13:31 +120014470 VkDescriptorSetObj descriptorSet(m_device);
14471 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014473
Tony Barbour5781e8f2015-08-04 16:23:11 -060014474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014475
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014476 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014477}
14478
Chris Forbesc68b43c2016-04-06 11:18:47 +120014479TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014480 TEST_DESCRIPTION(
14481 "Test that an error is produced for a pipeline containing multiple "
14482 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14484 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014485
14486 ASSERT_NO_FATAL_FAILURE(InitState());
14487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14488
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014489 char const *vsSource =
14490 "#version 450\n"
14491 "\n"
14492 "out gl_PerVertex {\n"
14493 " vec4 gl_Position;\n"
14494 "};\n"
14495 "void main(){\n"
14496 " gl_Position = vec4(1);\n"
14497 "}\n";
14498 char const *fsSource =
14499 "#version 450\n"
14500 "\n"
14501 "layout(location=0) out vec4 color;\n"
14502 "void main(){\n"
14503 " color = vec4(1);\n"
14504 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014505
14506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14508
14509 VkPipelineObj pipe(m_device);
14510 pipe.AddColorAttachment();
14511 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014512 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014513 pipe.AddShader(&fs);
14514
14515 VkDescriptorSetObj descriptorSet(m_device);
14516 descriptorSet.AppendDummy();
14517 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14518
14519 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14520
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014521 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014522}
14523
Chris Forbes82ff92a2016-09-09 10:50:24 +120014524TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014526
14527 ASSERT_NO_FATAL_FAILURE(InitState());
14528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014530 char const *vsSource =
14531 "#version 450\n"
14532 "out gl_PerVertex {\n"
14533 " vec4 gl_Position;\n"
14534 "};\n"
14535 "void main(){\n"
14536 " gl_Position = vec4(0);\n"
14537 "}\n";
14538 char const *fsSource =
14539 "#version 450\n"
14540 "\n"
14541 "layout(location=0) out vec4 color;\n"
14542 "void main(){\n"
14543 " color = vec4(1);\n"
14544 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014545
14546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14547 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14548
14549 VkPipelineObj pipe(m_device);
14550 pipe.AddColorAttachment();
14551 pipe.AddShader(&vs);
14552 pipe.AddShader(&fs);
14553
14554 VkDescriptorSetObj descriptorSet(m_device);
14555 descriptorSet.AppendDummy();
14556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14557
14558 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14559
14560 m_errorMonitor->VerifyFound();
14561}
14562
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014563TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14565 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14566 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014567
14568 ASSERT_NO_FATAL_FAILURE(InitState());
14569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14570
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014571 char const *vsSource =
14572 "#version 450\n"
14573 "void main(){ gl_Position = vec4(0); }\n";
14574 char const *fsSource =
14575 "#version 450\n"
14576 "\n"
14577 "layout(location=0) out vec4 color;\n"
14578 "void main(){\n"
14579 " color = vec4(1);\n"
14580 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014581
14582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14584
14585 VkPipelineObj pipe(m_device);
14586 pipe.AddColorAttachment();
14587 pipe.AddShader(&vs);
14588 pipe.AddShader(&fs);
14589
14590 VkDescriptorSetObj descriptorSet(m_device);
14591 descriptorSet.AppendDummy();
14592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14593
14594 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014595 {
14596 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14597 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14598 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014599 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014600 {
14601 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14602 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14603 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014604 },
14605 };
14606 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014607 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014608 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014609 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14610 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014611 VkRenderPass rp;
14612 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14613 ASSERT_VK_SUCCESS(err);
14614
14615 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14616
14617 m_errorMonitor->VerifyFound();
14618
14619 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14620}
14621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014622TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014623 TEST_DESCRIPTION(
14624 "Test that an error is produced for a variable output from "
14625 "the TCS without the patch decoration, but consumed in the TES "
14626 "with the decoration.");
14627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14628 "is per-vertex in tessellation control shader stage "
14629 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014630
14631 ASSERT_NO_FATAL_FAILURE(InitState());
14632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14633
Chris Forbesc1e852d2016-04-04 19:26:42 +120014634 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014635 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014636 return;
14637 }
14638
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014639 char const *vsSource =
14640 "#version 450\n"
14641 "void main(){}\n";
14642 char const *tcsSource =
14643 "#version 450\n"
14644 "layout(location=0) out int x[];\n"
14645 "layout(vertices=3) out;\n"
14646 "void main(){\n"
14647 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14648 " gl_TessLevelInner[0] = 1;\n"
14649 " x[gl_InvocationID] = gl_InvocationID;\n"
14650 "}\n";
14651 char const *tesSource =
14652 "#version 450\n"
14653 "layout(triangles, equal_spacing, cw) in;\n"
14654 "layout(location=0) patch in int x;\n"
14655 "out gl_PerVertex { vec4 gl_Position; };\n"
14656 "void main(){\n"
14657 " gl_Position.xyz = gl_TessCoord;\n"
14658 " gl_Position.w = x;\n"
14659 "}\n";
14660 char const *fsSource =
14661 "#version 450\n"
14662 "layout(location=0) out vec4 color;\n"
14663 "void main(){\n"
14664 " color = vec4(1);\n"
14665 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014666
14667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14668 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14669 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014672 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14673 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014674
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014676
14677 VkPipelineObj pipe(m_device);
14678 pipe.SetInputAssembly(&iasci);
14679 pipe.SetTessellation(&tsci);
14680 pipe.AddColorAttachment();
14681 pipe.AddShader(&vs);
14682 pipe.AddShader(&tcs);
14683 pipe.AddShader(&tes);
14684 pipe.AddShader(&fs);
14685
14686 VkDescriptorSetObj descriptorSet(m_device);
14687 descriptorSet.AppendDummy();
14688 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14689
14690 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14691
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014692 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014693}
14694
Karl Schultz6addd812016-02-02 17:17:23 -070014695TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014696 TEST_DESCRIPTION(
14697 "Test that an error is produced for a vertex attribute setup where multiple "
14698 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14700 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014701
Chris Forbes280ba2c2015-06-12 11:16:41 +120014702 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014704
14705 /* Two binding descriptions for binding 0 */
14706 VkVertexInputBindingDescription input_bindings[2];
14707 memset(input_bindings, 0, sizeof(input_bindings));
14708
14709 VkVertexInputAttributeDescription input_attrib;
14710 memset(&input_attrib, 0, sizeof(input_attrib));
14711 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014713 char const *vsSource =
14714 "#version 450\n"
14715 "\n"
14716 "layout(location=0) in float x;\n" /* attrib provided float */
14717 "out gl_PerVertex {\n"
14718 " vec4 gl_Position;\n"
14719 "};\n"
14720 "void main(){\n"
14721 " gl_Position = vec4(x);\n"
14722 "}\n";
14723 char const *fsSource =
14724 "#version 450\n"
14725 "\n"
14726 "layout(location=0) out vec4 color;\n"
14727 "void main(){\n"
14728 " color = vec4(1);\n"
14729 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014730
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014731 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14732 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014733
14734 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014735 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014736 pipe.AddShader(&vs);
14737 pipe.AddShader(&fs);
14738
14739 pipe.AddVertexInputBindings(input_bindings, 2);
14740 pipe.AddVertexInputAttribs(&input_attrib, 1);
14741
Chris Forbes280ba2c2015-06-12 11:16:41 +120014742 VkDescriptorSetObj descriptorSet(m_device);
14743 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014744 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014745
Tony Barbour5781e8f2015-08-04 16:23:11 -060014746 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014748 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014749}
Chris Forbes8f68b562015-05-25 11:13:32 +120014750
Karl Schultz6addd812016-02-02 17:17:23 -070014751TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014752 TEST_DESCRIPTION(
14753 "Test that an error is produced for a fragment shader which does not "
14754 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014756
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014757 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014759 char const *vsSource =
14760 "#version 450\n"
14761 "\n"
14762 "out gl_PerVertex {\n"
14763 " vec4 gl_Position;\n"
14764 "};\n"
14765 "void main(){\n"
14766 " gl_Position = vec4(1);\n"
14767 "}\n";
14768 char const *fsSource =
14769 "#version 450\n"
14770 "\n"
14771 "void main(){\n"
14772 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014773
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014774 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14775 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014776
14777 VkPipelineObj pipe(m_device);
14778 pipe.AddShader(&vs);
14779 pipe.AddShader(&fs);
14780
Chia-I Wu08accc62015-07-07 11:50:03 +080014781 /* set up CB 0, not written */
14782 pipe.AddColorAttachment();
14783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014784
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014785 VkDescriptorSetObj descriptorSet(m_device);
14786 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014787 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014788
Tony Barbour5781e8f2015-08-04 16:23:11 -060014789 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014790
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014791 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014792}
14793
Karl Schultz6addd812016-02-02 17:17:23 -070014794TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014795 TEST_DESCRIPTION(
14796 "Test that a warning is produced for a fragment shader which provides a spurious "
14797 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014799 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014800
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014801 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014803 char const *vsSource =
14804 "#version 450\n"
14805 "\n"
14806 "out gl_PerVertex {\n"
14807 " vec4 gl_Position;\n"
14808 "};\n"
14809 "void main(){\n"
14810 " gl_Position = vec4(1);\n"
14811 "}\n";
14812 char const *fsSource =
14813 "#version 450\n"
14814 "\n"
14815 "layout(location=0) out vec4 x;\n"
14816 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14817 "void main(){\n"
14818 " x = vec4(1);\n"
14819 " y = vec4(1);\n"
14820 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014821
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014822 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14823 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014824
14825 VkPipelineObj pipe(m_device);
14826 pipe.AddShader(&vs);
14827 pipe.AddShader(&fs);
14828
Chia-I Wu08accc62015-07-07 11:50:03 +080014829 /* set up CB 0, not written */
14830 pipe.AddColorAttachment();
14831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014832 /* FS writes CB 1, but we don't configure it */
14833
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014834 VkDescriptorSetObj descriptorSet(m_device);
14835 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014836 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014837
Tony Barbour5781e8f2015-08-04 16:23:11 -060014838 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014840 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014841}
14842
Karl Schultz6addd812016-02-02 17:17:23 -070014843TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014844 TEST_DESCRIPTION(
14845 "Test that an error is produced for a mismatch between the fundamental "
14846 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014848
Chris Forbesa36d69e2015-05-25 11:13:44 +120014849 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014851 char const *vsSource =
14852 "#version 450\n"
14853 "\n"
14854 "out gl_PerVertex {\n"
14855 " vec4 gl_Position;\n"
14856 "};\n"
14857 "void main(){\n"
14858 " gl_Position = vec4(1);\n"
14859 "}\n";
14860 char const *fsSource =
14861 "#version 450\n"
14862 "\n"
14863 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14864 "void main(){\n"
14865 " x = ivec4(1);\n"
14866 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014867
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014870
14871 VkPipelineObj pipe(m_device);
14872 pipe.AddShader(&vs);
14873 pipe.AddShader(&fs);
14874
Chia-I Wu08accc62015-07-07 11:50:03 +080014875 /* set up CB 0; type is UNORM by default */
14876 pipe.AddColorAttachment();
14877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014878
Chris Forbesa36d69e2015-05-25 11:13:44 +120014879 VkDescriptorSetObj descriptorSet(m_device);
14880 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014881 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014882
Tony Barbour5781e8f2015-08-04 16:23:11 -060014883 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014884
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014885 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014886}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014887
Karl Schultz6addd812016-02-02 17:17:23 -070014888TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014889 TEST_DESCRIPTION(
14890 "Test that an error is produced for a shader consuming a uniform "
14891 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014893
Chris Forbes556c76c2015-08-14 12:04:59 +120014894 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014895
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014896 char const *vsSource =
14897 "#version 450\n"
14898 "\n"
14899 "out gl_PerVertex {\n"
14900 " vec4 gl_Position;\n"
14901 "};\n"
14902 "void main(){\n"
14903 " gl_Position = vec4(1);\n"
14904 "}\n";
14905 char const *fsSource =
14906 "#version 450\n"
14907 "\n"
14908 "layout(location=0) out vec4 x;\n"
14909 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14910 "void main(){\n"
14911 " x = vec4(bar.y);\n"
14912 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014913
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014916
Chris Forbes556c76c2015-08-14 12:04:59 +120014917 VkPipelineObj pipe(m_device);
14918 pipe.AddShader(&vs);
14919 pipe.AddShader(&fs);
14920
14921 /* set up CB 0; type is UNORM by default */
14922 pipe.AddColorAttachment();
14923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14924
14925 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014926 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014927
14928 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14929
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014930 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014931}
14932
Chris Forbes5c59e902016-02-26 16:56:09 +130014933TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014934 TEST_DESCRIPTION(
14935 "Test that an error is produced for a shader consuming push constants "
14936 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014938
14939 ASSERT_NO_FATAL_FAILURE(InitState());
14940
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014941 char const *vsSource =
14942 "#version 450\n"
14943 "\n"
14944 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14945 "out gl_PerVertex {\n"
14946 " vec4 gl_Position;\n"
14947 "};\n"
14948 "void main(){\n"
14949 " gl_Position = vec4(consts.x);\n"
14950 "}\n";
14951 char const *fsSource =
14952 "#version 450\n"
14953 "\n"
14954 "layout(location=0) out vec4 x;\n"
14955 "void main(){\n"
14956 " x = vec4(1);\n"
14957 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014958
14959 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14960 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14961
14962 VkPipelineObj pipe(m_device);
14963 pipe.AddShader(&vs);
14964 pipe.AddShader(&fs);
14965
14966 /* set up CB 0; type is UNORM by default */
14967 pipe.AddColorAttachment();
14968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14969
14970 VkDescriptorSetObj descriptorSet(m_device);
14971 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14972
14973 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14974
14975 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014976 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014977}
14978
Chris Forbes3fb17902016-08-22 14:57:55 +120014979TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014980 TEST_DESCRIPTION(
14981 "Test that an error is produced for a shader consuming an input attachment "
14982 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14984 "consumes input attachment index 0 but not provided in subpass");
14985
14986 ASSERT_NO_FATAL_FAILURE(InitState());
14987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014988 char const *vsSource =
14989 "#version 450\n"
14990 "\n"
14991 "out gl_PerVertex {\n"
14992 " vec4 gl_Position;\n"
14993 "};\n"
14994 "void main(){\n"
14995 " gl_Position = vec4(1);\n"
14996 "}\n";
14997 char const *fsSource =
14998 "#version 450\n"
14999 "\n"
15000 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15001 "layout(location=0) out vec4 color;\n"
15002 "void main() {\n"
15003 " color = subpassLoad(x);\n"
15004 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015005
15006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15008
15009 VkPipelineObj pipe(m_device);
15010 pipe.AddShader(&vs);
15011 pipe.AddShader(&fs);
15012 pipe.AddColorAttachment();
15013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15016 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015017 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015018 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015019 ASSERT_VK_SUCCESS(err);
15020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015022 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015023 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015024 ASSERT_VK_SUCCESS(err);
15025
15026 // error here.
15027 pipe.CreateVKPipeline(pl, renderPass());
15028
15029 m_errorMonitor->VerifyFound();
15030
15031 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15032 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15033}
15034
Chris Forbes5a9a0472016-08-22 16:02:09 +120015035TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015036 TEST_DESCRIPTION(
15037 "Test that an error is produced for a shader consuming an input attachment "
15038 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15040 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15041
15042 ASSERT_NO_FATAL_FAILURE(InitState());
15043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015044 char const *vsSource =
15045 "#version 450\n"
15046 "\n"
15047 "out gl_PerVertex {\n"
15048 " vec4 gl_Position;\n"
15049 "};\n"
15050 "void main(){\n"
15051 " gl_Position = vec4(1);\n"
15052 "}\n";
15053 char const *fsSource =
15054 "#version 450\n"
15055 "\n"
15056 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15057 "layout(location=0) out vec4 color;\n"
15058 "void main() {\n"
15059 " color = subpassLoad(x);\n"
15060 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015061
15062 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15063 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15064
15065 VkPipelineObj pipe(m_device);
15066 pipe.AddShader(&vs);
15067 pipe.AddShader(&fs);
15068 pipe.AddColorAttachment();
15069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015071 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15072 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015073 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015074 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015075 ASSERT_VK_SUCCESS(err);
15076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015078 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015080 ASSERT_VK_SUCCESS(err);
15081
15082 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015083 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15084 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15085 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15086 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15087 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 +120015088 };
15089 VkAttachmentReference color = {
15090 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15091 };
15092 VkAttachmentReference input = {
15093 1, VK_IMAGE_LAYOUT_GENERAL,
15094 };
15095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015099 VkRenderPass rp;
15100 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15101 ASSERT_VK_SUCCESS(err);
15102
15103 // error here.
15104 pipe.CreateVKPipeline(pl, rp);
15105
15106 m_errorMonitor->VerifyFound();
15107
15108 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15109 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15110 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15111}
15112
Chris Forbes541f7b02016-08-22 15:30:27 +120015113TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015114 TEST_DESCRIPTION(
15115 "Test that an error is produced for a shader consuming an input attachment "
15116 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015118 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015119
15120 ASSERT_NO_FATAL_FAILURE(InitState());
15121
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015122 char const *vsSource =
15123 "#version 450\n"
15124 "\n"
15125 "out gl_PerVertex {\n"
15126 " vec4 gl_Position;\n"
15127 "};\n"
15128 "void main(){\n"
15129 " gl_Position = vec4(1);\n"
15130 "}\n";
15131 char const *fsSource =
15132 "#version 450\n"
15133 "\n"
15134 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15135 "layout(location=0) out vec4 color;\n"
15136 "void main() {\n"
15137 " color = subpassLoad(xs[0]);\n"
15138 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015139
15140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15142
15143 VkPipelineObj pipe(m_device);
15144 pipe.AddShader(&vs);
15145 pipe.AddShader(&fs);
15146 pipe.AddColorAttachment();
15147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015149 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15150 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015151 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015153 ASSERT_VK_SUCCESS(err);
15154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015155 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015156 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015157 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015158 ASSERT_VK_SUCCESS(err);
15159
15160 // error here.
15161 pipe.CreateVKPipeline(pl, renderPass());
15162
15163 m_errorMonitor->VerifyFound();
15164
15165 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15166 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15167}
15168
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015169TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015170 TEST_DESCRIPTION(
15171 "Test that an error is produced for a compute pipeline consuming a "
15172 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015174
15175 ASSERT_NO_FATAL_FAILURE(InitState());
15176
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015177 char const *csSource =
15178 "#version 450\n"
15179 "\n"
15180 "layout(local_size_x=1) in;\n"
15181 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15182 "void main(){\n"
15183 " x = vec4(1);\n"
15184 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015185
15186 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15187
15188 VkDescriptorSetObj descriptorSet(m_device);
15189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15192 nullptr,
15193 0,
15194 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15195 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15196 descriptorSet.GetPipelineLayout(),
15197 VK_NULL_HANDLE,
15198 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015199
15200 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015201 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015202
15203 m_errorMonitor->VerifyFound();
15204
15205 if (err == VK_SUCCESS) {
15206 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15207 }
15208}
15209
Chris Forbes22a9b092016-07-19 14:34:05 +120015210TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015211 TEST_DESCRIPTION(
15212 "Test that an error is produced for a pipeline consuming a "
15213 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15215 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015216
15217 ASSERT_NO_FATAL_FAILURE(InitState());
15218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15220 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015221 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015223 ASSERT_VK_SUCCESS(err);
15224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015226 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015227 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015228 ASSERT_VK_SUCCESS(err);
15229
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015230 char const *csSource =
15231 "#version 450\n"
15232 "\n"
15233 "layout(local_size_x=1) in;\n"
15234 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15235 "void main() {\n"
15236 " x.x = 1.0f;\n"
15237 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015238 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015240 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15241 nullptr,
15242 0,
15243 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15244 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15245 pl,
15246 VK_NULL_HANDLE,
15247 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015248
15249 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015251
15252 m_errorMonitor->VerifyFound();
15253
15254 if (err == VK_SUCCESS) {
15255 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15256 }
15257
15258 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15259 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15260}
15261
Chris Forbes50020592016-07-27 13:52:41 +120015262TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015263 TEST_DESCRIPTION(
15264 "Test that an error is produced when an image view type "
15265 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 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 +120015268
15269 ASSERT_NO_FATAL_FAILURE(InitState());
15270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015272 char const *vsSource =
15273 "#version 450\n"
15274 "\n"
15275 "out gl_PerVertex { vec4 gl_Position; };\n"
15276 "void main() { gl_Position = vec4(0); }\n";
15277 char const *fsSource =
15278 "#version 450\n"
15279 "\n"
15280 "layout(set=0, binding=0) uniform sampler3D s;\n"
15281 "layout(location=0) out vec4 color;\n"
15282 "void main() {\n"
15283 " color = texture(s, vec3(0));\n"
15284 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15287
15288 VkPipelineObj pipe(m_device);
15289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291 pipe.AddColorAttachment();
15292
15293 VkTextureObj texture(m_device, nullptr);
15294 VkSamplerObj sampler(m_device);
15295
15296 VkDescriptorSetObj descriptorSet(m_device);
15297 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15299
15300 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15301 ASSERT_VK_SUCCESS(err);
15302
Tony Barbour552f6c02016-12-21 14:34:07 -070015303 m_commandBuffer->BeginCommandBuffer();
15304 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015305
15306 m_commandBuffer->BindPipeline(pipe);
15307 m_commandBuffer->BindDescriptorSet(descriptorSet);
15308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015312 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15313
15314 // error produced here.
15315 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15316
15317 m_errorMonitor->VerifyFound();
15318
Tony Barbour552f6c02016-12-21 14:34:07 -070015319 m_commandBuffer->EndRenderPass();
15320 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015321}
15322
Chris Forbes5533bfc2016-07-27 14:12:34 +120015323TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015324 TEST_DESCRIPTION(
15325 "Test that an error is produced when a multisampled images "
15326 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015329
15330 ASSERT_NO_FATAL_FAILURE(InitState());
15331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15332
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015333 char const *vsSource =
15334 "#version 450\n"
15335 "\n"
15336 "out gl_PerVertex { vec4 gl_Position; };\n"
15337 "void main() { gl_Position = vec4(0); }\n";
15338 char const *fsSource =
15339 "#version 450\n"
15340 "\n"
15341 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15342 "layout(location=0) out vec4 color;\n"
15343 "void main() {\n"
15344 " color = texelFetch(s, ivec2(0), 0);\n"
15345 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15348
15349 VkPipelineObj pipe(m_device);
15350 pipe.AddShader(&vs);
15351 pipe.AddShader(&fs);
15352 pipe.AddColorAttachment();
15353
15354 VkTextureObj texture(m_device, nullptr);
15355 VkSamplerObj sampler(m_device);
15356
15357 VkDescriptorSetObj descriptorSet(m_device);
15358 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15359 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15360
15361 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15362 ASSERT_VK_SUCCESS(err);
15363
Tony Barbour552f6c02016-12-21 14:34:07 -070015364 m_commandBuffer->BeginCommandBuffer();
15365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015366
15367 m_commandBuffer->BindPipeline(pipe);
15368 m_commandBuffer->BindDescriptorSet(descriptorSet);
15369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015371 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015372 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015373 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15374
15375 // error produced here.
15376 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15377
15378 m_errorMonitor->VerifyFound();
15379
Tony Barbour552f6c02016-12-21 14:34:07 -070015380 m_commandBuffer->EndRenderPass();
15381 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015382}
15383
Mark Youngc48c4c12016-04-11 14:26:49 -060015384TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015386
15387 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015388
15389 // Create an image
15390 VkImage image;
15391
Karl Schultz6addd812016-02-02 17:17:23 -070015392 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15393 const int32_t tex_width = 32;
15394 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015395
15396 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015397 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15398 image_create_info.pNext = NULL;
15399 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15400 image_create_info.format = tex_format;
15401 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015402 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015403 image_create_info.extent.depth = 1;
15404 image_create_info.mipLevels = 1;
15405 image_create_info.arrayLayers = 1;
15406 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15407 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15408 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15409 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015410
15411 // Introduce error by sending down a bogus width extent
15412 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015413 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015415 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015416}
15417
Mark Youngc48c4c12016-04-11 14:26:49 -060015418TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015420
15421 ASSERT_NO_FATAL_FAILURE(InitState());
15422
15423 // Create an image
15424 VkImage image;
15425
15426 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15427 const int32_t tex_width = 32;
15428 const int32_t tex_height = 32;
15429
15430 VkImageCreateInfo image_create_info = {};
15431 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15432 image_create_info.pNext = NULL;
15433 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15434 image_create_info.format = tex_format;
15435 image_create_info.extent.width = tex_width;
15436 image_create_info.extent.height = tex_height;
15437 image_create_info.extent.depth = 1;
15438 image_create_info.mipLevels = 1;
15439 image_create_info.arrayLayers = 1;
15440 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15441 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15442 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15443 image_create_info.flags = 0;
15444
15445 // Introduce error by sending down a bogus width extent
15446 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015447 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015448 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15449
15450 m_errorMonitor->VerifyFound();
15451}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015452
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015453TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015454 TEST_DESCRIPTION(
15455 "Create a render pass with an attachment description "
15456 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015457
15458 ASSERT_NO_FATAL_FAILURE(InitState());
15459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15460
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015462
15463 VkAttachmentReference color_attach = {};
15464 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15465 color_attach.attachment = 0;
15466 VkSubpassDescription subpass = {};
15467 subpass.colorAttachmentCount = 1;
15468 subpass.pColorAttachments = &color_attach;
15469
15470 VkRenderPassCreateInfo rpci = {};
15471 rpci.subpassCount = 1;
15472 rpci.pSubpasses = &subpass;
15473 rpci.attachmentCount = 1;
15474 VkAttachmentDescription attach_desc = {};
15475 attach_desc.format = VK_FORMAT_UNDEFINED;
15476 rpci.pAttachments = &attach_desc;
15477 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15478 VkRenderPass rp;
15479 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15480
15481 m_errorMonitor->VerifyFound();
15482
15483 if (result == VK_SUCCESS) {
15484 vkDestroyRenderPass(m_device->device(), rp, NULL);
15485 }
15486}
15487
Karl Schultz6addd812016-02-02 17:17:23 -070015488TEST_F(VkLayerTest, InvalidImageView) {
15489 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015490
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015492
Tobin Ehliscde08892015-09-22 10:11:37 -060015493 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015494
Mike Stroyana3082432015-09-25 13:39:21 -060015495 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015496 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015497
Karl Schultz6addd812016-02-02 17:17:23 -070015498 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15499 const int32_t tex_width = 32;
15500 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015501
15502 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015503 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15504 image_create_info.pNext = NULL;
15505 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15506 image_create_info.format = tex_format;
15507 image_create_info.extent.width = tex_width;
15508 image_create_info.extent.height = tex_height;
15509 image_create_info.extent.depth = 1;
15510 image_create_info.mipLevels = 1;
15511 image_create_info.arrayLayers = 1;
15512 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15513 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15514 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15515 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015516
Chia-I Wuf7458c52015-10-26 21:10:41 +080015517 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015518 ASSERT_VK_SUCCESS(err);
15519
15520 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015521 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015522 image_view_create_info.image = image;
15523 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15524 image_view_create_info.format = tex_format;
15525 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015526 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015527 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015529
15530 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015531 m_errorMonitor->SetUnexpectedError(
15532 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015533 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015534
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015535 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015536 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015537}
Mike Stroyana3082432015-09-25 13:39:21 -060015538
Mark Youngd339ba32016-05-30 13:28:35 -060015539TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15540 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015542 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015543
15544 ASSERT_NO_FATAL_FAILURE(InitState());
15545
15546 // Create an image and try to create a view with no memory backing the image
15547 VkImage image;
15548
15549 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15550 const int32_t tex_width = 32;
15551 const int32_t tex_height = 32;
15552
15553 VkImageCreateInfo image_create_info = {};
15554 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15555 image_create_info.pNext = NULL;
15556 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15557 image_create_info.format = tex_format;
15558 image_create_info.extent.width = tex_width;
15559 image_create_info.extent.height = tex_height;
15560 image_create_info.extent.depth = 1;
15561 image_create_info.mipLevels = 1;
15562 image_create_info.arrayLayers = 1;
15563 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15564 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15565 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15566 image_create_info.flags = 0;
15567
15568 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15569 ASSERT_VK_SUCCESS(err);
15570
15571 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015572 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015573 image_view_create_info.image = image;
15574 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15575 image_view_create_info.format = tex_format;
15576 image_view_create_info.subresourceRange.layerCount = 1;
15577 image_view_create_info.subresourceRange.baseMipLevel = 0;
15578 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015580
15581 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015583
15584 m_errorMonitor->VerifyFound();
15585 vkDestroyImage(m_device->device(), image, NULL);
15586 // If last error is success, it still created the view, so delete it.
15587 if (err == VK_SUCCESS) {
15588 vkDestroyImageView(m_device->device(), view, NULL);
15589 }
Mark Youngd339ba32016-05-30 13:28:35 -060015590}
15591
Karl Schultz6addd812016-02-02 17:17:23 -070015592TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015595
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015596 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015597
Karl Schultz6addd812016-02-02 17:17:23 -070015598 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015599 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015600 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015601 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015602
15603 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015604 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015605 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015606 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15607 image_view_create_info.format = tex_format;
15608 image_view_create_info.subresourceRange.baseMipLevel = 0;
15609 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015610 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015611 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015613
15614 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015615 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015616
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015617 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015618}
15619
Mike Weiblena1e13f42017-02-09 21:25:59 -070015620TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15621 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15622
15623 ASSERT_NO_FATAL_FAILURE(InitState());
15624 VkSubresourceLayout subres_layout = {};
15625
15626 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15627 {
15628 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15629 VkImageObj img(m_device);
15630 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15631 ASSERT_TRUE(img.initialized());
15632
15633 VkImageSubresource subres = {};
15634 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15635 subres.mipLevel = 0;
15636 subres.arrayLayer = 0;
15637
15638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15639 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15640 m_errorMonitor->VerifyFound();
15641 }
15642
15643 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15644 {
15645 VkImageObj img(m_device);
15646 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15647 ASSERT_TRUE(img.initialized());
15648
15649 VkImageSubresource subres = {};
15650 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15651 subres.mipLevel = 0;
15652 subres.arrayLayer = 0;
15653
15654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15656 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15657 m_errorMonitor->VerifyFound();
15658 }
15659
15660 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15661 {
15662 VkImageObj img(m_device);
15663 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15664 ASSERT_TRUE(img.initialized());
15665
15666 VkImageSubresource subres = {};
15667 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15668 subres.mipLevel = 1; // ERROR: triggers VU 00739
15669 subres.arrayLayer = 0;
15670
15671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15672 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15673 m_errorMonitor->VerifyFound();
15674 }
15675
15676 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15677 {
15678 VkImageObj img(m_device);
15679 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15680 ASSERT_TRUE(img.initialized());
15681
15682 VkImageSubresource subres = {};
15683 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15684 subres.mipLevel = 0;
15685 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15686
15687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15688 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15689 m_errorMonitor->VerifyFound();
15690 }
15691}
15692
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015693TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015694 VkResult err;
15695 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015696
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015698
Mike Stroyana3082432015-09-25 13:39:21 -060015699 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015700
15701 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015702 VkImage srcImage;
15703 VkImage dstImage;
15704 VkDeviceMemory srcMem;
15705 VkDeviceMemory destMem;
15706 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015707
15708 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15710 image_create_info.pNext = NULL;
15711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15712 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15713 image_create_info.extent.width = 32;
15714 image_create_info.extent.height = 32;
15715 image_create_info.extent.depth = 1;
15716 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015717 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015718 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15719 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15720 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15721 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015724 ASSERT_VK_SUCCESS(err);
15725
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015726 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015727 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015728 ASSERT_VK_SUCCESS(err);
15729
15730 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015731 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015732 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15733 memAlloc.pNext = NULL;
15734 memAlloc.allocationSize = 0;
15735 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015736
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015737 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015738 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015740 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015741 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015742 ASSERT_VK_SUCCESS(err);
15743
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015744 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015745 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015746 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015747 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015748 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015749 ASSERT_VK_SUCCESS(err);
15750
15751 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15752 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015753 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015754 ASSERT_VK_SUCCESS(err);
15755
Tony Barbour552f6c02016-12-21 14:34:07 -070015756 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015757 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015758 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015759 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015760 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015761 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015762 copyRegion.srcOffset.x = 0;
15763 copyRegion.srcOffset.y = 0;
15764 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015765 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015766 copyRegion.dstSubresource.mipLevel = 0;
15767 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015768 // Introduce failure by forcing the dst layerCount to differ from src
15769 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015770 copyRegion.dstOffset.x = 0;
15771 copyRegion.dstOffset.y = 0;
15772 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015773 copyRegion.extent.width = 1;
15774 copyRegion.extent.height = 1;
15775 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015777 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015778
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015779 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015780
Chia-I Wuf7458c52015-10-26 21:10:41 +080015781 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015782 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015783 vkFreeMemory(m_device->device(), srcMem, NULL);
15784 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015785}
15786
Tony Barbourd6673642016-05-05 14:46:39 -060015787TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015788 TEST_DESCRIPTION("Creating images with unsuported formats ");
15789
15790 ASSERT_NO_FATAL_FAILURE(InitState());
15791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15792 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015793 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 -060015794 VK_IMAGE_TILING_OPTIMAL, 0);
15795 ASSERT_TRUE(image.initialized());
15796
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015797 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015798 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015799 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015800 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15801 image_create_info.format = VK_FORMAT_UNDEFINED;
15802 image_create_info.extent.width = 32;
15803 image_create_info.extent.height = 32;
15804 image_create_info.extent.depth = 1;
15805 image_create_info.mipLevels = 1;
15806 image_create_info.arrayLayers = 1;
15807 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15808 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15809 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15812 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015813
15814 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015815 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15816 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15817 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15818 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015819 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15820 m_errorMonitor->VerifyFound();
15821
Tony Barbourd6673642016-05-05 14:46:39 -060015822 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015823 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015824 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15825 VkFormat format = static_cast<VkFormat>(f);
15826 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015827 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015828 unsupported = format;
15829 break;
15830 }
15831 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015832
Tony Barbourd6673642016-05-05 14:46:39 -060015833 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015834 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015836
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015837 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15838 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15839 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15840 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15841 m_errorMonitor->SetUnexpectedError(
15842 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15843 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15844 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015845 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015846 m_errorMonitor->VerifyFound();
15847 }
15848}
15849
15850TEST_F(VkLayerTest, ImageLayerViewTests) {
15851 VkResult ret;
15852 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15853
15854 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015855 auto depth_format = find_depth_stencil_format(m_device);
15856 if (!depth_format) {
15857 return;
15858 }
Tony Barbourd6673642016-05-05 14:46:39 -060015859
15860 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015861 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 -060015862 VK_IMAGE_TILING_OPTIMAL, 0);
15863 ASSERT_TRUE(image.initialized());
15864
15865 VkImageView imgView;
15866 VkImageViewCreateInfo imgViewInfo = {};
15867 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15868 imgViewInfo.image = image.handle();
15869 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15870 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15871 imgViewInfo.subresourceRange.layerCount = 1;
15872 imgViewInfo.subresourceRange.baseMipLevel = 0;
15873 imgViewInfo.subresourceRange.levelCount = 1;
15874 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15875
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015877 // View can't have baseMipLevel >= image's mipLevels - Expect
15878 // VIEW_CREATE_ERROR
15879 imgViewInfo.subresourceRange.baseMipLevel = 1;
15880 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15881 m_errorMonitor->VerifyFound();
15882 imgViewInfo.subresourceRange.baseMipLevel = 0;
15883
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015885 // View can't have baseArrayLayer >= image's arraySize - Expect
15886 // VIEW_CREATE_ERROR
15887 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15888 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15889 m_errorMonitor->VerifyFound();
15890 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15891
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015893 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15894 imgViewInfo.subresourceRange.levelCount = 0;
15895 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15896 m_errorMonitor->VerifyFound();
15897 imgViewInfo.subresourceRange.levelCount = 1;
15898
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015899 m_errorMonitor->SetDesiredFailureMsg(
15900 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15901 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015902 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15903 imgViewInfo.subresourceRange.layerCount = 0;
15904 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15905 m_errorMonitor->VerifyFound();
15906 imgViewInfo.subresourceRange.layerCount = 1;
15907
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15909 "Formats MUST be IDENTICAL unless "
15910 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15911 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015912 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070015913 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060015914 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15915 m_errorMonitor->VerifyFound();
15916 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15917
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015919 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15920 // VIEW_CREATE_ERROR
15921 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15922 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15923 m_errorMonitor->VerifyFound();
15924 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15925
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015927 // TODO: Update framework to easily passing mutable flag into ImageObj init
15928 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015929 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15930 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15931 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015932 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15933 // VIEW_CREATE_ERROR
15934 VkImageCreateInfo mutImgInfo = image.create_info();
15935 VkImage mutImage;
15936 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015937 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015938 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15939 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15940 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15941 ASSERT_VK_SUCCESS(ret);
15942 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015943 m_errorMonitor->SetUnexpectedError(
15944 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Tony Barbourd6673642016-05-05 14:46:39 -060015945 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15946 m_errorMonitor->VerifyFound();
15947 imgViewInfo.image = image.handle();
15948 vkDestroyImage(m_device->handle(), mutImage, NULL);
15949}
15950
Dave Houlton75967fc2017-03-06 17:21:16 -070015951TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
15952 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
15953
15954 ASSERT_NO_FATAL_FAILURE(InitState());
15955
15956 VkPhysicalDeviceFeatures device_features;
15957 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
15958 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
15959 if (device_features.textureCompressionBC) {
15960 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
15961 } else if (device_features.textureCompressionETC2) {
15962 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
15963 } else if (device_features.textureCompressionASTC_LDR) {
15964 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
15965 } else {
15966 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
15967 return;
15968 }
15969
15970 VkImageCreateInfo ci;
15971 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15972 ci.pNext = NULL;
15973 ci.flags = 0;
15974 ci.imageType = VK_IMAGE_TYPE_2D;
15975 ci.format = compressed_format;
15976 ci.extent = {32, 32, 1};
15977 ci.mipLevels = 6;
15978 ci.arrayLayers = 1;
15979 ci.samples = VK_SAMPLE_COUNT_1_BIT;
15980 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
15981 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15982 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15983 ci.queueFamilyIndexCount = 0;
15984 ci.pQueueFamilyIndices = NULL;
15985 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15986
15987 VkImageObj image(m_device);
15988 image.init(&ci);
15989 ASSERT_TRUE(image.initialized());
15990
15991 VkImageObj odd_image(m_device);
15992 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
15993 odd_image.init(&ci);
15994 ASSERT_TRUE(odd_image.initialized());
15995
15996 // Allocate buffers
15997 VkMemoryPropertyFlags reqs = 0;
15998 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
15999 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16000 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16001 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16002 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16003
16004 VkBufferImageCopy region = {};
16005 region.bufferRowLength = 0;
16006 region.bufferImageHeight = 0;
16007 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16008 region.imageSubresource.layerCount = 1;
16009 region.imageOffset = {0, 0, 0};
16010 region.bufferOffset = 0;
16011
16012 // start recording
16013 m_commandBuffer->BeginCommandBuffer();
16014
16015 // Mip level copies that work - 5 levels
16016 m_errorMonitor->ExpectSuccess();
16017
16018 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16019 region.imageExtent = {32, 32, 1};
16020 region.imageSubresource.mipLevel = 0;
16021 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16022 &region);
16023 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16024 &region);
16025
16026 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16027 region.imageExtent = {8, 8, 1};
16028 region.imageSubresource.mipLevel = 2;
16029 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16030 &region);
16031 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16032 &region);
16033
16034 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16035 region.imageExtent = {4, 4, 1};
16036 region.imageSubresource.mipLevel = 3;
16037 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16038 &region);
16039 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16040 &region);
16041
16042 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16043 region.imageExtent = {2, 2, 1};
16044 region.imageSubresource.mipLevel = 4;
16045 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16046 &region);
16047 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16048 &region);
16049
16050 region.imageExtent = {1, 1, 1};
16051 region.imageSubresource.mipLevel = 5;
16052 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16053 &region);
16054 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16055 &region);
16056 m_errorMonitor->VerifyNotFound();
16057
16058 // Buffer must accomodate a full compressed block, regardless of texel count
16059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16060 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16061 &region);
16062 m_errorMonitor->VerifyFound();
16063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16064 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16065 &region);
16066 m_errorMonitor->VerifyFound();
16067
16068 // Copy width < compressed block size, but not the full mip width
16069 region.imageExtent = {1, 2, 1};
16070 region.imageSubresource.mipLevel = 4;
16071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16072 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16073 &region);
16074 m_errorMonitor->VerifyFound();
16075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16076 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16077 &region);
16078 m_errorMonitor->VerifyFound();
16079
16080 // Copy height < compressed block size but not the full mip height
16081 region.imageExtent = {2, 1, 1};
16082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16083 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16084 &region);
16085 m_errorMonitor->VerifyFound();
16086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16087 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16088 &region);
16089 m_errorMonitor->VerifyFound();
16090
16091 // Offsets must be multiple of compressed block size
16092 region.imageOffset = {1, 1, 0};
16093 region.imageExtent = {1, 1, 1};
16094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16095 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16096 &region);
16097 m_errorMonitor->VerifyFound();
16098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16099 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16100 &region);
16101 m_errorMonitor->VerifyFound();
16102
16103 // Offset + extent width = mip width - should succeed
16104 region.imageOffset = {4, 4, 0};
16105 region.imageExtent = {3, 4, 1};
16106 region.imageSubresource.mipLevel = 2;
16107 m_errorMonitor->ExpectSuccess();
16108 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16109 &region);
16110 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16111 &region);
16112 m_errorMonitor->VerifyNotFound();
16113
16114 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16115 region.imageExtent = {4, 4, 1};
16116 m_errorMonitor->ExpectSuccess();
16117 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16118 &region);
16119 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16120 &region);
16121 m_errorMonitor->VerifyNotFound();
16122
16123 // Offset + extent width < mip width and not a multiple of block width - should fail
16124 region.imageExtent = {3, 3, 1};
16125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16126 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16127 &region);
16128 m_errorMonitor->VerifyFound();
16129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16131 &region);
16132 m_errorMonitor->VerifyFound();
16133}
16134
Dave Houlton59a20702017-02-02 17:26:23 -070016135TEST_F(VkLayerTest, ImageBufferCopyTests) {
16136 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16137
16138 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016139 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16140 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16141 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16142 return;
16143 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016144
16145 // Bail if any dimension of transfer granularity is 0.
16146 auto index = m_device->graphics_queue_node_index_;
16147 auto queue_family_properties = m_device->phy().queue_properties();
16148 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16149 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16150 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16151 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16152 return;
16153 }
16154
Dave Houlton59a20702017-02-02 17:26:23 -070016155 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16156 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16157 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016158 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16159 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16160 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16161 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16162
Dave Houlton59a20702017-02-02 17:26:23 -070016163 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16164 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16165 VK_IMAGE_TILING_OPTIMAL, 0);
16166 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16167 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16168 VK_IMAGE_TILING_OPTIMAL, 0);
16169 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16170 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016171 ASSERT_TRUE(image_64k.initialized());
16172 ASSERT_TRUE(image_16k.initialized());
16173 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016174
Dave Houltonf3229d52017-02-21 15:59:08 -070016175 // Verify all needed Depth/Stencil formats are supported
16176 bool missing_ds_support = false;
16177 VkFormatProperties props = {0, 0, 0};
16178 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16179 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16180 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16181 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16182 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16183 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16184 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16185 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16186
16187 if (!missing_ds_support) {
16188 ds_image_4D_1S.init(
16189 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16190 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16191 VK_IMAGE_TILING_OPTIMAL, 0);
16192 ASSERT_TRUE(ds_image_4D_1S.initialized());
16193
16194 ds_image_3D_1S.init(
16195 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16196 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16197 VK_IMAGE_TILING_OPTIMAL, 0);
16198 ASSERT_TRUE(ds_image_3D_1S.initialized());
16199
16200 ds_image_2D.init(
16201 256, 256, VK_FORMAT_D16_UNORM,
16202 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16203 VK_IMAGE_TILING_OPTIMAL, 0);
16204 ASSERT_TRUE(ds_image_2D.initialized());
16205
16206 ds_image_1S.init(
16207 256, 256, VK_FORMAT_S8_UINT,
16208 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16209 VK_IMAGE_TILING_OPTIMAL, 0);
16210 ASSERT_TRUE(ds_image_1S.initialized());
16211 }
16212
16213 // Allocate buffers
16214 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016215 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016216 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16217 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16218 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16219 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016220
16221 VkBufferImageCopy region = {};
16222 region.bufferRowLength = 0;
16223 region.bufferImageHeight = 0;
16224 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16225 region.imageSubresource.layerCount = 1;
16226 region.imageOffset = {0, 0, 0};
16227 region.imageExtent = {64, 64, 1};
16228 region.bufferOffset = 0;
16229
16230 // attempt copies before putting command buffer in recording state
16231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16232 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16233 &region);
16234 m_errorMonitor->VerifyFound();
16235
16236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16237 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16238 &region);
16239 m_errorMonitor->VerifyFound();
16240
16241 // start recording
16242 m_commandBuffer->BeginCommandBuffer();
16243
16244 // successful copies
16245 m_errorMonitor->ExpectSuccess();
16246 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16247 &region);
16248 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16249 &region);
16250 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16251 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16252 &region);
16253 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16254 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16255 &region);
16256 region.imageOffset.x = 0;
16257 region.imageExtent.height = 64;
16258 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16259 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16260 &region);
16261 m_errorMonitor->VerifyNotFound();
16262
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016263 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016264 region.imageExtent = {65, 64, 1};
16265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16266 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16267 &region);
16268 m_errorMonitor->VerifyFound();
16269
16270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16271 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16272 &region);
16273 m_errorMonitor->VerifyFound();
16274
16275 // image/buffer too small (offset) on copy to image
16276 region.imageExtent = {64, 64, 1};
16277 region.imageOffset = {0, 4, 0};
16278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16279 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16280 &region);
16281 m_errorMonitor->VerifyFound();
16282
16283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16284 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16285 &region);
16286 m_errorMonitor->VerifyFound();
16287
16288 // image/buffer too small on copy to buffer
16289 region.imageExtent = {64, 64, 1};
16290 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016291 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16293 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16294 &region);
16295 m_errorMonitor->VerifyFound();
16296
16297 region.imageExtent = {64, 65, 1};
16298 region.bufferOffset = 0;
16299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16300 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16301 &region);
16302 m_errorMonitor->VerifyFound();
16303
16304 // buffer size ok but rowlength causes loose packing
16305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16306 region.imageExtent = {64, 64, 1};
16307 region.bufferRowLength = 68;
16308 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16309 &region);
16310 m_errorMonitor->VerifyFound();
16311
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016312 // An extent with zero area should produce a warning, but no error
16313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16314 region.imageExtent.width = 0;
16315 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16316 &region);
16317 m_errorMonitor->VerifyFound();
16318
Dave Houlton59a20702017-02-02 17:26:23 -070016319 // aspect bits
16320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16321 region.imageExtent = {64, 64, 1};
16322 region.bufferRowLength = 0;
16323 region.bufferImageHeight = 0;
16324 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16325 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16326 buffer_16k.handle(), 1, &region);
16327 m_errorMonitor->VerifyFound();
16328
16329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16330 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16331 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16332 &region);
16333 m_errorMonitor->VerifyFound();
16334
16335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16336 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16337 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16338 buffer_16k.handle(), 1, &region);
16339 m_errorMonitor->VerifyFound();
16340
Dave Houltonf3229d52017-02-21 15:59:08 -070016341 // Test Depth/Stencil copies
16342 if (missing_ds_support) {
16343 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16344 } else {
16345 VkBufferImageCopy ds_region = {};
16346 ds_region.bufferOffset = 0;
16347 ds_region.bufferRowLength = 0;
16348 ds_region.bufferImageHeight = 0;
16349 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16350 ds_region.imageSubresource.mipLevel = 0;
16351 ds_region.imageSubresource.baseArrayLayer = 0;
16352 ds_region.imageSubresource.layerCount = 1;
16353 ds_region.imageOffset = {0, 0, 0};
16354 ds_region.imageExtent = {256, 256, 1};
16355
16356 // Depth copies that should succeed
16357 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16359 buffer_256k.handle(), 1, &ds_region);
16360 m_errorMonitor->VerifyNotFound();
16361
16362 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16363 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16364 buffer_256k.handle(), 1, &ds_region);
16365 m_errorMonitor->VerifyNotFound();
16366
16367 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16368 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16369 buffer_128k.handle(), 1, &ds_region);
16370 m_errorMonitor->VerifyNotFound();
16371
16372 // Depth copies that should fail
16373 ds_region.bufferOffset = 4;
16374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16375 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16376 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16377 buffer_256k.handle(), 1, &ds_region);
16378 m_errorMonitor->VerifyFound();
16379
16380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16381 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16382 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16383 buffer_256k.handle(), 1, &ds_region);
16384 m_errorMonitor->VerifyFound();
16385
16386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16387 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16389 buffer_128k.handle(), 1, &ds_region);
16390 m_errorMonitor->VerifyFound();
16391
16392 // Stencil copies that should succeed
16393 ds_region.bufferOffset = 0;
16394 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16395 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16397 buffer_64k.handle(), 1, &ds_region);
16398 m_errorMonitor->VerifyNotFound();
16399
16400 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16401 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16402 buffer_64k.handle(), 1, &ds_region);
16403 m_errorMonitor->VerifyNotFound();
16404
16405 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16406 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16407 buffer_64k.handle(), 1, &ds_region);
16408 m_errorMonitor->VerifyNotFound();
16409
16410 // Stencil copies that should fail
16411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16412 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16413 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16414 buffer_16k.handle(), 1, &ds_region);
16415 m_errorMonitor->VerifyFound();
16416
16417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16418 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16419 ds_region.bufferRowLength = 260;
16420 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16421 buffer_64k.handle(), 1, &ds_region);
16422 m_errorMonitor->VerifyFound();
16423
16424 ds_region.bufferRowLength = 0;
16425 ds_region.bufferOffset = 4;
16426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16427 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16428 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16429 buffer_64k.handle(), 1, &ds_region);
16430 m_errorMonitor->VerifyFound();
16431 }
16432
Dave Houlton584d51e2017-02-16 12:52:54 -070016433 // Test compressed formats, if supported
16434 VkPhysicalDeviceFeatures device_features;
16435 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016436 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16437 device_features.textureCompressionASTC_LDR)) {
16438 printf(" No compressed formats supported - block compression tests skipped.\n");
16439 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016440 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16441 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016442 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016443 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 -070016444 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16445 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016446 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016447 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 -070016448 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016449 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16450 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016451 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016452 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16453 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016454 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16455 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016456 }
16457 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016458
Dave Houlton584d51e2017-02-16 12:52:54 -070016459 // Just fits
16460 m_errorMonitor->ExpectSuccess();
16461 region.imageExtent = {128, 128, 1};
16462 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16463 buffer_16k.handle(), 1, &region);
16464 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016465
Dave Houlton584d51e2017-02-16 12:52:54 -070016466 // with offset, too big for buffer
16467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16468 region.bufferOffset = 16;
16469 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16470 buffer_16k.handle(), 1, &region);
16471 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016472 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016473
Dave Houlton67e9b532017-03-02 17:00:10 -070016474 // extents that are not a multiple of compressed block size
16475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16476 region.imageExtent.width = 66;
16477 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16478 buffer_16k.handle(), 1, &region);
16479 m_errorMonitor->VerifyFound();
16480 region.imageExtent.width = 128;
16481
16482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016483 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016484 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16485 buffer_16k.handle(), 1, &region);
16486 m_errorMonitor->VerifyFound();
16487 region.imageExtent.height = 128;
16488
16489 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16490
16491 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16492 m_errorMonitor->ExpectSuccess();
16493 region.imageExtent.width = 66;
16494 region.imageOffset.x = 64;
16495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16496 buffer_16k.handle(), 1, &region);
16497 region.imageExtent.width = 16;
16498 region.imageOffset.x = 0;
16499 region.imageExtent.height = 2;
16500 region.imageOffset.y = 128;
16501 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016502 buffer_16k.handle(), 1, &region);
16503 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016504 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016505
Dave Houlton584d51e2017-02-16 12:52:54 -070016506 // buffer offset must be a multiple of texel block size (16)
16507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16509 region.imageExtent = {64, 64, 1};
16510 region.bufferOffset = 24;
16511 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16512 buffer_16k.handle(), 1, &region);
16513 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016514
Dave Houlton584d51e2017-02-16 12:52:54 -070016515 // rowlength not a multiple of block width (4)
16516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16517 region.bufferOffset = 0;
16518 region.bufferRowLength = 130;
16519 region.bufferImageHeight = 0;
16520 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16521 buffer_64k.handle(), 1, &region);
16522 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016523
Dave Houlton584d51e2017-02-16 12:52:54 -070016524 // imageheight not a multiple of block height (4)
16525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16526 region.bufferRowLength = 0;
16527 region.bufferImageHeight = 130;
16528 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16529 buffer_64k.handle(), 1, &region);
16530 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016531 }
Dave Houlton59a20702017-02-02 17:26:23 -070016532}
16533
Tony Barbourd6673642016-05-05 14:46:39 -060016534TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016535 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016536
16537 ASSERT_NO_FATAL_FAILURE(InitState());
16538
Rene Lindsay135204f2016-12-22 17:11:09 -070016539 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016540 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016541 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 -070016542 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016543 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016544 vk_testing::Buffer buffer;
16545 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016546 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016547 VkBufferImageCopy region = {};
16548 region.bufferRowLength = 128;
16549 region.bufferImageHeight = 128;
16550 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16551 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016552 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016553 region.imageExtent.height = 4;
16554 region.imageExtent.width = 4;
16555 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016556
16557 VkImageObj image2(m_device);
16558 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 -070016559 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016560 ASSERT_TRUE(image2.initialized());
16561 vk_testing::Buffer buffer2;
16562 VkMemoryPropertyFlags reqs2 = 0;
16563 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16564 VkBufferImageCopy region2 = {};
16565 region2.bufferRowLength = 128;
16566 region2.bufferImageHeight = 128;
16567 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16568 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16569 region2.imageSubresource.layerCount = 1;
16570 region2.imageExtent.height = 4;
16571 region2.imageExtent.width = 4;
16572 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016573 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016574
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016575 // Image must have offset.z of 0 and extent.depth of 1
16576 // Introduce failure by setting imageExtent.depth to 0
16577 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016579 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016580 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016581 m_errorMonitor->VerifyFound();
16582
16583 region.imageExtent.depth = 1;
16584
16585 // Image must have offset.z of 0 and extent.depth of 1
16586 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016587 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016588 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016591 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016592 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016593 m_errorMonitor->VerifyFound();
16594
16595 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016596 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16597 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016598 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016600 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16601 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016602 m_errorMonitor->VerifyFound();
16603
16604 // BufferOffset must be a multiple of 4
16605 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016606 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016608 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16609 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016610 m_errorMonitor->VerifyFound();
16611
16612 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16613 region.bufferOffset = 0;
16614 region.imageExtent.height = 128;
16615 region.imageExtent.width = 128;
16616 // Introduce failure by setting bufferRowLength > 0 but less than width
16617 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016619 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16620 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016621 m_errorMonitor->VerifyFound();
16622
16623 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16624 region.bufferRowLength = 128;
16625 // Introduce failure by setting bufferRowHeight > 0 but less than height
16626 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016628 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16629 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016630 m_errorMonitor->VerifyFound();
16631
16632 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016633 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016634 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16635 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016636 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016637 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16638 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016639 VkImageBlit blitRegion = {};
16640 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16641 blitRegion.srcSubresource.baseArrayLayer = 0;
16642 blitRegion.srcSubresource.layerCount = 1;
16643 blitRegion.srcSubresource.mipLevel = 0;
16644 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16645 blitRegion.dstSubresource.baseArrayLayer = 0;
16646 blitRegion.dstSubresource.layerCount = 1;
16647 blitRegion.dstSubresource.mipLevel = 0;
16648
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016649 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016651 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016652 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16653 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016654 m_errorMonitor->VerifyFound();
16655
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016657 VkImageMemoryBarrier img_barrier;
16658 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16659 img_barrier.pNext = NULL;
16660 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16661 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16662 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16663 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16664 img_barrier.image = image.handle();
16665 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16666 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16667 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16668 img_barrier.subresourceRange.baseArrayLayer = 0;
16669 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016670 img_barrier.subresourceRange.layerCount = 0;
16671 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16673 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016674 m_errorMonitor->VerifyFound();
16675 img_barrier.subresourceRange.layerCount = 1;
16676}
16677
16678TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016679 TEST_DESCRIPTION("Exceed the limits of image format ");
16680
Cody Northropc31a84f2016-08-22 10:41:47 -060016681 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016683 VkImageCreateInfo image_create_info = {};
16684 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16685 image_create_info.pNext = NULL;
16686 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16687 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16688 image_create_info.extent.width = 32;
16689 image_create_info.extent.height = 32;
16690 image_create_info.extent.depth = 1;
16691 image_create_info.mipLevels = 1;
16692 image_create_info.arrayLayers = 1;
16693 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16694 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16695 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16696 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16697 image_create_info.flags = 0;
16698
16699 VkImage nullImg;
16700 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016701 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16702 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016703 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016704 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16705 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16706 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016707 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016710 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16711 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16712 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16713 m_errorMonitor->VerifyFound();
16714 image_create_info.mipLevels = 1;
16715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016717 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16718 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16719 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16720 m_errorMonitor->VerifyFound();
16721 image_create_info.arrayLayers = 1;
16722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016724 int samples = imgFmtProps.sampleCounts >> 1;
16725 image_create_info.samples = (VkSampleCountFlagBits)samples;
16726 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16727 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16728 m_errorMonitor->VerifyFound();
16729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16732 "pCreateInfo->initialLayout, must be "
16733 "VK_IMAGE_LAYOUT_UNDEFINED or "
16734 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016735 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16736 // Expect INVALID_LAYOUT
16737 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16738 m_errorMonitor->VerifyFound();
16739 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16740}
16741
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016742TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016743 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016745
16746 ASSERT_NO_FATAL_FAILURE(InitState());
16747
16748 VkImageObj src_image(m_device);
16749 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16750 VkImageObj dst_image(m_device);
16751 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16752
Tony Barbour552f6c02016-12-21 14:34:07 -070016753 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016754 VkImageCopy copy_region;
16755 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16756 copy_region.srcSubresource.mipLevel = 0;
16757 copy_region.srcSubresource.baseArrayLayer = 0;
16758 copy_region.srcSubresource.layerCount = 0;
16759 copy_region.srcOffset.x = 0;
16760 copy_region.srcOffset.y = 0;
16761 copy_region.srcOffset.z = 0;
16762 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16763 copy_region.dstSubresource.mipLevel = 0;
16764 copy_region.dstSubresource.baseArrayLayer = 0;
16765 copy_region.dstSubresource.layerCount = 0;
16766 copy_region.dstOffset.x = 0;
16767 copy_region.dstOffset.y = 0;
16768 copy_region.dstOffset.z = 0;
16769 copy_region.extent.width = 64;
16770 copy_region.extent.height = 64;
16771 copy_region.extent.depth = 1;
16772 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16773 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016774 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016775
16776 m_errorMonitor->VerifyFound();
16777}
16778
16779TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016780 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016782
16783 ASSERT_NO_FATAL_FAILURE(InitState());
16784
16785 VkImageObj src_image(m_device);
16786 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16787 VkImageObj dst_image(m_device);
16788 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16789
Tony Barbour552f6c02016-12-21 14:34:07 -070016790 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016791 VkImageCopy copy_region;
16792 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16793 copy_region.srcSubresource.mipLevel = 0;
16794 copy_region.srcSubresource.baseArrayLayer = 0;
16795 copy_region.srcSubresource.layerCount = 0;
16796 copy_region.srcOffset.x = 0;
16797 copy_region.srcOffset.y = 0;
16798 copy_region.srcOffset.z = 0;
16799 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16800 copy_region.dstSubresource.mipLevel = 0;
16801 copy_region.dstSubresource.baseArrayLayer = 0;
16802 copy_region.dstSubresource.layerCount = 0;
16803 copy_region.dstOffset.x = 0;
16804 copy_region.dstOffset.y = 0;
16805 copy_region.dstOffset.z = 0;
16806 copy_region.extent.width = 64;
16807 copy_region.extent.height = 64;
16808 copy_region.extent.depth = 1;
16809 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16810 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016811 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016812
16813 m_errorMonitor->VerifyFound();
16814}
16815
Karl Schultz6addd812016-02-02 17:17:23 -070016816TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016817 VkResult err;
16818 bool pass;
16819
16820 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016822
16823 ASSERT_NO_FATAL_FAILURE(InitState());
16824
16825 // Create two images of different types and try to copy between them
16826 VkImage srcImage;
16827 VkImage dstImage;
16828 VkDeviceMemory srcMem;
16829 VkDeviceMemory destMem;
16830 VkMemoryRequirements memReqs;
16831
16832 VkImageCreateInfo image_create_info = {};
16833 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16834 image_create_info.pNext = NULL;
16835 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16836 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16837 image_create_info.extent.width = 32;
16838 image_create_info.extent.height = 32;
16839 image_create_info.extent.depth = 1;
16840 image_create_info.mipLevels = 1;
16841 image_create_info.arrayLayers = 1;
16842 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16843 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16844 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16845 image_create_info.flags = 0;
16846
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016847 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016848 ASSERT_VK_SUCCESS(err);
16849
16850 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16851 // Introduce failure by creating second image with a different-sized format.
16852 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016855 ASSERT_VK_SUCCESS(err);
16856
16857 // Allocate memory
16858 VkMemoryAllocateInfo memAlloc = {};
16859 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16860 memAlloc.pNext = NULL;
16861 memAlloc.allocationSize = 0;
16862 memAlloc.memoryTypeIndex = 0;
16863
16864 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16865 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016866 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016867 ASSERT_TRUE(pass);
16868 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16869 ASSERT_VK_SUCCESS(err);
16870
16871 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16872 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016873 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016874 ASSERT_TRUE(pass);
16875 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16876 ASSERT_VK_SUCCESS(err);
16877
16878 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16879 ASSERT_VK_SUCCESS(err);
16880 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16881 ASSERT_VK_SUCCESS(err);
16882
Tony Barbour552f6c02016-12-21 14:34:07 -070016883 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016884 VkImageCopy copyRegion;
16885 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16886 copyRegion.srcSubresource.mipLevel = 0;
16887 copyRegion.srcSubresource.baseArrayLayer = 0;
16888 copyRegion.srcSubresource.layerCount = 0;
16889 copyRegion.srcOffset.x = 0;
16890 copyRegion.srcOffset.y = 0;
16891 copyRegion.srcOffset.z = 0;
16892 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16893 copyRegion.dstSubresource.mipLevel = 0;
16894 copyRegion.dstSubresource.baseArrayLayer = 0;
16895 copyRegion.dstSubresource.layerCount = 0;
16896 copyRegion.dstOffset.x = 0;
16897 copyRegion.dstOffset.y = 0;
16898 copyRegion.dstOffset.z = 0;
16899 copyRegion.extent.width = 1;
16900 copyRegion.extent.height = 1;
16901 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016902 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016903 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016904
16905 m_errorMonitor->VerifyFound();
16906
16907 vkDestroyImage(m_device->device(), srcImage, NULL);
16908 vkDestroyImage(m_device->device(), dstImage, NULL);
16909 vkFreeMemory(m_device->device(), srcMem, NULL);
16910 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016911}
16912
Karl Schultz6addd812016-02-02 17:17:23 -070016913TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16914 VkResult err;
16915 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016916
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016917 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16919 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016920
Mike Stroyana3082432015-09-25 13:39:21 -060016921 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016922 auto depth_format = find_depth_stencil_format(m_device);
16923 if (!depth_format) {
16924 return;
16925 }
Mike Stroyana3082432015-09-25 13:39:21 -060016926
16927 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016928 VkImage srcImage;
16929 VkImage dstImage;
16930 VkDeviceMemory srcMem;
16931 VkDeviceMemory destMem;
16932 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016933
16934 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016935 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16936 image_create_info.pNext = NULL;
16937 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16938 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16939 image_create_info.extent.width = 32;
16940 image_create_info.extent.height = 32;
16941 image_create_info.extent.depth = 1;
16942 image_create_info.mipLevels = 1;
16943 image_create_info.arrayLayers = 1;
16944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16945 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16946 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16947 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016949 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016950 ASSERT_VK_SUCCESS(err);
16951
Karl Schultzbdb75952016-04-19 11:36:49 -060016952 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16953
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016954 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016955 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070016956 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016957 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016959 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016960 ASSERT_VK_SUCCESS(err);
16961
16962 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016963 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016964 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16965 memAlloc.pNext = NULL;
16966 memAlloc.allocationSize = 0;
16967 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016968
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016969 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016970 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016971 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016972 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016973 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016974 ASSERT_VK_SUCCESS(err);
16975
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016976 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016977 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016978 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016979 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016980 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016981 ASSERT_VK_SUCCESS(err);
16982
16983 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16984 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016985 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016986 ASSERT_VK_SUCCESS(err);
16987
Tony Barbour552f6c02016-12-21 14:34:07 -070016988 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016989 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016990 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016991 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016992 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016993 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016994 copyRegion.srcOffset.x = 0;
16995 copyRegion.srcOffset.y = 0;
16996 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016997 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016998 copyRegion.dstSubresource.mipLevel = 0;
16999 copyRegion.dstSubresource.baseArrayLayer = 0;
17000 copyRegion.dstSubresource.layerCount = 0;
17001 copyRegion.dstOffset.x = 0;
17002 copyRegion.dstOffset.y = 0;
17003 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017004 copyRegion.extent.width = 1;
17005 copyRegion.extent.height = 1;
17006 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017007 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017008 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017010 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017011
Chia-I Wuf7458c52015-10-26 21:10:41 +080017012 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017013 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017014 vkFreeMemory(m_device->device(), srcMem, NULL);
17015 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017016}
17017
Karl Schultz6addd812016-02-02 17:17:23 -070017018TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17019 VkResult err;
17020 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17023 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017024
Mike Stroyana3082432015-09-25 13:39:21 -060017025 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017026
17027 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017028 VkImage srcImage;
17029 VkImage dstImage;
17030 VkDeviceMemory srcMem;
17031 VkDeviceMemory destMem;
17032 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017033
17034 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017035 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17036 image_create_info.pNext = NULL;
17037 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17038 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17039 image_create_info.extent.width = 32;
17040 image_create_info.extent.height = 1;
17041 image_create_info.extent.depth = 1;
17042 image_create_info.mipLevels = 1;
17043 image_create_info.arrayLayers = 1;
17044 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17045 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17046 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17047 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017049 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017050 ASSERT_VK_SUCCESS(err);
17051
Karl Schultz6addd812016-02-02 17:17:23 -070017052 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017054 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017055 ASSERT_VK_SUCCESS(err);
17056
17057 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017058 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017059 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17060 memAlloc.pNext = NULL;
17061 memAlloc.allocationSize = 0;
17062 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017063
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017064 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017065 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017067 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017069 ASSERT_VK_SUCCESS(err);
17070
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017071 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017072 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017073 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017074 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017075 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017076 ASSERT_VK_SUCCESS(err);
17077
17078 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17079 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017080 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017081 ASSERT_VK_SUCCESS(err);
17082
Tony Barbour552f6c02016-12-21 14:34:07 -070017083 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017084 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017085 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17086 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017087 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017088 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017089 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017090 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017091 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017092 resolveRegion.srcOffset.x = 0;
17093 resolveRegion.srcOffset.y = 0;
17094 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017095 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017096 resolveRegion.dstSubresource.mipLevel = 0;
17097 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017098 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017099 resolveRegion.dstOffset.x = 0;
17100 resolveRegion.dstOffset.y = 0;
17101 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017102 resolveRegion.extent.width = 1;
17103 resolveRegion.extent.height = 1;
17104 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017105 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017106 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017107
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017108 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017109
Chia-I Wuf7458c52015-10-26 21:10:41 +080017110 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017111 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017112 vkFreeMemory(m_device->device(), srcMem, NULL);
17113 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017114}
17115
Karl Schultz6addd812016-02-02 17:17:23 -070017116TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17117 VkResult err;
17118 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17121 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017122
Mike Stroyana3082432015-09-25 13:39:21 -060017123 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017124
Chris Forbesa7530692016-05-08 12:35:39 +120017125 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017126 VkImage srcImage;
17127 VkImage dstImage;
17128 VkDeviceMemory srcMem;
17129 VkDeviceMemory destMem;
17130 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017131
17132 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17134 image_create_info.pNext = NULL;
17135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17136 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17137 image_create_info.extent.width = 32;
17138 image_create_info.extent.height = 1;
17139 image_create_info.extent.depth = 1;
17140 image_create_info.mipLevels = 1;
17141 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017142 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017143 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17144 // Note: Some implementations expect color attachment usage for any
17145 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017146 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017147 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017149 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017150 ASSERT_VK_SUCCESS(err);
17151
Karl Schultz6addd812016-02-02 17:17:23 -070017152 // Note: Some implementations expect color attachment usage for any
17153 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017154 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017156 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017157 ASSERT_VK_SUCCESS(err);
17158
17159 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017160 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017161 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17162 memAlloc.pNext = NULL;
17163 memAlloc.allocationSize = 0;
17164 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017165
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017166 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017167 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017168 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017169 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017170 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017171 ASSERT_VK_SUCCESS(err);
17172
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017173 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017174 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017175 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017176 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017177 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017178 ASSERT_VK_SUCCESS(err);
17179
17180 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17181 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017182 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017183 ASSERT_VK_SUCCESS(err);
17184
Tony Barbour552f6c02016-12-21 14:34:07 -070017185 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017186 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017187 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17188 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017189 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017190 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017191 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017192 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017193 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017194 resolveRegion.srcOffset.x = 0;
17195 resolveRegion.srcOffset.y = 0;
17196 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017197 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017198 resolveRegion.dstSubresource.mipLevel = 0;
17199 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017200 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017201 resolveRegion.dstOffset.x = 0;
17202 resolveRegion.dstOffset.y = 0;
17203 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017204 resolveRegion.extent.width = 1;
17205 resolveRegion.extent.height = 1;
17206 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017207 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017208 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017209
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017210 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017211
Chia-I Wuf7458c52015-10-26 21:10:41 +080017212 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017213 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017214 vkFreeMemory(m_device->device(), srcMem, NULL);
17215 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017216}
17217
Karl Schultz6addd812016-02-02 17:17:23 -070017218TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17219 VkResult err;
17220 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017221
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017223 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017224
Mike Stroyana3082432015-09-25 13:39:21 -060017225 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017226
17227 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017228 VkImage srcImage;
17229 VkImage dstImage;
17230 VkDeviceMemory srcMem;
17231 VkDeviceMemory destMem;
17232 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017233
17234 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017235 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17236 image_create_info.pNext = NULL;
17237 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17238 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17239 image_create_info.extent.width = 32;
17240 image_create_info.extent.height = 1;
17241 image_create_info.extent.depth = 1;
17242 image_create_info.mipLevels = 1;
17243 image_create_info.arrayLayers = 1;
17244 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17245 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17246 // Note: Some implementations expect color attachment usage for any
17247 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017248 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017249 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017250
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017251 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017252 ASSERT_VK_SUCCESS(err);
17253
Karl Schultz6addd812016-02-02 17:17:23 -070017254 // Set format to something other than source image
17255 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17256 // Note: Some implementations expect color attachment usage for any
17257 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017258 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017259 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017262 ASSERT_VK_SUCCESS(err);
17263
17264 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017265 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017266 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17267 memAlloc.pNext = NULL;
17268 memAlloc.allocationSize = 0;
17269 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017270
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017271 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017272 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017273 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017274 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017275 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017276 ASSERT_VK_SUCCESS(err);
17277
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017278 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017279 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017280 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017281 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017282 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017283 ASSERT_VK_SUCCESS(err);
17284
17285 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17286 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017287 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017288 ASSERT_VK_SUCCESS(err);
17289
Tony Barbour552f6c02016-12-21 14:34:07 -070017290 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017291 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017292 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17293 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017294 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017295 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017296 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017297 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017298 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017299 resolveRegion.srcOffset.x = 0;
17300 resolveRegion.srcOffset.y = 0;
17301 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017302 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017303 resolveRegion.dstSubresource.mipLevel = 0;
17304 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017305 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017306 resolveRegion.dstOffset.x = 0;
17307 resolveRegion.dstOffset.y = 0;
17308 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017309 resolveRegion.extent.width = 1;
17310 resolveRegion.extent.height = 1;
17311 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017312 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017313 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017315 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017316
Chia-I Wuf7458c52015-10-26 21:10:41 +080017317 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017318 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017319 vkFreeMemory(m_device->device(), srcMem, NULL);
17320 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017321}
17322
Karl Schultz6addd812016-02-02 17:17:23 -070017323TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17324 VkResult err;
17325 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017326
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017328 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017329
Mike Stroyana3082432015-09-25 13:39:21 -060017330 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017331
17332 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017333 VkImage srcImage;
17334 VkImage dstImage;
17335 VkDeviceMemory srcMem;
17336 VkDeviceMemory destMem;
17337 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017338
17339 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017340 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17341 image_create_info.pNext = NULL;
17342 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17343 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17344 image_create_info.extent.width = 32;
17345 image_create_info.extent.height = 1;
17346 image_create_info.extent.depth = 1;
17347 image_create_info.mipLevels = 1;
17348 image_create_info.arrayLayers = 1;
17349 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17350 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17351 // Note: Some implementations expect color attachment usage for any
17352 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017353 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017354 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017356 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017357 ASSERT_VK_SUCCESS(err);
17358
Karl Schultz6addd812016-02-02 17:17:23 -070017359 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17360 // Note: Some implementations expect color attachment usage for any
17361 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017362 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017365 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017366 ASSERT_VK_SUCCESS(err);
17367
17368 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017369 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017370 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17371 memAlloc.pNext = NULL;
17372 memAlloc.allocationSize = 0;
17373 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017374
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017375 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017376 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017377 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017378 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017379 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017380 ASSERT_VK_SUCCESS(err);
17381
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017382 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017383 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017384 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017385 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017386 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017387 ASSERT_VK_SUCCESS(err);
17388
17389 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17390 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017391 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017392 ASSERT_VK_SUCCESS(err);
17393
Tony Barbour552f6c02016-12-21 14:34:07 -070017394 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017395 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017396 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17397 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017398 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017399 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017400 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017401 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017402 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017403 resolveRegion.srcOffset.x = 0;
17404 resolveRegion.srcOffset.y = 0;
17405 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017406 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017407 resolveRegion.dstSubresource.mipLevel = 0;
17408 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017409 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017410 resolveRegion.dstOffset.x = 0;
17411 resolveRegion.dstOffset.y = 0;
17412 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017413 resolveRegion.extent.width = 1;
17414 resolveRegion.extent.height = 1;
17415 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017416 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017417 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017418
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017419 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017420
Chia-I Wuf7458c52015-10-26 21:10:41 +080017421 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017422 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017423 vkFreeMemory(m_device->device(), srcMem, NULL);
17424 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017425}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017426
Karl Schultz6addd812016-02-02 17:17:23 -070017427TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017428 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017429 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17430 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017431 // The image format check comes 2nd in validation so we trigger it first,
17432 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017433 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17436 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017437
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017438 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017439 auto depth_format = find_depth_stencil_format(m_device);
17440 if (!depth_format) {
17441 return;
17442 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017443
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017444 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017445 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17446 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017447
17448 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017449 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17450 ds_pool_ci.pNext = NULL;
17451 ds_pool_ci.maxSets = 1;
17452 ds_pool_ci.poolSizeCount = 1;
17453 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017454
17455 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017456 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017457 ASSERT_VK_SUCCESS(err);
17458
17459 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017460 dsl_binding.binding = 0;
17461 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17462 dsl_binding.descriptorCount = 1;
17463 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17464 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017465
17466 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017467 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17468 ds_layout_ci.pNext = NULL;
17469 ds_layout_ci.bindingCount = 1;
17470 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017471 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017472 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017473 ASSERT_VK_SUCCESS(err);
17474
17475 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017476 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017477 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017478 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017479 alloc_info.descriptorPool = ds_pool;
17480 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017481 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017482 ASSERT_VK_SUCCESS(err);
17483
Karl Schultz6addd812016-02-02 17:17:23 -070017484 VkImage image_bad;
17485 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017486 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017487 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017488 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017489 const int32_t tex_width = 32;
17490 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017491
17492 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017493 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17494 image_create_info.pNext = NULL;
17495 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17496 image_create_info.format = tex_format_bad;
17497 image_create_info.extent.width = tex_width;
17498 image_create_info.extent.height = tex_height;
17499 image_create_info.extent.depth = 1;
17500 image_create_info.mipLevels = 1;
17501 image_create_info.arrayLayers = 1;
17502 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17503 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017504 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017505 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017507 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017508 ASSERT_VK_SUCCESS(err);
17509 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017510 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17511 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017512 ASSERT_VK_SUCCESS(err);
17513
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017514 // ---Bind image memory---
17515 VkMemoryRequirements img_mem_reqs;
17516 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17517 VkMemoryAllocateInfo image_alloc_info = {};
17518 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17519 image_alloc_info.pNext = NULL;
17520 image_alloc_info.memoryTypeIndex = 0;
17521 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017522 bool pass =
17523 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 -070017524 ASSERT_TRUE(pass);
17525 VkDeviceMemory mem;
17526 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17527 ASSERT_VK_SUCCESS(err);
17528 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17529 ASSERT_VK_SUCCESS(err);
17530 // -----------------------
17531
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017532 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017533 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017534 image_view_create_info.image = image_bad;
17535 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17536 image_view_create_info.format = tex_format_bad;
17537 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17538 image_view_create_info.subresourceRange.baseMipLevel = 0;
17539 image_view_create_info.subresourceRange.layerCount = 1;
17540 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017541 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017542
17543 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017544 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017545
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017546 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017547
Chia-I Wuf7458c52015-10-26 21:10:41 +080017548 vkDestroyImage(m_device->device(), image_bad, NULL);
17549 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17551 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017552
17553 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017554}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017555
17556TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017557 TEST_DESCRIPTION(
17558 "Call ClearColorImage w/ a depth|stencil image and "
17559 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017560
17561 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017562 auto depth_format = find_depth_stencil_format(m_device);
17563 if (!depth_format) {
17564 return;
17565 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17567
Tony Barbour552f6c02016-12-21 14:34:07 -070017568 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017569
17570 // Color image
17571 VkClearColorValue clear_color;
17572 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17573 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17574 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17575 const int32_t img_width = 32;
17576 const int32_t img_height = 32;
17577 VkImageCreateInfo image_create_info = {};
17578 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17579 image_create_info.pNext = NULL;
17580 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17581 image_create_info.format = color_format;
17582 image_create_info.extent.width = img_width;
17583 image_create_info.extent.height = img_height;
17584 image_create_info.extent.depth = 1;
17585 image_create_info.mipLevels = 1;
17586 image_create_info.arrayLayers = 1;
17587 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17588 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17589 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17590
17591 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017592 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017594 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017595
17596 // Depth/Stencil image
17597 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017598 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017599 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17600 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017601 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017602 ds_image_create_info.extent.width = 64;
17603 ds_image_create_info.extent.height = 64;
17604 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017605 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 -060017606
17607 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017608 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017610 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 -060017611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017614 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017615 &color_range);
17616
17617 m_errorMonitor->VerifyFound();
17618
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17620 "vkCmdClearColorImage called with "
17621 "image created without "
17622 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017623
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017624 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017625 &color_range);
17626
17627 m_errorMonitor->VerifyFound();
17628
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017629 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17631 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017633 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17634 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017635
17636 m_errorMonitor->VerifyFound();
17637}
Tobin Ehliscde08892015-09-22 10:11:37 -060017638
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017639// WSI Enabled Tests
17640//
Chris Forbes09368e42016-10-13 11:59:22 +130017641#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017642TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17643
17644#if defined(VK_USE_PLATFORM_XCB_KHR)
17645 VkSurfaceKHR surface = VK_NULL_HANDLE;
17646
17647 VkResult err;
17648 bool pass;
17649 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17650 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17651 // uint32_t swapchain_image_count = 0;
17652 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17653 // uint32_t image_index = 0;
17654 // VkPresentInfoKHR present_info = {};
17655
17656 ASSERT_NO_FATAL_FAILURE(InitState());
17657
17658 // Use the create function from one of the VK_KHR_*_surface extension in
17659 // order to create a surface, testing all known errors in the process,
17660 // before successfully creating a surface:
17661 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17663 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17664 pass = (err != VK_SUCCESS);
17665 ASSERT_TRUE(pass);
17666 m_errorMonitor->VerifyFound();
17667
17668 // Next, try to create a surface with the wrong
17669 // VkXcbSurfaceCreateInfoKHR::sType:
17670 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17671 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17673 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17674 pass = (err != VK_SUCCESS);
17675 ASSERT_TRUE(pass);
17676 m_errorMonitor->VerifyFound();
17677
17678 // Create a native window, and then correctly create a surface:
17679 xcb_connection_t *connection;
17680 xcb_screen_t *screen;
17681 xcb_window_t xcb_window;
17682 xcb_intern_atom_reply_t *atom_wm_delete_window;
17683
17684 const xcb_setup_t *setup;
17685 xcb_screen_iterator_t iter;
17686 int scr;
17687 uint32_t value_mask, value_list[32];
17688 int width = 1;
17689 int height = 1;
17690
17691 connection = xcb_connect(NULL, &scr);
17692 ASSERT_TRUE(connection != NULL);
17693 setup = xcb_get_setup(connection);
17694 iter = xcb_setup_roots_iterator(setup);
17695 while (scr-- > 0)
17696 xcb_screen_next(&iter);
17697 screen = iter.data;
17698
17699 xcb_window = xcb_generate_id(connection);
17700
17701 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17702 value_list[0] = screen->black_pixel;
17703 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17704
17705 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17706 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17707
17708 /* Magic code that will send notification when window is destroyed */
17709 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17710 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17711
17712 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17713 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17714 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17715 free(reply);
17716
17717 xcb_map_window(connection, xcb_window);
17718
17719 // Force the x/y coordinates to 100,100 results are identical in consecutive
17720 // runs
17721 const uint32_t coords[] = { 100, 100 };
17722 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17723
17724 // Finally, try to correctly create a surface:
17725 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17726 xcb_create_info.pNext = NULL;
17727 xcb_create_info.flags = 0;
17728 xcb_create_info.connection = connection;
17729 xcb_create_info.window = xcb_window;
17730 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17731 pass = (err == VK_SUCCESS);
17732 ASSERT_TRUE(pass);
17733
17734 // Check if surface supports presentation:
17735
17736 // 1st, do so without having queried the queue families:
17737 VkBool32 supported = false;
17738 // TODO: Get the following error to come out:
17739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17740 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17741 "function");
17742 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17743 pass = (err != VK_SUCCESS);
17744 // ASSERT_TRUE(pass);
17745 // m_errorMonitor->VerifyFound();
17746
17747 // Next, query a queue family index that's too large:
17748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17749 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17750 pass = (err != VK_SUCCESS);
17751 ASSERT_TRUE(pass);
17752 m_errorMonitor->VerifyFound();
17753
17754 // Finally, do so correctly:
17755 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17756 // SUPPORTED
17757 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17758 pass = (err == VK_SUCCESS);
17759 ASSERT_TRUE(pass);
17760
17761 // Before proceeding, try to create a swapchain without having called
17762 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17763 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17764 swapchain_create_info.pNext = NULL;
17765 swapchain_create_info.flags = 0;
17766 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17767 swapchain_create_info.surface = surface;
17768 swapchain_create_info.imageArrayLayers = 1;
17769 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17770 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17772 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17773 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17774 pass = (err != VK_SUCCESS);
17775 ASSERT_TRUE(pass);
17776 m_errorMonitor->VerifyFound();
17777
17778 // Get the surface capabilities:
17779 VkSurfaceCapabilitiesKHR surface_capabilities;
17780
17781 // Do so correctly (only error logged by this entrypoint is if the
17782 // extension isn't enabled):
17783 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17784 pass = (err == VK_SUCCESS);
17785 ASSERT_TRUE(pass);
17786
17787 // Get the surface formats:
17788 uint32_t surface_format_count;
17789
17790 // First, try without a pointer to surface_format_count:
17791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17792 "specified as NULL");
17793 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17794 pass = (err == VK_SUCCESS);
17795 ASSERT_TRUE(pass);
17796 m_errorMonitor->VerifyFound();
17797
17798 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17799 // correctly done a 1st try (to get the count):
17800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17801 surface_format_count = 0;
17802 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17803 pass = (err == VK_SUCCESS);
17804 ASSERT_TRUE(pass);
17805 m_errorMonitor->VerifyFound();
17806
17807 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17808 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17809 pass = (err == VK_SUCCESS);
17810 ASSERT_TRUE(pass);
17811
17812 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17813 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17814
17815 // Next, do a 2nd try with surface_format_count being set too high:
17816 surface_format_count += 5;
17817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17818 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17819 pass = (err == VK_SUCCESS);
17820 ASSERT_TRUE(pass);
17821 m_errorMonitor->VerifyFound();
17822
17823 // Finally, do a correct 1st and 2nd try:
17824 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17825 pass = (err == VK_SUCCESS);
17826 ASSERT_TRUE(pass);
17827 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17828 pass = (err == VK_SUCCESS);
17829 ASSERT_TRUE(pass);
17830
17831 // Get the surface present modes:
17832 uint32_t surface_present_mode_count;
17833
17834 // First, try without a pointer to surface_format_count:
17835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17836 "specified as NULL");
17837
17838 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17839 pass = (err == VK_SUCCESS);
17840 ASSERT_TRUE(pass);
17841 m_errorMonitor->VerifyFound();
17842
17843 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17844 // correctly done a 1st try (to get the count):
17845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17846 surface_present_mode_count = 0;
17847 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17848 (VkPresentModeKHR *)&surface_present_mode_count);
17849 pass = (err == VK_SUCCESS);
17850 ASSERT_TRUE(pass);
17851 m_errorMonitor->VerifyFound();
17852
17853 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17854 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17855 pass = (err == VK_SUCCESS);
17856 ASSERT_TRUE(pass);
17857
17858 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17859 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17860
17861 // Next, do a 2nd try with surface_format_count being set too high:
17862 surface_present_mode_count += 5;
17863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17864 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17865 pass = (err == VK_SUCCESS);
17866 ASSERT_TRUE(pass);
17867 m_errorMonitor->VerifyFound();
17868
17869 // Finally, do a correct 1st and 2nd try:
17870 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17871 pass = (err == VK_SUCCESS);
17872 ASSERT_TRUE(pass);
17873 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17874 pass = (err == VK_SUCCESS);
17875 ASSERT_TRUE(pass);
17876
17877 // Create a swapchain:
17878
17879 // First, try without a pointer to swapchain_create_info:
17880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17881 "specified as NULL");
17882
17883 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17884 pass = (err != VK_SUCCESS);
17885 ASSERT_TRUE(pass);
17886 m_errorMonitor->VerifyFound();
17887
17888 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17889 // sType:
17890 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17892
17893 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17894 pass = (err != VK_SUCCESS);
17895 ASSERT_TRUE(pass);
17896 m_errorMonitor->VerifyFound();
17897
17898 // Next, call with a NULL swapchain pointer:
17899 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17900 swapchain_create_info.pNext = NULL;
17901 swapchain_create_info.flags = 0;
17902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17903 "specified as NULL");
17904
17905 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17906 pass = (err != VK_SUCCESS);
17907 ASSERT_TRUE(pass);
17908 m_errorMonitor->VerifyFound();
17909
17910 // TODO: Enhance swapchain layer so that
17911 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17912
17913 // Next, call with a queue family index that's too large:
17914 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17915 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17916 swapchain_create_info.queueFamilyIndexCount = 2;
17917 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17919 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17920 pass = (err != VK_SUCCESS);
17921 ASSERT_TRUE(pass);
17922 m_errorMonitor->VerifyFound();
17923
17924 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17925 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17926 swapchain_create_info.queueFamilyIndexCount = 1;
17927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17928 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17929 "pCreateInfo->pQueueFamilyIndices).");
17930 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17931 pass = (err != VK_SUCCESS);
17932 ASSERT_TRUE(pass);
17933 m_errorMonitor->VerifyFound();
17934
17935 // Next, call with an invalid imageSharingMode:
17936 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17937 swapchain_create_info.queueFamilyIndexCount = 1;
17938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17939 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17940 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17941 pass = (err != VK_SUCCESS);
17942 ASSERT_TRUE(pass);
17943 m_errorMonitor->VerifyFound();
17944 // Fix for the future:
17945 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17946 // SUPPORTED
17947 swapchain_create_info.queueFamilyIndexCount = 0;
17948 queueFamilyIndex[0] = 0;
17949 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17950
17951 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17952 // Get the images from a swapchain:
17953 // Acquire an image from a swapchain:
17954 // Present an image to a swapchain:
17955 // Destroy the swapchain:
17956
17957 // TODOs:
17958 //
17959 // - Try destroying the device without first destroying the swapchain
17960 //
17961 // - Try destroying the device without first destroying the surface
17962 //
17963 // - Try destroying the surface without first destroying the swapchain
17964
17965 // Destroy the surface:
17966 vkDestroySurfaceKHR(instance(), surface, NULL);
17967
17968 // Tear down the window:
17969 xcb_destroy_window(connection, xcb_window);
17970 xcb_disconnect(connection);
17971
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017972#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017973 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017974#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017975}
Chris Forbes09368e42016-10-13 11:59:22 +130017976#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017977
17978//
17979// POSITIVE VALIDATION TESTS
17980//
17981// These tests do not expect to encounter ANY validation errors pass only if this is true
17982
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017983TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17984 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17985 ASSERT_NO_FATAL_FAILURE(InitState());
17986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17987
17988 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17989 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17990 command_buffer_allocate_info.commandPool = m_commandPool;
17991 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17992 command_buffer_allocate_info.commandBufferCount = 1;
17993
17994 VkCommandBuffer secondary_command_buffer;
17995 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17996 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17997 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17998 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17999 command_buffer_inheritance_info.renderPass = m_renderPass;
18000 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18001
18002 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18003 command_buffer_begin_info.flags =
18004 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18005 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18006
18007 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18008 VkClearAttachment color_attachment;
18009 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18010 color_attachment.clearValue.color.float32[0] = 0;
18011 color_attachment.clearValue.color.float32[1] = 0;
18012 color_attachment.clearValue.color.float32[2] = 0;
18013 color_attachment.clearValue.color.float32[3] = 0;
18014 color_attachment.colorAttachment = 0;
18015 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18016 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18017}
18018
Tobin Ehlise0006882016-11-03 10:14:28 -060018019TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018020 TEST_DESCRIPTION(
18021 "Perform an image layout transition in a secondary command buffer followed "
18022 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018023 VkResult err;
18024 m_errorMonitor->ExpectSuccess();
18025 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018026 auto depth_format = find_depth_stencil_format(m_device);
18027 if (!depth_format) {
18028 return;
18029 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18031 // Allocate a secondary and primary cmd buffer
18032 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18033 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18034 command_buffer_allocate_info.commandPool = m_commandPool;
18035 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18036 command_buffer_allocate_info.commandBufferCount = 1;
18037
18038 VkCommandBuffer secondary_command_buffer;
18039 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18040 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18041 VkCommandBuffer primary_command_buffer;
18042 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18043 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18044 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18045 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18046 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18047 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18048 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18049
18050 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18051 ASSERT_VK_SUCCESS(err);
18052 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018053 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 -060018054 ASSERT_TRUE(image.initialized());
18055 VkImageMemoryBarrier img_barrier = {};
18056 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18057 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18058 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18059 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18060 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18061 img_barrier.image = image.handle();
18062 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18063 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18064 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18065 img_barrier.subresourceRange.baseArrayLayer = 0;
18066 img_barrier.subresourceRange.baseMipLevel = 0;
18067 img_barrier.subresourceRange.layerCount = 1;
18068 img_barrier.subresourceRange.levelCount = 1;
18069 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18070 0, nullptr, 1, &img_barrier);
18071 err = vkEndCommandBuffer(secondary_command_buffer);
18072 ASSERT_VK_SUCCESS(err);
18073
18074 // Now update primary cmd buffer to execute secondary and transitions image
18075 command_buffer_begin_info.pInheritanceInfo = nullptr;
18076 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18077 ASSERT_VK_SUCCESS(err);
18078 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18079 VkImageMemoryBarrier img_barrier2 = {};
18080 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18081 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18082 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18083 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18084 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18085 img_barrier2.image = image.handle();
18086 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18087 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18088 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18089 img_barrier2.subresourceRange.baseArrayLayer = 0;
18090 img_barrier2.subresourceRange.baseMipLevel = 0;
18091 img_barrier2.subresourceRange.layerCount = 1;
18092 img_barrier2.subresourceRange.levelCount = 1;
18093 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18094 nullptr, 1, &img_barrier2);
18095 err = vkEndCommandBuffer(primary_command_buffer);
18096 ASSERT_VK_SUCCESS(err);
18097 VkSubmitInfo submit_info = {};
18098 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18099 submit_info.commandBufferCount = 1;
18100 submit_info.pCommandBuffers = &primary_command_buffer;
18101 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18102 ASSERT_VK_SUCCESS(err);
18103 m_errorMonitor->VerifyNotFound();
18104 err = vkDeviceWaitIdle(m_device->device());
18105 ASSERT_VK_SUCCESS(err);
18106 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18107 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18108}
18109
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018110// This is a positive test. No failures are expected.
18111TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018112 TEST_DESCRIPTION(
18113 "Ensure that the vkUpdateDescriptorSets validation code "
18114 "is ignoring VkWriteDescriptorSet members that are not "
18115 "related to the descriptor type specified by "
18116 "VkWriteDescriptorSet::descriptorType. Correct "
18117 "validation behavior will result in the test running to "
18118 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018119
18120 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18121
18122 ASSERT_NO_FATAL_FAILURE(InitState());
18123
18124 // Image Case
18125 {
18126 m_errorMonitor->ExpectSuccess();
18127
18128 VkImage image;
18129 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18130 const int32_t tex_width = 32;
18131 const int32_t tex_height = 32;
18132 VkImageCreateInfo image_create_info = {};
18133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18134 image_create_info.pNext = NULL;
18135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18136 image_create_info.format = tex_format;
18137 image_create_info.extent.width = tex_width;
18138 image_create_info.extent.height = tex_height;
18139 image_create_info.extent.depth = 1;
18140 image_create_info.mipLevels = 1;
18141 image_create_info.arrayLayers = 1;
18142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18143 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18145 image_create_info.flags = 0;
18146 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18147 ASSERT_VK_SUCCESS(err);
18148
18149 VkMemoryRequirements memory_reqs;
18150 VkDeviceMemory image_memory;
18151 bool pass;
18152 VkMemoryAllocateInfo memory_info = {};
18153 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18154 memory_info.pNext = NULL;
18155 memory_info.allocationSize = 0;
18156 memory_info.memoryTypeIndex = 0;
18157 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18158 memory_info.allocationSize = memory_reqs.size;
18159 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18160 ASSERT_TRUE(pass);
18161 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18162 ASSERT_VK_SUCCESS(err);
18163 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18164 ASSERT_VK_SUCCESS(err);
18165
18166 VkImageViewCreateInfo image_view_create_info = {};
18167 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18168 image_view_create_info.image = image;
18169 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18170 image_view_create_info.format = tex_format;
18171 image_view_create_info.subresourceRange.layerCount = 1;
18172 image_view_create_info.subresourceRange.baseMipLevel = 0;
18173 image_view_create_info.subresourceRange.levelCount = 1;
18174 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18175
18176 VkImageView view;
18177 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18178 ASSERT_VK_SUCCESS(err);
18179
18180 VkDescriptorPoolSize ds_type_count = {};
18181 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18182 ds_type_count.descriptorCount = 1;
18183
18184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18186 ds_pool_ci.pNext = NULL;
18187 ds_pool_ci.maxSets = 1;
18188 ds_pool_ci.poolSizeCount = 1;
18189 ds_pool_ci.pPoolSizes = &ds_type_count;
18190
18191 VkDescriptorPool ds_pool;
18192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18193 ASSERT_VK_SUCCESS(err);
18194
18195 VkDescriptorSetLayoutBinding dsl_binding = {};
18196 dsl_binding.binding = 0;
18197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18198 dsl_binding.descriptorCount = 1;
18199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18200 dsl_binding.pImmutableSamplers = NULL;
18201
18202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18204 ds_layout_ci.pNext = NULL;
18205 ds_layout_ci.bindingCount = 1;
18206 ds_layout_ci.pBindings = &dsl_binding;
18207 VkDescriptorSetLayout ds_layout;
18208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18209 ASSERT_VK_SUCCESS(err);
18210
18211 VkDescriptorSet descriptor_set;
18212 VkDescriptorSetAllocateInfo alloc_info = {};
18213 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18214 alloc_info.descriptorSetCount = 1;
18215 alloc_info.descriptorPool = ds_pool;
18216 alloc_info.pSetLayouts = &ds_layout;
18217 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18218 ASSERT_VK_SUCCESS(err);
18219
18220 VkDescriptorImageInfo image_info = {};
18221 image_info.imageView = view;
18222 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18223
18224 VkWriteDescriptorSet descriptor_write;
18225 memset(&descriptor_write, 0, sizeof(descriptor_write));
18226 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18227 descriptor_write.dstSet = descriptor_set;
18228 descriptor_write.dstBinding = 0;
18229 descriptor_write.descriptorCount = 1;
18230 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18231 descriptor_write.pImageInfo = &image_info;
18232
18233 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18234 // be
18235 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18236 // This will most likely produce a crash if the parameter_validation
18237 // layer
18238 // does not correctly ignore pBufferInfo.
18239 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18240 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18241
18242 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18243
18244 m_errorMonitor->VerifyNotFound();
18245
18246 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18247 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18248 vkDestroyImageView(m_device->device(), view, NULL);
18249 vkDestroyImage(m_device->device(), image, NULL);
18250 vkFreeMemory(m_device->device(), image_memory, NULL);
18251 }
18252
18253 // Buffer Case
18254 {
18255 m_errorMonitor->ExpectSuccess();
18256
18257 VkBuffer buffer;
18258 uint32_t queue_family_index = 0;
18259 VkBufferCreateInfo buffer_create_info = {};
18260 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18261 buffer_create_info.size = 1024;
18262 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18263 buffer_create_info.queueFamilyIndexCount = 1;
18264 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18265
18266 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18267 ASSERT_VK_SUCCESS(err);
18268
18269 VkMemoryRequirements memory_reqs;
18270 VkDeviceMemory buffer_memory;
18271 bool pass;
18272 VkMemoryAllocateInfo memory_info = {};
18273 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18274 memory_info.pNext = NULL;
18275 memory_info.allocationSize = 0;
18276 memory_info.memoryTypeIndex = 0;
18277
18278 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18279 memory_info.allocationSize = memory_reqs.size;
18280 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18281 ASSERT_TRUE(pass);
18282
18283 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18284 ASSERT_VK_SUCCESS(err);
18285 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18286 ASSERT_VK_SUCCESS(err);
18287
18288 VkDescriptorPoolSize ds_type_count = {};
18289 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18290 ds_type_count.descriptorCount = 1;
18291
18292 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18293 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18294 ds_pool_ci.pNext = NULL;
18295 ds_pool_ci.maxSets = 1;
18296 ds_pool_ci.poolSizeCount = 1;
18297 ds_pool_ci.pPoolSizes = &ds_type_count;
18298
18299 VkDescriptorPool ds_pool;
18300 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18301 ASSERT_VK_SUCCESS(err);
18302
18303 VkDescriptorSetLayoutBinding dsl_binding = {};
18304 dsl_binding.binding = 0;
18305 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18306 dsl_binding.descriptorCount = 1;
18307 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18308 dsl_binding.pImmutableSamplers = NULL;
18309
18310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18312 ds_layout_ci.pNext = NULL;
18313 ds_layout_ci.bindingCount = 1;
18314 ds_layout_ci.pBindings = &dsl_binding;
18315 VkDescriptorSetLayout ds_layout;
18316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18317 ASSERT_VK_SUCCESS(err);
18318
18319 VkDescriptorSet descriptor_set;
18320 VkDescriptorSetAllocateInfo alloc_info = {};
18321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18322 alloc_info.descriptorSetCount = 1;
18323 alloc_info.descriptorPool = ds_pool;
18324 alloc_info.pSetLayouts = &ds_layout;
18325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18326 ASSERT_VK_SUCCESS(err);
18327
18328 VkDescriptorBufferInfo buffer_info = {};
18329 buffer_info.buffer = buffer;
18330 buffer_info.offset = 0;
18331 buffer_info.range = 1024;
18332
18333 VkWriteDescriptorSet descriptor_write;
18334 memset(&descriptor_write, 0, sizeof(descriptor_write));
18335 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18336 descriptor_write.dstSet = descriptor_set;
18337 descriptor_write.dstBinding = 0;
18338 descriptor_write.descriptorCount = 1;
18339 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18340 descriptor_write.pBufferInfo = &buffer_info;
18341
18342 // Set pImageInfo and pTexelBufferView to invalid values, which should
18343 // be
18344 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18345 // This will most likely produce a crash if the parameter_validation
18346 // layer
18347 // does not correctly ignore pImageInfo.
18348 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18349 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18350
18351 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18352
18353 m_errorMonitor->VerifyNotFound();
18354
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018355 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18356 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18357 vkDestroyBuffer(m_device->device(), buffer, NULL);
18358 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18359 }
18360
18361 // Texel Buffer Case
18362 {
18363 m_errorMonitor->ExpectSuccess();
18364
18365 VkBuffer buffer;
18366 uint32_t queue_family_index = 0;
18367 VkBufferCreateInfo buffer_create_info = {};
18368 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18369 buffer_create_info.size = 1024;
18370 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18371 buffer_create_info.queueFamilyIndexCount = 1;
18372 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18373
18374 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18375 ASSERT_VK_SUCCESS(err);
18376
18377 VkMemoryRequirements memory_reqs;
18378 VkDeviceMemory buffer_memory;
18379 bool pass;
18380 VkMemoryAllocateInfo memory_info = {};
18381 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18382 memory_info.pNext = NULL;
18383 memory_info.allocationSize = 0;
18384 memory_info.memoryTypeIndex = 0;
18385
18386 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18387 memory_info.allocationSize = memory_reqs.size;
18388 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18389 ASSERT_TRUE(pass);
18390
18391 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18392 ASSERT_VK_SUCCESS(err);
18393 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18394 ASSERT_VK_SUCCESS(err);
18395
18396 VkBufferViewCreateInfo buff_view_ci = {};
18397 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18398 buff_view_ci.buffer = buffer;
18399 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18400 buff_view_ci.range = VK_WHOLE_SIZE;
18401 VkBufferView buffer_view;
18402 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18403
18404 VkDescriptorPoolSize ds_type_count = {};
18405 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18406 ds_type_count.descriptorCount = 1;
18407
18408 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18409 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18410 ds_pool_ci.pNext = NULL;
18411 ds_pool_ci.maxSets = 1;
18412 ds_pool_ci.poolSizeCount = 1;
18413 ds_pool_ci.pPoolSizes = &ds_type_count;
18414
18415 VkDescriptorPool ds_pool;
18416 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18417 ASSERT_VK_SUCCESS(err);
18418
18419 VkDescriptorSetLayoutBinding dsl_binding = {};
18420 dsl_binding.binding = 0;
18421 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18422 dsl_binding.descriptorCount = 1;
18423 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18424 dsl_binding.pImmutableSamplers = NULL;
18425
18426 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18427 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18428 ds_layout_ci.pNext = NULL;
18429 ds_layout_ci.bindingCount = 1;
18430 ds_layout_ci.pBindings = &dsl_binding;
18431 VkDescriptorSetLayout ds_layout;
18432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18433 ASSERT_VK_SUCCESS(err);
18434
18435 VkDescriptorSet descriptor_set;
18436 VkDescriptorSetAllocateInfo alloc_info = {};
18437 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18438 alloc_info.descriptorSetCount = 1;
18439 alloc_info.descriptorPool = ds_pool;
18440 alloc_info.pSetLayouts = &ds_layout;
18441 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18442 ASSERT_VK_SUCCESS(err);
18443
18444 VkWriteDescriptorSet descriptor_write;
18445 memset(&descriptor_write, 0, sizeof(descriptor_write));
18446 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18447 descriptor_write.dstSet = descriptor_set;
18448 descriptor_write.dstBinding = 0;
18449 descriptor_write.descriptorCount = 1;
18450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18451 descriptor_write.pTexelBufferView = &buffer_view;
18452
18453 // Set pImageInfo and pBufferInfo to invalid values, which should be
18454 // ignored for descriptorType ==
18455 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18456 // This will most likely produce a crash if the parameter_validation
18457 // layer
18458 // does not correctly ignore pImageInfo and pBufferInfo.
18459 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18460 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18461
18462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18463
18464 m_errorMonitor->VerifyNotFound();
18465
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18468 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18469 vkDestroyBuffer(m_device->device(), buffer, NULL);
18470 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18471 }
18472}
18473
Tobin Ehlisf7428442016-10-25 07:58:24 -060018474TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18475 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18476
18477 ASSERT_NO_FATAL_FAILURE(InitState());
18478 // Create layout where two binding #s are "1"
18479 static const uint32_t NUM_BINDINGS = 3;
18480 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18481 dsl_binding[0].binding = 1;
18482 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18483 dsl_binding[0].descriptorCount = 1;
18484 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18485 dsl_binding[0].pImmutableSamplers = NULL;
18486 dsl_binding[1].binding = 0;
18487 dsl_binding[1].descriptorCount = 1;
18488 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18489 dsl_binding[1].descriptorCount = 1;
18490 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18491 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018492 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018493 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18494 dsl_binding[2].descriptorCount = 1;
18495 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18496 dsl_binding[2].pImmutableSamplers = NULL;
18497
18498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18500 ds_layout_ci.pNext = NULL;
18501 ds_layout_ci.bindingCount = NUM_BINDINGS;
18502 ds_layout_ci.pBindings = dsl_binding;
18503 VkDescriptorSetLayout ds_layout;
18504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18505 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18506 m_errorMonitor->VerifyFound();
18507}
18508
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018509TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018510 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18511
18512 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018513
Tony Barbour552f6c02016-12-21 14:34:07 -070018514 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018515
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018516 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18517
18518 {
18519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18520 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18521 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18522 m_errorMonitor->VerifyFound();
18523 }
18524
18525 {
18526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18527 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18528 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18529 m_errorMonitor->VerifyFound();
18530 }
18531
18532 {
18533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18534 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18535 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18536 m_errorMonitor->VerifyFound();
18537 }
18538
18539 {
18540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18541 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18542 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18543 m_errorMonitor->VerifyFound();
18544 }
18545
18546 {
18547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18548 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18549 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18550 m_errorMonitor->VerifyFound();
18551 }
18552
18553 {
18554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18555 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18556 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18557 m_errorMonitor->VerifyFound();
18558 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018559
18560 {
18561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18562 VkRect2D scissor = {{-1, 0}, {16, 16}};
18563 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18564 m_errorMonitor->VerifyFound();
18565 }
18566
18567 {
18568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18569 VkRect2D scissor = {{0, -2}, {16, 16}};
18570 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18571 m_errorMonitor->VerifyFound();
18572 }
18573
18574 {
18575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18576 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18577 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18578 m_errorMonitor->VerifyFound();
18579 }
18580
18581 {
18582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18583 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18584 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18585 m_errorMonitor->VerifyFound();
18586 }
18587
Tony Barbour552f6c02016-12-21 14:34:07 -070018588 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018589}
18590
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018591// This is a positive test. No failures are expected.
18592TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18593 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18594 VkResult err;
18595
18596 ASSERT_NO_FATAL_FAILURE(InitState());
18597 m_errorMonitor->ExpectSuccess();
18598 VkDescriptorPoolSize ds_type_count = {};
18599 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18600 ds_type_count.descriptorCount = 2;
18601
18602 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18603 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18604 ds_pool_ci.pNext = NULL;
18605 ds_pool_ci.maxSets = 1;
18606 ds_pool_ci.poolSizeCount = 1;
18607 ds_pool_ci.pPoolSizes = &ds_type_count;
18608
18609 VkDescriptorPool ds_pool;
18610 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18611 ASSERT_VK_SUCCESS(err);
18612
18613 // Create layout with two uniform buffer descriptors w/ empty binding between them
18614 static const uint32_t NUM_BINDINGS = 3;
18615 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18616 dsl_binding[0].binding = 0;
18617 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18618 dsl_binding[0].descriptorCount = 1;
18619 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18620 dsl_binding[0].pImmutableSamplers = NULL;
18621 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018622 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018623 dsl_binding[2].binding = 2;
18624 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18625 dsl_binding[2].descriptorCount = 1;
18626 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18627 dsl_binding[2].pImmutableSamplers = NULL;
18628
18629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18631 ds_layout_ci.pNext = NULL;
18632 ds_layout_ci.bindingCount = NUM_BINDINGS;
18633 ds_layout_ci.pBindings = dsl_binding;
18634 VkDescriptorSetLayout ds_layout;
18635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18636 ASSERT_VK_SUCCESS(err);
18637
18638 VkDescriptorSet descriptor_set = {};
18639 VkDescriptorSetAllocateInfo alloc_info = {};
18640 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18641 alloc_info.descriptorSetCount = 1;
18642 alloc_info.descriptorPool = ds_pool;
18643 alloc_info.pSetLayouts = &ds_layout;
18644 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18645 ASSERT_VK_SUCCESS(err);
18646
18647 // Create a buffer to be used for update
18648 VkBufferCreateInfo buff_ci = {};
18649 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18650 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18651 buff_ci.size = 256;
18652 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18653 VkBuffer buffer;
18654 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18655 ASSERT_VK_SUCCESS(err);
18656 // Have to bind memory to buffer before descriptor update
18657 VkMemoryAllocateInfo mem_alloc = {};
18658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18659 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018660 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018661 mem_alloc.memoryTypeIndex = 0;
18662
18663 VkMemoryRequirements mem_reqs;
18664 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18665 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18666 if (!pass) {
18667 vkDestroyBuffer(m_device->device(), buffer, NULL);
18668 return;
18669 }
18670
18671 VkDeviceMemory mem;
18672 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18673 ASSERT_VK_SUCCESS(err);
18674 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18675 ASSERT_VK_SUCCESS(err);
18676
18677 // Only update the descriptor at binding 2
18678 VkDescriptorBufferInfo buff_info = {};
18679 buff_info.buffer = buffer;
18680 buff_info.offset = 0;
18681 buff_info.range = VK_WHOLE_SIZE;
18682 VkWriteDescriptorSet descriptor_write = {};
18683 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18684 descriptor_write.dstBinding = 2;
18685 descriptor_write.descriptorCount = 1;
18686 descriptor_write.pTexelBufferView = nullptr;
18687 descriptor_write.pBufferInfo = &buff_info;
18688 descriptor_write.pImageInfo = nullptr;
18689 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18690 descriptor_write.dstSet = descriptor_set;
18691
18692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18693
18694 m_errorMonitor->VerifyNotFound();
18695 // Cleanup
18696 vkFreeMemory(m_device->device(), mem, NULL);
18697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18698 vkDestroyBuffer(m_device->device(), buffer, NULL);
18699 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18700}
18701
18702// This is a positive test. No failures are expected.
18703TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18704 VkResult err;
18705 bool pass;
18706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018707 TEST_DESCRIPTION(
18708 "Create a buffer, allocate memory, bind memory, destroy "
18709 "the buffer, create an image, and bind the same memory to "
18710 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018711
18712 m_errorMonitor->ExpectSuccess();
18713
18714 ASSERT_NO_FATAL_FAILURE(InitState());
18715
18716 VkBuffer buffer;
18717 VkImage image;
18718 VkDeviceMemory mem;
18719 VkMemoryRequirements mem_reqs;
18720
18721 VkBufferCreateInfo buf_info = {};
18722 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18723 buf_info.pNext = NULL;
18724 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18725 buf_info.size = 256;
18726 buf_info.queueFamilyIndexCount = 0;
18727 buf_info.pQueueFamilyIndices = NULL;
18728 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18729 buf_info.flags = 0;
18730 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18731 ASSERT_VK_SUCCESS(err);
18732
18733 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18734
18735 VkMemoryAllocateInfo alloc_info = {};
18736 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18737 alloc_info.pNext = NULL;
18738 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018739
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018740 // Ensure memory is big enough for both bindings
18741 alloc_info.allocationSize = 0x10000;
18742
18743 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18744 if (!pass) {
18745 vkDestroyBuffer(m_device->device(), buffer, NULL);
18746 return;
18747 }
18748
18749 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18750 ASSERT_VK_SUCCESS(err);
18751
18752 uint8_t *pData;
18753 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18754 ASSERT_VK_SUCCESS(err);
18755
18756 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18757
18758 vkUnmapMemory(m_device->device(), mem);
18759
18760 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18761 ASSERT_VK_SUCCESS(err);
18762
18763 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18764 // memory. In fact, it was never used by the GPU.
18765 // Just be be sure, wait for idle.
18766 vkDestroyBuffer(m_device->device(), buffer, NULL);
18767 vkDeviceWaitIdle(m_device->device());
18768
Tobin Ehlis6a005702016-12-28 15:25:56 -070018769 // Use optimal as some platforms report linear support but then fail image creation
18770 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18771 VkImageFormatProperties image_format_properties;
18772 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18773 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18774 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018775 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018776 vkFreeMemory(m_device->device(), mem, NULL);
18777 return;
18778 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018779 VkImageCreateInfo image_create_info = {};
18780 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18781 image_create_info.pNext = NULL;
18782 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18783 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18784 image_create_info.extent.width = 64;
18785 image_create_info.extent.height = 64;
18786 image_create_info.extent.depth = 1;
18787 image_create_info.mipLevels = 1;
18788 image_create_info.arrayLayers = 1;
18789 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018790 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018791 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18792 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18793 image_create_info.queueFamilyIndexCount = 0;
18794 image_create_info.pQueueFamilyIndices = NULL;
18795 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18796 image_create_info.flags = 0;
18797
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018798 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018799 * to be textures or it will be the staging image if they are not.
18800 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018801 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18802 ASSERT_VK_SUCCESS(err);
18803
18804 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18805
Tobin Ehlis6a005702016-12-28 15:25:56 -070018806 VkMemoryAllocateInfo mem_alloc = {};
18807 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18808 mem_alloc.pNext = NULL;
18809 mem_alloc.allocationSize = 0;
18810 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018811 mem_alloc.allocationSize = mem_reqs.size;
18812
18813 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18814 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018815 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018816 vkDestroyImage(m_device->device(), image, NULL);
18817 return;
18818 }
18819
18820 // VALIDATION FAILURE:
18821 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18822 ASSERT_VK_SUCCESS(err);
18823
18824 m_errorMonitor->VerifyNotFound();
18825
18826 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018827 vkDestroyImage(m_device->device(), image, NULL);
18828}
18829
Tony Barbourab713912017-02-02 14:17:35 -070018830// This is a positive test. No failures are expected.
18831TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18832 VkResult err;
18833
18834 TEST_DESCRIPTION(
18835 "Call all applicable destroy and free routines with NULL"
18836 "handles, expecting no validation errors");
18837
18838 m_errorMonitor->ExpectSuccess();
18839
18840 ASSERT_NO_FATAL_FAILURE(InitState());
18841 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18842 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18843 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18844 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18845 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18846 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18847 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18848 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18849 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18850 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18851 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18852 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18853 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18854 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18855 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18856 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18857 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18858 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18859 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18860 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18861
18862 VkCommandPool command_pool;
18863 VkCommandPoolCreateInfo pool_create_info{};
18864 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18865 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18866 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18867 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18868 VkCommandBuffer command_buffers[3] = {};
18869 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18870 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18871 command_buffer_allocate_info.commandPool = command_pool;
18872 command_buffer_allocate_info.commandBufferCount = 1;
18873 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18874 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18875 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18876 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18877
18878 VkDescriptorPoolSize ds_type_count = {};
18879 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18880 ds_type_count.descriptorCount = 1;
18881
18882 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18883 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18884 ds_pool_ci.pNext = NULL;
18885 ds_pool_ci.maxSets = 1;
18886 ds_pool_ci.poolSizeCount = 1;
18887 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18888 ds_pool_ci.pPoolSizes = &ds_type_count;
18889
18890 VkDescriptorPool ds_pool;
18891 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18892 ASSERT_VK_SUCCESS(err);
18893
18894 VkDescriptorSetLayoutBinding dsl_binding = {};
18895 dsl_binding.binding = 2;
18896 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18897 dsl_binding.descriptorCount = 1;
18898 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18899 dsl_binding.pImmutableSamplers = NULL;
18900 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18901 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18902 ds_layout_ci.pNext = NULL;
18903 ds_layout_ci.bindingCount = 1;
18904 ds_layout_ci.pBindings = &dsl_binding;
18905 VkDescriptorSetLayout ds_layout;
18906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18907 ASSERT_VK_SUCCESS(err);
18908
18909 VkDescriptorSet descriptor_sets[3] = {};
18910 VkDescriptorSetAllocateInfo alloc_info = {};
18911 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18912 alloc_info.descriptorSetCount = 1;
18913 alloc_info.descriptorPool = ds_pool;
18914 alloc_info.pSetLayouts = &ds_layout;
18915 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18916 ASSERT_VK_SUCCESS(err);
18917 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18918 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18919 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18920
18921 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18922
18923 m_errorMonitor->VerifyNotFound();
18924}
18925
Tony Barbour626994c2017-02-08 15:29:37 -070018926TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018927 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018928
18929 m_errorMonitor->ExpectSuccess();
18930
18931 ASSERT_NO_FATAL_FAILURE(InitState());
18932 VkCommandBuffer cmd_bufs[4];
18933 VkCommandBufferAllocateInfo alloc_info;
18934 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18935 alloc_info.pNext = NULL;
18936 alloc_info.commandBufferCount = 4;
18937 alloc_info.commandPool = m_commandPool;
18938 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18939 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18940 VkImageObj image(m_device);
18941 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18942 ASSERT_TRUE(image.initialized());
18943 VkCommandBufferBeginInfo cb_binfo;
18944 cb_binfo.pNext = NULL;
18945 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18946 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18947 cb_binfo.flags = 0;
18948 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18949 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18950 VkImageMemoryBarrier img_barrier = {};
18951 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18952 img_barrier.pNext = NULL;
18953 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18954 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18955 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18956 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18957 img_barrier.image = image.handle();
18958 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18959 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18960 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18961 img_barrier.subresourceRange.baseArrayLayer = 0;
18962 img_barrier.subresourceRange.baseMipLevel = 0;
18963 img_barrier.subresourceRange.layerCount = 1;
18964 img_barrier.subresourceRange.levelCount = 1;
18965 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18966 &img_barrier);
18967 vkEndCommandBuffer(cmd_bufs[0]);
18968 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18969 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18970 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18971 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18972 &img_barrier);
18973 vkEndCommandBuffer(cmd_bufs[1]);
18974 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18975 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18976 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18977 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18978 &img_barrier);
18979 vkEndCommandBuffer(cmd_bufs[2]);
18980 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18981 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18982 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18983 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18984 &img_barrier);
18985 vkEndCommandBuffer(cmd_bufs[3]);
18986
18987 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18988 VkSemaphore semaphore1, semaphore2;
18989 VkSemaphoreCreateInfo semaphore_create_info{};
18990 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18991 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18992 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18993 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18994 VkSubmitInfo submit_info[3];
18995 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18996 submit_info[0].pNext = nullptr;
18997 submit_info[0].commandBufferCount = 1;
18998 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18999 submit_info[0].signalSemaphoreCount = 1;
19000 submit_info[0].pSignalSemaphores = &semaphore1;
19001 submit_info[0].waitSemaphoreCount = 0;
19002 submit_info[0].pWaitDstStageMask = nullptr;
19003 submit_info[0].pWaitDstStageMask = flags;
19004 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19005 submit_info[1].pNext = nullptr;
19006 submit_info[1].commandBufferCount = 1;
19007 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19008 submit_info[1].waitSemaphoreCount = 1;
19009 submit_info[1].pWaitSemaphores = &semaphore1;
19010 submit_info[1].signalSemaphoreCount = 1;
19011 submit_info[1].pSignalSemaphores = &semaphore2;
19012 submit_info[1].pWaitDstStageMask = flags;
19013 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19014 submit_info[2].pNext = nullptr;
19015 submit_info[2].commandBufferCount = 2;
19016 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19017 submit_info[2].waitSemaphoreCount = 1;
19018 submit_info[2].pWaitSemaphores = &semaphore2;
19019 submit_info[2].signalSemaphoreCount = 0;
19020 submit_info[2].pSignalSemaphores = nullptr;
19021 submit_info[2].pWaitDstStageMask = flags;
19022 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19023 vkQueueWaitIdle(m_device->m_queue);
19024
19025 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19026 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19027 m_errorMonitor->VerifyNotFound();
19028}
19029
Tobin Ehlis953e8392016-11-17 10:54:13 -070019030TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19031 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19032 // We previously had a bug where dynamic offset of inactive bindings was still being used
19033 VkResult err;
19034 m_errorMonitor->ExpectSuccess();
19035
19036 ASSERT_NO_FATAL_FAILURE(InitState());
19037 ASSERT_NO_FATAL_FAILURE(InitViewport());
19038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19039
19040 VkDescriptorPoolSize ds_type_count = {};
19041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19042 ds_type_count.descriptorCount = 3;
19043
19044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19046 ds_pool_ci.pNext = NULL;
19047 ds_pool_ci.maxSets = 1;
19048 ds_pool_ci.poolSizeCount = 1;
19049 ds_pool_ci.pPoolSizes = &ds_type_count;
19050
19051 VkDescriptorPool ds_pool;
19052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19053 ASSERT_VK_SUCCESS(err);
19054
19055 const uint32_t BINDING_COUNT = 3;
19056 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019057 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019058 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19059 dsl_binding[0].descriptorCount = 1;
19060 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19061 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019062 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019063 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19064 dsl_binding[1].descriptorCount = 1;
19065 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19066 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019067 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019068 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19069 dsl_binding[2].descriptorCount = 1;
19070 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19071 dsl_binding[2].pImmutableSamplers = NULL;
19072
19073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19075 ds_layout_ci.pNext = NULL;
19076 ds_layout_ci.bindingCount = BINDING_COUNT;
19077 ds_layout_ci.pBindings = dsl_binding;
19078 VkDescriptorSetLayout ds_layout;
19079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19080 ASSERT_VK_SUCCESS(err);
19081
19082 VkDescriptorSet descriptor_set;
19083 VkDescriptorSetAllocateInfo alloc_info = {};
19084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19085 alloc_info.descriptorSetCount = 1;
19086 alloc_info.descriptorPool = ds_pool;
19087 alloc_info.pSetLayouts = &ds_layout;
19088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19089 ASSERT_VK_SUCCESS(err);
19090
19091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19093 pipeline_layout_ci.pNext = NULL;
19094 pipeline_layout_ci.setLayoutCount = 1;
19095 pipeline_layout_ci.pSetLayouts = &ds_layout;
19096
19097 VkPipelineLayout pipeline_layout;
19098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19099 ASSERT_VK_SUCCESS(err);
19100
19101 // Create two buffers to update the descriptors with
19102 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19103 uint32_t qfi = 0;
19104 VkBufferCreateInfo buffCI = {};
19105 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19106 buffCI.size = 2048;
19107 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19108 buffCI.queueFamilyIndexCount = 1;
19109 buffCI.pQueueFamilyIndices = &qfi;
19110
19111 VkBuffer dyub1;
19112 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19113 ASSERT_VK_SUCCESS(err);
19114 // buffer2
19115 buffCI.size = 1024;
19116 VkBuffer dyub2;
19117 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19118 ASSERT_VK_SUCCESS(err);
19119 // Allocate memory and bind to buffers
19120 VkMemoryAllocateInfo mem_alloc[2] = {};
19121 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19122 mem_alloc[0].pNext = NULL;
19123 mem_alloc[0].memoryTypeIndex = 0;
19124 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19125 mem_alloc[1].pNext = NULL;
19126 mem_alloc[1].memoryTypeIndex = 0;
19127
19128 VkMemoryRequirements mem_reqs1;
19129 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19130 VkMemoryRequirements mem_reqs2;
19131 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19132 mem_alloc[0].allocationSize = mem_reqs1.size;
19133 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19134 mem_alloc[1].allocationSize = mem_reqs2.size;
19135 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19136 if (!pass) {
19137 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19138 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19139 return;
19140 }
19141
19142 VkDeviceMemory mem1;
19143 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19144 ASSERT_VK_SUCCESS(err);
19145 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19146 ASSERT_VK_SUCCESS(err);
19147 VkDeviceMemory mem2;
19148 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19149 ASSERT_VK_SUCCESS(err);
19150 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19151 ASSERT_VK_SUCCESS(err);
19152 // Update descriptors
19153 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19154 buff_info[0].buffer = dyub1;
19155 buff_info[0].offset = 0;
19156 buff_info[0].range = 256;
19157 buff_info[1].buffer = dyub1;
19158 buff_info[1].offset = 256;
19159 buff_info[1].range = 512;
19160 buff_info[2].buffer = dyub2;
19161 buff_info[2].offset = 0;
19162 buff_info[2].range = 512;
19163
19164 VkWriteDescriptorSet descriptor_write;
19165 memset(&descriptor_write, 0, sizeof(descriptor_write));
19166 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19167 descriptor_write.dstSet = descriptor_set;
19168 descriptor_write.dstBinding = 0;
19169 descriptor_write.descriptorCount = BINDING_COUNT;
19170 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19171 descriptor_write.pBufferInfo = buff_info;
19172
19173 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19174
Tony Barbour552f6c02016-12-21 14:34:07 -070019175 m_commandBuffer->BeginCommandBuffer();
19176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019177
19178 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019179 char const *vsSource =
19180 "#version 450\n"
19181 "\n"
19182 "out gl_PerVertex { \n"
19183 " vec4 gl_Position;\n"
19184 "};\n"
19185 "void main(){\n"
19186 " gl_Position = vec4(1);\n"
19187 "}\n";
19188 char const *fsSource =
19189 "#version 450\n"
19190 "\n"
19191 "layout(location=0) out vec4 x;\n"
19192 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19193 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19194 "void main(){\n"
19195 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19196 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19199 VkPipelineObj pipe(m_device);
19200 pipe.SetViewport(m_viewports);
19201 pipe.SetScissor(m_scissors);
19202 pipe.AddShader(&vs);
19203 pipe.AddShader(&fs);
19204 pipe.AddColorAttachment();
19205 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19206
19207 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19208 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19209 // we used to have a bug in this case.
19210 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19211 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19212 &descriptor_set, BINDING_COUNT, dyn_off);
19213 Draw(1, 0, 0, 0);
19214 m_errorMonitor->VerifyNotFound();
19215
19216 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19217 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19218 vkFreeMemory(m_device->device(), mem1, NULL);
19219 vkFreeMemory(m_device->device(), mem2, NULL);
19220
19221 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19222 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19223 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19224}
19225
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019226TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019227 TEST_DESCRIPTION(
19228 "Ensure that validations handling of non-coherent memory "
19229 "mapping while using VK_WHOLE_SIZE does not cause access "
19230 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019231 VkResult err;
19232 uint8_t *pData;
19233 ASSERT_NO_FATAL_FAILURE(InitState());
19234
19235 VkDeviceMemory mem;
19236 VkMemoryRequirements mem_reqs;
19237 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019238 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019239 VkMemoryAllocateInfo alloc_info = {};
19240 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19241 alloc_info.pNext = NULL;
19242 alloc_info.memoryTypeIndex = 0;
19243
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019244 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019245 alloc_info.allocationSize = allocation_size;
19246
19247 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19248 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 -070019249 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019250 if (!pass) {
19251 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019252 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19253 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019254 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019255 pass = m_device->phy().set_memory_type(
19256 mem_reqs.memoryTypeBits, &alloc_info,
19257 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19258 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019259 if (!pass) {
19260 return;
19261 }
19262 }
19263 }
19264
19265 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19266 ASSERT_VK_SUCCESS(err);
19267
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019268 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019269 m_errorMonitor->ExpectSuccess();
19270 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19271 ASSERT_VK_SUCCESS(err);
19272 VkMappedMemoryRange mmr = {};
19273 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19274 mmr.memory = mem;
19275 mmr.offset = 0;
19276 mmr.size = VK_WHOLE_SIZE;
19277 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19278 ASSERT_VK_SUCCESS(err);
19279 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19280 ASSERT_VK_SUCCESS(err);
19281 m_errorMonitor->VerifyNotFound();
19282 vkUnmapMemory(m_device->device(), mem);
19283
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019284 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019285 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019286 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019287 ASSERT_VK_SUCCESS(err);
19288 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19289 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019290 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019291 mmr.size = VK_WHOLE_SIZE;
19292 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19293 ASSERT_VK_SUCCESS(err);
19294 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19295 ASSERT_VK_SUCCESS(err);
19296 m_errorMonitor->VerifyNotFound();
19297 vkUnmapMemory(m_device->device(), mem);
19298
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019299 // Map with offset and size
19300 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019301 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019302 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019303 ASSERT_VK_SUCCESS(err);
19304 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19305 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019306 mmr.offset = 4 * atom_size;
19307 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019308 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19309 ASSERT_VK_SUCCESS(err);
19310 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19311 ASSERT_VK_SUCCESS(err);
19312 m_errorMonitor->VerifyNotFound();
19313 vkUnmapMemory(m_device->device(), mem);
19314
19315 // Map without offset and flush WHOLE_SIZE with two separate offsets
19316 m_errorMonitor->ExpectSuccess();
19317 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19318 ASSERT_VK_SUCCESS(err);
19319 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19320 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019321 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019322 mmr.size = VK_WHOLE_SIZE;
19323 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19324 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019325 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019326 mmr.size = VK_WHOLE_SIZE;
19327 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19328 ASSERT_VK_SUCCESS(err);
19329 m_errorMonitor->VerifyNotFound();
19330 vkUnmapMemory(m_device->device(), mem);
19331
19332 vkFreeMemory(m_device->device(), mem, NULL);
19333}
19334
19335// This is a positive test. We used to expect error in this case but spec now allows it
19336TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19337 m_errorMonitor->ExpectSuccess();
19338 vk_testing::Fence testFence;
19339 VkFenceCreateInfo fenceInfo = {};
19340 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19341 fenceInfo.pNext = NULL;
19342
19343 ASSERT_NO_FATAL_FAILURE(InitState());
19344 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019345 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019346 VkResult result = vkResetFences(m_device->device(), 1, fences);
19347 ASSERT_VK_SUCCESS(result);
19348
19349 m_errorMonitor->VerifyNotFound();
19350}
19351
19352TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19353 m_errorMonitor->ExpectSuccess();
19354
19355 ASSERT_NO_FATAL_FAILURE(InitState());
19356 VkResult err;
19357
19358 // Record (empty!) command buffer that can be submitted multiple times
19359 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019360 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19361 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362 m_commandBuffer->BeginCommandBuffer(&cbbi);
19363 m_commandBuffer->EndCommandBuffer();
19364
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019365 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019366 VkFence fence;
19367 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19368 ASSERT_VK_SUCCESS(err);
19369
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019370 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019371 VkSemaphore s1, s2;
19372 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19373 ASSERT_VK_SUCCESS(err);
19374 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19375 ASSERT_VK_SUCCESS(err);
19376
19377 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019378 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019379 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19380 ASSERT_VK_SUCCESS(err);
19381
19382 // Submit CB again, signaling s2.
19383 si.pSignalSemaphores = &s2;
19384 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19385 ASSERT_VK_SUCCESS(err);
19386
19387 // Wait for fence.
19388 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19389 ASSERT_VK_SUCCESS(err);
19390
19391 // CB is still in flight from second submission, but semaphore s1 is no
19392 // longer in flight. delete it.
19393 vkDestroySemaphore(m_device->device(), s1, nullptr);
19394
19395 m_errorMonitor->VerifyNotFound();
19396
19397 // Force device idle and clean up remaining objects
19398 vkDeviceWaitIdle(m_device->device());
19399 vkDestroySemaphore(m_device->device(), s2, nullptr);
19400 vkDestroyFence(m_device->device(), fence, nullptr);
19401}
19402
19403TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19404 m_errorMonitor->ExpectSuccess();
19405
19406 ASSERT_NO_FATAL_FAILURE(InitState());
19407 VkResult err;
19408
19409 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019410 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019411 VkFence f1;
19412 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19413 ASSERT_VK_SUCCESS(err);
19414
19415 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019416 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019417 VkFence f2;
19418 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19419 ASSERT_VK_SUCCESS(err);
19420
19421 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019422 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019423 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19424
19425 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019426 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019427 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19428
19429 // Should have both retired!
19430 vkDestroyFence(m_device->device(), f1, nullptr);
19431 vkDestroyFence(m_device->device(), f2, nullptr);
19432
19433 m_errorMonitor->VerifyNotFound();
19434}
19435
19436TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019437 TEST_DESCRIPTION(
19438 "Verify that creating an image view from an image with valid usage "
19439 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019440
19441 ASSERT_NO_FATAL_FAILURE(InitState());
19442
19443 m_errorMonitor->ExpectSuccess();
19444 // Verify that we can create a view with usage INPUT_ATTACHMENT
19445 VkImageObj image(m_device);
19446 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19447 ASSERT_TRUE(image.initialized());
19448 VkImageView imageView;
19449 VkImageViewCreateInfo ivci = {};
19450 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19451 ivci.image = image.handle();
19452 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19453 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19454 ivci.subresourceRange.layerCount = 1;
19455 ivci.subresourceRange.baseMipLevel = 0;
19456 ivci.subresourceRange.levelCount = 1;
19457 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19458
19459 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19460 m_errorMonitor->VerifyNotFound();
19461 vkDestroyImageView(m_device->device(), imageView, NULL);
19462}
19463
19464// This is a positive test. No failures are expected.
19465TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019466 TEST_DESCRIPTION(
19467 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19468 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019469
19470 ASSERT_NO_FATAL_FAILURE(InitState());
19471
19472 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019473 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019474
19475 m_errorMonitor->ExpectSuccess();
19476
19477 VkImage image;
19478 VkImageCreateInfo image_create_info = {};
19479 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19480 image_create_info.pNext = NULL;
19481 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19482 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19483 image_create_info.extent.width = 64;
19484 image_create_info.extent.height = 64;
19485 image_create_info.extent.depth = 1;
19486 image_create_info.mipLevels = 1;
19487 image_create_info.arrayLayers = 1;
19488 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19489 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19490 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19491 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19492 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19493 ASSERT_VK_SUCCESS(err);
19494
19495 VkMemoryRequirements memory_reqs;
19496 VkDeviceMemory memory_one, memory_two;
19497 bool pass;
19498 VkMemoryAllocateInfo memory_info = {};
19499 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19500 memory_info.pNext = NULL;
19501 memory_info.allocationSize = 0;
19502 memory_info.memoryTypeIndex = 0;
19503 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19504 // Find an image big enough to allow sparse mapping of 2 memory regions
19505 // Increase the image size until it is at least twice the
19506 // size of the required alignment, to ensure we can bind both
19507 // allocated memory blocks to the image on aligned offsets.
19508 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19509 vkDestroyImage(m_device->device(), image, nullptr);
19510 image_create_info.extent.width *= 2;
19511 image_create_info.extent.height *= 2;
19512 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19513 ASSERT_VK_SUCCESS(err);
19514 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19515 }
19516 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19517 // at the end of the first
19518 memory_info.allocationSize = memory_reqs.alignment;
19519 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19520 ASSERT_TRUE(pass);
19521 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19522 ASSERT_VK_SUCCESS(err);
19523 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19524 ASSERT_VK_SUCCESS(err);
19525 VkSparseMemoryBind binds[2];
19526 binds[0].flags = 0;
19527 binds[0].memory = memory_one;
19528 binds[0].memoryOffset = 0;
19529 binds[0].resourceOffset = 0;
19530 binds[0].size = memory_info.allocationSize;
19531 binds[1].flags = 0;
19532 binds[1].memory = memory_two;
19533 binds[1].memoryOffset = 0;
19534 binds[1].resourceOffset = memory_info.allocationSize;
19535 binds[1].size = memory_info.allocationSize;
19536
19537 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19538 opaqueBindInfo.image = image;
19539 opaqueBindInfo.bindCount = 2;
19540 opaqueBindInfo.pBinds = binds;
19541
19542 VkFence fence = VK_NULL_HANDLE;
19543 VkBindSparseInfo bindSparseInfo = {};
19544 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19545 bindSparseInfo.imageOpaqueBindCount = 1;
19546 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19547
19548 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19549 vkQueueWaitIdle(m_device->m_queue);
19550 vkDestroyImage(m_device->device(), image, NULL);
19551 vkFreeMemory(m_device->device(), memory_one, NULL);
19552 vkFreeMemory(m_device->device(), memory_two, NULL);
19553 m_errorMonitor->VerifyNotFound();
19554}
19555
19556TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019557 TEST_DESCRIPTION(
19558 "Ensure that CmdBeginRenderPass with an attachment's "
19559 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19560 "the command buffer has prior knowledge of that "
19561 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019562
19563 m_errorMonitor->ExpectSuccess();
19564
19565 ASSERT_NO_FATAL_FAILURE(InitState());
19566
19567 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019568 VkAttachmentDescription attachment = {0,
19569 VK_FORMAT_R8G8B8A8_UNORM,
19570 VK_SAMPLE_COUNT_1_BIT,
19571 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19572 VK_ATTACHMENT_STORE_OP_STORE,
19573 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19574 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19575 VK_IMAGE_LAYOUT_UNDEFINED,
19576 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019577
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019578 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019579
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019580 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019581
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019582 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019583
19584 VkRenderPass rp;
19585 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19586 ASSERT_VK_SUCCESS(err);
19587
19588 // A compatible framebuffer.
19589 VkImageObj image(m_device);
19590 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19591 ASSERT_TRUE(image.initialized());
19592
19593 VkImageViewCreateInfo ivci = {
19594 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19595 nullptr,
19596 0,
19597 image.handle(),
19598 VK_IMAGE_VIEW_TYPE_2D,
19599 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019600 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19601 VK_COMPONENT_SWIZZLE_IDENTITY},
19602 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019603 };
19604 VkImageView view;
19605 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19606 ASSERT_VK_SUCCESS(err);
19607
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019608 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019609 VkFramebuffer fb;
19610 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19611 ASSERT_VK_SUCCESS(err);
19612
19613 // Record a single command buffer which uses this renderpass twice. The
19614 // bug is triggered at the beginning of the second renderpass, when the
19615 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019616 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 -070019617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019618 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19619 vkCmdEndRenderPass(m_commandBuffer->handle());
19620 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19621
19622 m_errorMonitor->VerifyNotFound();
19623
19624 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019625 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019626
19627 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19628 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19629 vkDestroyImageView(m_device->device(), view, nullptr);
19630}
19631
19632TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019633 TEST_DESCRIPTION(
19634 "This test should pass. Create a Framebuffer and "
19635 "command buffer, bind them together, then destroy "
19636 "command pool and framebuffer and verify there are no "
19637 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019638
19639 m_errorMonitor->ExpectSuccess();
19640
19641 ASSERT_NO_FATAL_FAILURE(InitState());
19642
19643 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019644 VkAttachmentDescription attachment = {0,
19645 VK_FORMAT_R8G8B8A8_UNORM,
19646 VK_SAMPLE_COUNT_1_BIT,
19647 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19648 VK_ATTACHMENT_STORE_OP_STORE,
19649 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19650 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19651 VK_IMAGE_LAYOUT_UNDEFINED,
19652 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019653
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019654 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019655
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019656 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019657
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019658 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019659
19660 VkRenderPass rp;
19661 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19662 ASSERT_VK_SUCCESS(err);
19663
19664 // A compatible framebuffer.
19665 VkImageObj image(m_device);
19666 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19667 ASSERT_TRUE(image.initialized());
19668
19669 VkImageViewCreateInfo ivci = {
19670 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19671 nullptr,
19672 0,
19673 image.handle(),
19674 VK_IMAGE_VIEW_TYPE_2D,
19675 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019676 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19677 VK_COMPONENT_SWIZZLE_IDENTITY},
19678 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019679 };
19680 VkImageView view;
19681 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19682 ASSERT_VK_SUCCESS(err);
19683
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019684 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019685 VkFramebuffer fb;
19686 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19687 ASSERT_VK_SUCCESS(err);
19688
19689 // Explicitly create a command buffer to bind the FB to so that we can then
19690 // destroy the command pool in order to implicitly free command buffer
19691 VkCommandPool command_pool;
19692 VkCommandPoolCreateInfo pool_create_info{};
19693 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19694 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19695 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19696 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19697
19698 VkCommandBuffer command_buffer;
19699 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19700 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19701 command_buffer_allocate_info.commandPool = command_pool;
19702 command_buffer_allocate_info.commandBufferCount = 1;
19703 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19704 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19705
19706 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019707 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019708 VkCommandBufferBeginInfo begin_info{};
19709 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19710 vkBeginCommandBuffer(command_buffer, &begin_info);
19711
19712 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19713 vkCmdEndRenderPass(command_buffer);
19714 vkEndCommandBuffer(command_buffer);
19715 vkDestroyImageView(m_device->device(), view, nullptr);
19716 // Destroy command pool to implicitly free command buffer
19717 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19718 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19719 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19720 m_errorMonitor->VerifyNotFound();
19721}
19722
19723TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019724 TEST_DESCRIPTION(
19725 "Ensure that CmdBeginRenderPass applies the layout "
19726 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019727
19728 m_errorMonitor->ExpectSuccess();
19729
19730 ASSERT_NO_FATAL_FAILURE(InitState());
19731
19732 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019733 VkAttachmentDescription attachment = {0,
19734 VK_FORMAT_R8G8B8A8_UNORM,
19735 VK_SAMPLE_COUNT_1_BIT,
19736 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19737 VK_ATTACHMENT_STORE_OP_STORE,
19738 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19739 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19740 VK_IMAGE_LAYOUT_UNDEFINED,
19741 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019742
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019743 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019744
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019745 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019746
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019747 VkSubpassDependency dep = {0,
19748 0,
19749 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19750 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19751 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19752 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19753 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019754
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019755 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019756
19757 VkResult err;
19758 VkRenderPass rp;
19759 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19760 ASSERT_VK_SUCCESS(err);
19761
19762 // A compatible framebuffer.
19763 VkImageObj image(m_device);
19764 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19765 ASSERT_TRUE(image.initialized());
19766
19767 VkImageViewCreateInfo ivci = {
19768 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19769 nullptr,
19770 0,
19771 image.handle(),
19772 VK_IMAGE_VIEW_TYPE_2D,
19773 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019774 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19775 VK_COMPONENT_SWIZZLE_IDENTITY},
19776 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019777 };
19778 VkImageView view;
19779 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19780 ASSERT_VK_SUCCESS(err);
19781
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019782 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019783 VkFramebuffer fb;
19784 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19785 ASSERT_VK_SUCCESS(err);
19786
19787 // Record a single command buffer which issues a pipeline barrier w/
19788 // image memory barrier for the attachment. This detects the previously
19789 // missing tracking of the subpass layout by throwing a validation error
19790 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019791 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 -070019792 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019793 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19794
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019795 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19796 nullptr,
19797 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19798 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19800 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19801 VK_QUEUE_FAMILY_IGNORED,
19802 VK_QUEUE_FAMILY_IGNORED,
19803 image.handle(),
19804 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019805 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019806 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19807 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019808
19809 vkCmdEndRenderPass(m_commandBuffer->handle());
19810 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019811 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019812
19813 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19814 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19815 vkDestroyImageView(m_device->device(), view, nullptr);
19816}
19817
19818TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019819 TEST_DESCRIPTION(
19820 "Validate that when an imageView of a depth/stencil image "
19821 "is used as a depth/stencil framebuffer attachment, the "
19822 "aspectMask is ignored and both depth and stencil image "
19823 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019824
19825 VkFormatProperties format_properties;
19826 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19827 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19828 return;
19829 }
19830
19831 m_errorMonitor->ExpectSuccess();
19832
19833 ASSERT_NO_FATAL_FAILURE(InitState());
19834
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019835 VkAttachmentDescription attachment = {0,
19836 VK_FORMAT_D32_SFLOAT_S8_UINT,
19837 VK_SAMPLE_COUNT_1_BIT,
19838 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19839 VK_ATTACHMENT_STORE_OP_STORE,
19840 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19841 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19842 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19843 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019844
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019845 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019846
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019847 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019848
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019849 VkSubpassDependency dep = {0,
19850 0,
19851 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19852 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19853 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19854 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19855 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019856
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019857 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019858
19859 VkResult err;
19860 VkRenderPass rp;
19861 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19862 ASSERT_VK_SUCCESS(err);
19863
19864 VkImageObj image(m_device);
19865 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019866 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019867 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019868 ASSERT_TRUE(image.initialized());
19869 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19870
19871 VkImageViewCreateInfo ivci = {
19872 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19873 nullptr,
19874 0,
19875 image.handle(),
19876 VK_IMAGE_VIEW_TYPE_2D,
19877 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019878 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19879 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019880 };
19881 VkImageView view;
19882 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19883 ASSERT_VK_SUCCESS(err);
19884
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019885 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019886 VkFramebuffer fb;
19887 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19888 ASSERT_VK_SUCCESS(err);
19889
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019890 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 -070019891 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019892 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19893
19894 VkImageMemoryBarrier imb = {};
19895 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19896 imb.pNext = nullptr;
19897 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19898 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19899 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19900 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19901 imb.srcQueueFamilyIndex = 0;
19902 imb.dstQueueFamilyIndex = 0;
19903 imb.image = image.handle();
19904 imb.subresourceRange.aspectMask = 0x6;
19905 imb.subresourceRange.baseMipLevel = 0;
19906 imb.subresourceRange.levelCount = 0x1;
19907 imb.subresourceRange.baseArrayLayer = 0;
19908 imb.subresourceRange.layerCount = 0x1;
19909
19910 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019911 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19912 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019913
19914 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019915 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019916 QueueCommandBuffer(false);
19917 m_errorMonitor->VerifyNotFound();
19918
19919 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19920 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19921 vkDestroyImageView(m_device->device(), view, nullptr);
19922}
19923
19924TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019925 TEST_DESCRIPTION(
19926 "Ensure that layout transitions work correctly without "
19927 "errors, when an attachment reference is "
19928 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019929
19930 m_errorMonitor->ExpectSuccess();
19931
19932 ASSERT_NO_FATAL_FAILURE(InitState());
19933
19934 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019935 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019936
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019937 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019938
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019939 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019940
19941 VkRenderPass rp;
19942 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19943 ASSERT_VK_SUCCESS(err);
19944
19945 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019946 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019947 VkFramebuffer fb;
19948 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19949 ASSERT_VK_SUCCESS(err);
19950
19951 // Record a command buffer which just begins and ends the renderpass. The
19952 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019953 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 -070019954 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019955 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19956 vkCmdEndRenderPass(m_commandBuffer->handle());
19957 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019958 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019959
19960 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19961 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19962}
19963
19964// This is a positive test. No errors are expected.
19965TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019966 TEST_DESCRIPTION(
19967 "Create a stencil-only attachment with a LOAD_OP set to "
19968 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019969 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070019970 ASSERT_NO_FATAL_FAILURE(InitState());
19971 auto depth_format = find_depth_stencil_format(m_device);
19972 if (!depth_format) {
19973 printf(" No Depth + Stencil format found. Skipped.\n");
19974 return;
19975 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019976 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070019977 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019978 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19979 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019980 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19981 return;
19982 }
19983
Tony Barbourf887b162017-03-09 10:06:46 -070019984 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019985 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019986 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019987 VkAttachmentDescription att = {};
19988 VkAttachmentReference ref = {};
19989 att.format = depth_stencil_fmt;
19990 att.samples = VK_SAMPLE_COUNT_1_BIT;
19991 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19992 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19993 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19994 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19995 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19996 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19997
19998 VkClearValue clear;
19999 clear.depthStencil.depth = 1.0;
20000 clear.depthStencil.stencil = 0;
20001 ref.attachment = 0;
20002 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20003
20004 VkSubpassDescription subpass = {};
20005 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20006 subpass.flags = 0;
20007 subpass.inputAttachmentCount = 0;
20008 subpass.pInputAttachments = NULL;
20009 subpass.colorAttachmentCount = 0;
20010 subpass.pColorAttachments = NULL;
20011 subpass.pResolveAttachments = NULL;
20012 subpass.pDepthStencilAttachment = &ref;
20013 subpass.preserveAttachmentCount = 0;
20014 subpass.pPreserveAttachments = NULL;
20015
20016 VkRenderPass rp;
20017 VkRenderPassCreateInfo rp_info = {};
20018 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20019 rp_info.attachmentCount = 1;
20020 rp_info.pAttachments = &att;
20021 rp_info.subpassCount = 1;
20022 rp_info.pSubpasses = &subpass;
20023 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20024 ASSERT_VK_SUCCESS(result);
20025
20026 VkImageView *depthView = m_depthStencil->BindInfo();
20027 VkFramebufferCreateInfo fb_info = {};
20028 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20029 fb_info.pNext = NULL;
20030 fb_info.renderPass = rp;
20031 fb_info.attachmentCount = 1;
20032 fb_info.pAttachments = depthView;
20033 fb_info.width = 100;
20034 fb_info.height = 100;
20035 fb_info.layers = 1;
20036 VkFramebuffer fb;
20037 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20038 ASSERT_VK_SUCCESS(result);
20039
20040 VkRenderPassBeginInfo rpbinfo = {};
20041 rpbinfo.clearValueCount = 1;
20042 rpbinfo.pClearValues = &clear;
20043 rpbinfo.pNext = NULL;
20044 rpbinfo.renderPass = rp;
20045 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20046 rpbinfo.renderArea.extent.width = 100;
20047 rpbinfo.renderArea.extent.height = 100;
20048 rpbinfo.renderArea.offset.x = 0;
20049 rpbinfo.renderArea.offset.y = 0;
20050 rpbinfo.framebuffer = fb;
20051
20052 VkFence fence = {};
20053 VkFenceCreateInfo fence_ci = {};
20054 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20055 fence_ci.pNext = nullptr;
20056 fence_ci.flags = 0;
20057 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20058 ASSERT_VK_SUCCESS(result);
20059
20060 m_commandBuffer->BeginCommandBuffer();
20061 m_commandBuffer->BeginRenderPass(rpbinfo);
20062 m_commandBuffer->EndRenderPass();
20063 m_commandBuffer->EndCommandBuffer();
20064 m_commandBuffer->QueueCommandBuffer(fence);
20065
20066 VkImageObj destImage(m_device);
20067 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 -070020068 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069 VkImageMemoryBarrier barrier = {};
20070 VkImageSubresourceRange range;
20071 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20072 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20073 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20074 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20075 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20076 barrier.image = m_depthStencil->handle();
20077 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20078 range.baseMipLevel = 0;
20079 range.levelCount = 1;
20080 range.baseArrayLayer = 0;
20081 range.layerCount = 1;
20082 barrier.subresourceRange = range;
20083 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20084 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20085 cmdbuf.BeginCommandBuffer();
20086 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 -070020087 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020088 barrier.srcAccessMask = 0;
20089 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20090 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20091 barrier.image = destImage.handle();
20092 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20093 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 -070020094 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020095 VkImageCopy cregion;
20096 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20097 cregion.srcSubresource.mipLevel = 0;
20098 cregion.srcSubresource.baseArrayLayer = 0;
20099 cregion.srcSubresource.layerCount = 1;
20100 cregion.srcOffset.x = 0;
20101 cregion.srcOffset.y = 0;
20102 cregion.srcOffset.z = 0;
20103 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20104 cregion.dstSubresource.mipLevel = 0;
20105 cregion.dstSubresource.baseArrayLayer = 0;
20106 cregion.dstSubresource.layerCount = 1;
20107 cregion.dstOffset.x = 0;
20108 cregion.dstOffset.y = 0;
20109 cregion.dstOffset.z = 0;
20110 cregion.extent.width = 100;
20111 cregion.extent.height = 100;
20112 cregion.extent.depth = 1;
20113 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020114 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020115 cmdbuf.EndCommandBuffer();
20116
20117 VkSubmitInfo submit_info;
20118 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20119 submit_info.pNext = NULL;
20120 submit_info.waitSemaphoreCount = 0;
20121 submit_info.pWaitSemaphores = NULL;
20122 submit_info.pWaitDstStageMask = NULL;
20123 submit_info.commandBufferCount = 1;
20124 submit_info.pCommandBuffers = &cmdbuf.handle();
20125 submit_info.signalSemaphoreCount = 0;
20126 submit_info.pSignalSemaphores = NULL;
20127
20128 m_errorMonitor->ExpectSuccess();
20129 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20130 m_errorMonitor->VerifyNotFound();
20131
20132 vkQueueWaitIdle(m_device->m_queue);
20133 vkDestroyFence(m_device->device(), fence, nullptr);
20134 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20135 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20136}
20137
20138// This is a positive test. No errors should be generated.
20139TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20140 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20141
20142 m_errorMonitor->ExpectSuccess();
20143 ASSERT_NO_FATAL_FAILURE(InitState());
20144
20145 VkEvent event;
20146 VkEventCreateInfo event_create_info{};
20147 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20148 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20149
20150 VkCommandPool command_pool;
20151 VkCommandPoolCreateInfo pool_create_info{};
20152 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20153 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20154 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20155 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20156
20157 VkCommandBuffer command_buffer;
20158 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20159 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20160 command_buffer_allocate_info.commandPool = command_pool;
20161 command_buffer_allocate_info.commandBufferCount = 1;
20162 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20163 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20164
20165 VkQueue queue = VK_NULL_HANDLE;
20166 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20167
20168 {
20169 VkCommandBufferBeginInfo begin_info{};
20170 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20171 vkBeginCommandBuffer(command_buffer, &begin_info);
20172
20173 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 -070020174 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020175 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20176 vkEndCommandBuffer(command_buffer);
20177 }
20178 {
20179 VkSubmitInfo submit_info{};
20180 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20181 submit_info.commandBufferCount = 1;
20182 submit_info.pCommandBuffers = &command_buffer;
20183 submit_info.signalSemaphoreCount = 0;
20184 submit_info.pSignalSemaphores = nullptr;
20185 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20186 }
20187 { vkSetEvent(m_device->device(), event); }
20188
20189 vkQueueWaitIdle(queue);
20190
20191 vkDestroyEvent(m_device->device(), event, nullptr);
20192 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20193 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20194
20195 m_errorMonitor->VerifyNotFound();
20196}
20197// This is a positive test. No errors should be generated.
20198TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20199 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20200
20201 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020202 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020203
20204 m_errorMonitor->ExpectSuccess();
20205
20206 VkQueryPool query_pool;
20207 VkQueryPoolCreateInfo query_pool_create_info{};
20208 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20209 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20210 query_pool_create_info.queryCount = 1;
20211 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20212
20213 VkCommandPool command_pool;
20214 VkCommandPoolCreateInfo pool_create_info{};
20215 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20216 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20217 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20218 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20219
20220 VkCommandBuffer command_buffer;
20221 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20222 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20223 command_buffer_allocate_info.commandPool = command_pool;
20224 command_buffer_allocate_info.commandBufferCount = 1;
20225 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20226 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20227
20228 VkCommandBuffer secondary_command_buffer;
20229 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20230 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20231
20232 VkQueue queue = VK_NULL_HANDLE;
20233 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20234
20235 uint32_t qfi = 0;
20236 VkBufferCreateInfo buff_create_info = {};
20237 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20238 buff_create_info.size = 1024;
20239 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20240 buff_create_info.queueFamilyIndexCount = 1;
20241 buff_create_info.pQueueFamilyIndices = &qfi;
20242
20243 VkResult err;
20244 VkBuffer buffer;
20245 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20246 ASSERT_VK_SUCCESS(err);
20247 VkMemoryAllocateInfo mem_alloc = {};
20248 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20249 mem_alloc.pNext = NULL;
20250 mem_alloc.allocationSize = 1024;
20251 mem_alloc.memoryTypeIndex = 0;
20252
20253 VkMemoryRequirements memReqs;
20254 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20255 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20256 if (!pass) {
20257 vkDestroyBuffer(m_device->device(), buffer, NULL);
20258 return;
20259 }
20260
20261 VkDeviceMemory mem;
20262 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20263 ASSERT_VK_SUCCESS(err);
20264 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20265 ASSERT_VK_SUCCESS(err);
20266
20267 VkCommandBufferInheritanceInfo hinfo = {};
20268 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20269 hinfo.renderPass = VK_NULL_HANDLE;
20270 hinfo.subpass = 0;
20271 hinfo.framebuffer = VK_NULL_HANDLE;
20272 hinfo.occlusionQueryEnable = VK_FALSE;
20273 hinfo.queryFlags = 0;
20274 hinfo.pipelineStatistics = 0;
20275
20276 {
20277 VkCommandBufferBeginInfo begin_info{};
20278 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20279 begin_info.pInheritanceInfo = &hinfo;
20280 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20281
20282 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20283 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20284
20285 vkEndCommandBuffer(secondary_command_buffer);
20286
20287 begin_info.pInheritanceInfo = nullptr;
20288 vkBeginCommandBuffer(command_buffer, &begin_info);
20289
20290 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20291 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20292
20293 vkEndCommandBuffer(command_buffer);
20294 }
20295 {
20296 VkSubmitInfo submit_info{};
20297 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20298 submit_info.commandBufferCount = 1;
20299 submit_info.pCommandBuffers = &command_buffer;
20300 submit_info.signalSemaphoreCount = 0;
20301 submit_info.pSignalSemaphores = nullptr;
20302 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20303 }
20304
20305 vkQueueWaitIdle(queue);
20306
20307 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20308 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20309 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20310 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20311 vkDestroyBuffer(m_device->device(), buffer, NULL);
20312 vkFreeMemory(m_device->device(), mem, NULL);
20313
20314 m_errorMonitor->VerifyNotFound();
20315}
20316
20317// This is a positive test. No errors should be generated.
20318TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20319 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20320
20321 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020322 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020323
20324 m_errorMonitor->ExpectSuccess();
20325
20326 VkQueryPool query_pool;
20327 VkQueryPoolCreateInfo query_pool_create_info{};
20328 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20329 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20330 query_pool_create_info.queryCount = 1;
20331 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20332
20333 VkCommandPool command_pool;
20334 VkCommandPoolCreateInfo pool_create_info{};
20335 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20336 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20337 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20338 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20339
20340 VkCommandBuffer command_buffer[2];
20341 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20342 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20343 command_buffer_allocate_info.commandPool = command_pool;
20344 command_buffer_allocate_info.commandBufferCount = 2;
20345 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20346 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20347
20348 VkQueue queue = VK_NULL_HANDLE;
20349 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20350
20351 uint32_t qfi = 0;
20352 VkBufferCreateInfo buff_create_info = {};
20353 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20354 buff_create_info.size = 1024;
20355 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20356 buff_create_info.queueFamilyIndexCount = 1;
20357 buff_create_info.pQueueFamilyIndices = &qfi;
20358
20359 VkResult err;
20360 VkBuffer buffer;
20361 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20362 ASSERT_VK_SUCCESS(err);
20363 VkMemoryAllocateInfo mem_alloc = {};
20364 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20365 mem_alloc.pNext = NULL;
20366 mem_alloc.allocationSize = 1024;
20367 mem_alloc.memoryTypeIndex = 0;
20368
20369 VkMemoryRequirements memReqs;
20370 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20371 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20372 if (!pass) {
20373 vkDestroyBuffer(m_device->device(), buffer, NULL);
20374 return;
20375 }
20376
20377 VkDeviceMemory mem;
20378 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20379 ASSERT_VK_SUCCESS(err);
20380 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20381 ASSERT_VK_SUCCESS(err);
20382
20383 {
20384 VkCommandBufferBeginInfo begin_info{};
20385 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20386 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20387
20388 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20389 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20390
20391 vkEndCommandBuffer(command_buffer[0]);
20392
20393 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20394
20395 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20396
20397 vkEndCommandBuffer(command_buffer[1]);
20398 }
20399 {
20400 VkSubmitInfo submit_info{};
20401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20402 submit_info.commandBufferCount = 2;
20403 submit_info.pCommandBuffers = command_buffer;
20404 submit_info.signalSemaphoreCount = 0;
20405 submit_info.pSignalSemaphores = nullptr;
20406 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20407 }
20408
20409 vkQueueWaitIdle(queue);
20410
20411 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20412 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20413 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20414 vkDestroyBuffer(m_device->device(), buffer, NULL);
20415 vkFreeMemory(m_device->device(), mem, NULL);
20416
20417 m_errorMonitor->VerifyNotFound();
20418}
20419
Tony Barbourc46924f2016-11-04 11:49:52 -060020420TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020421 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20422
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020423 ASSERT_NO_FATAL_FAILURE(InitState());
20424 VkEvent event;
20425 VkEventCreateInfo event_create_info{};
20426 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20427 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20428
20429 VkCommandPool command_pool;
20430 VkCommandPoolCreateInfo pool_create_info{};
20431 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20432 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20433 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20434 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20435
20436 VkCommandBuffer command_buffer;
20437 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20438 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20439 command_buffer_allocate_info.commandPool = command_pool;
20440 command_buffer_allocate_info.commandBufferCount = 1;
20441 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20442 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20443
20444 VkQueue queue = VK_NULL_HANDLE;
20445 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20446
20447 {
20448 VkCommandBufferBeginInfo begin_info{};
20449 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20450 vkBeginCommandBuffer(command_buffer, &begin_info);
20451
20452 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020453 vkEndCommandBuffer(command_buffer);
20454 }
20455 {
20456 VkSubmitInfo submit_info{};
20457 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20458 submit_info.commandBufferCount = 1;
20459 submit_info.pCommandBuffers = &command_buffer;
20460 submit_info.signalSemaphoreCount = 0;
20461 submit_info.pSignalSemaphores = nullptr;
20462 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20463 }
20464 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20466 "that is already in use by a "
20467 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020468 vkSetEvent(m_device->device(), event);
20469 m_errorMonitor->VerifyFound();
20470 }
20471
20472 vkQueueWaitIdle(queue);
20473
20474 vkDestroyEvent(m_device->device(), event, nullptr);
20475 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20476 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20477}
20478
20479// This is a positive test. No errors should be generated.
20480TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020481 TEST_DESCRIPTION(
20482 "Two command buffers with two separate fences are each "
20483 "run through a Submit & WaitForFences cycle 3 times. This "
20484 "previously revealed a bug so running this positive test "
20485 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020486 m_errorMonitor->ExpectSuccess();
20487
20488 ASSERT_NO_FATAL_FAILURE(InitState());
20489 VkQueue queue = VK_NULL_HANDLE;
20490 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20491
20492 static const uint32_t NUM_OBJECTS = 2;
20493 static const uint32_t NUM_FRAMES = 3;
20494 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20495 VkFence fences[NUM_OBJECTS] = {};
20496
20497 VkCommandPool cmd_pool;
20498 VkCommandPoolCreateInfo cmd_pool_ci = {};
20499 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20500 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20501 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20502 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20503 ASSERT_VK_SUCCESS(err);
20504
20505 VkCommandBufferAllocateInfo cmd_buf_info = {};
20506 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20507 cmd_buf_info.commandPool = cmd_pool;
20508 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20509 cmd_buf_info.commandBufferCount = 1;
20510
20511 VkFenceCreateInfo fence_ci = {};
20512 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20513 fence_ci.pNext = nullptr;
20514 fence_ci.flags = 0;
20515
20516 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20517 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20518 ASSERT_VK_SUCCESS(err);
20519 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20520 ASSERT_VK_SUCCESS(err);
20521 }
20522
20523 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20524 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20525 // Create empty cmd buffer
20526 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20527 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20528
20529 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20530 ASSERT_VK_SUCCESS(err);
20531 err = vkEndCommandBuffer(cmd_buffers[obj]);
20532 ASSERT_VK_SUCCESS(err);
20533
20534 VkSubmitInfo submit_info = {};
20535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20536 submit_info.commandBufferCount = 1;
20537 submit_info.pCommandBuffers = &cmd_buffers[obj];
20538 // Submit cmd buffer and wait for fence
20539 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20540 ASSERT_VK_SUCCESS(err);
20541 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20542 ASSERT_VK_SUCCESS(err);
20543 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20544 ASSERT_VK_SUCCESS(err);
20545 }
20546 }
20547 m_errorMonitor->VerifyNotFound();
20548 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20549 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20550 vkDestroyFence(m_device->device(), fences[i], nullptr);
20551 }
20552}
20553// This is a positive test. No errors should be generated.
20554TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020555 TEST_DESCRIPTION(
20556 "Two command buffers, each in a separate QueueSubmit call "
20557 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020558
20559 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020560 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020561
20562 m_errorMonitor->ExpectSuccess();
20563
20564 VkSemaphore semaphore;
20565 VkSemaphoreCreateInfo semaphore_create_info{};
20566 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20567 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20568
20569 VkCommandPool command_pool;
20570 VkCommandPoolCreateInfo pool_create_info{};
20571 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20572 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20573 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20574 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20575
20576 VkCommandBuffer command_buffer[2];
20577 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20578 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20579 command_buffer_allocate_info.commandPool = command_pool;
20580 command_buffer_allocate_info.commandBufferCount = 2;
20581 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20582 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20583
20584 VkQueue queue = VK_NULL_HANDLE;
20585 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20586
20587 {
20588 VkCommandBufferBeginInfo begin_info{};
20589 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20590 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20591
20592 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 -070020593 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020594
20595 VkViewport viewport{};
20596 viewport.maxDepth = 1.0f;
20597 viewport.minDepth = 0.0f;
20598 viewport.width = 512;
20599 viewport.height = 512;
20600 viewport.x = 0;
20601 viewport.y = 0;
20602 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20603 vkEndCommandBuffer(command_buffer[0]);
20604 }
20605 {
20606 VkCommandBufferBeginInfo begin_info{};
20607 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20608 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20609
20610 VkViewport viewport{};
20611 viewport.maxDepth = 1.0f;
20612 viewport.minDepth = 0.0f;
20613 viewport.width = 512;
20614 viewport.height = 512;
20615 viewport.x = 0;
20616 viewport.y = 0;
20617 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20618 vkEndCommandBuffer(command_buffer[1]);
20619 }
20620 {
20621 VkSubmitInfo submit_info{};
20622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20623 submit_info.commandBufferCount = 1;
20624 submit_info.pCommandBuffers = &command_buffer[0];
20625 submit_info.signalSemaphoreCount = 1;
20626 submit_info.pSignalSemaphores = &semaphore;
20627 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20628 }
20629 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020630 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020631 VkSubmitInfo submit_info{};
20632 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20633 submit_info.commandBufferCount = 1;
20634 submit_info.pCommandBuffers = &command_buffer[1];
20635 submit_info.waitSemaphoreCount = 1;
20636 submit_info.pWaitSemaphores = &semaphore;
20637 submit_info.pWaitDstStageMask = flags;
20638 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20639 }
20640
20641 vkQueueWaitIdle(m_device->m_queue);
20642
20643 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20644 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20645 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20646
20647 m_errorMonitor->VerifyNotFound();
20648}
20649
20650// This is a positive test. No errors should be generated.
20651TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020652 TEST_DESCRIPTION(
20653 "Two command buffers, each in a separate QueueSubmit call "
20654 "submitted on separate queues, the second having a fence"
20655 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020656
20657 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020658 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020659
20660 m_errorMonitor->ExpectSuccess();
20661
20662 VkFence fence;
20663 VkFenceCreateInfo fence_create_info{};
20664 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20665 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20666
20667 VkSemaphore semaphore;
20668 VkSemaphoreCreateInfo semaphore_create_info{};
20669 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20670 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20671
20672 VkCommandPool command_pool;
20673 VkCommandPoolCreateInfo pool_create_info{};
20674 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20675 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20676 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20677 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20678
20679 VkCommandBuffer command_buffer[2];
20680 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20681 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20682 command_buffer_allocate_info.commandPool = command_pool;
20683 command_buffer_allocate_info.commandBufferCount = 2;
20684 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20685 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20686
20687 VkQueue queue = VK_NULL_HANDLE;
20688 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20689
20690 {
20691 VkCommandBufferBeginInfo begin_info{};
20692 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20693 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20694
20695 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 -070020696 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020697
20698 VkViewport viewport{};
20699 viewport.maxDepth = 1.0f;
20700 viewport.minDepth = 0.0f;
20701 viewport.width = 512;
20702 viewport.height = 512;
20703 viewport.x = 0;
20704 viewport.y = 0;
20705 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20706 vkEndCommandBuffer(command_buffer[0]);
20707 }
20708 {
20709 VkCommandBufferBeginInfo begin_info{};
20710 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20711 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20712
20713 VkViewport viewport{};
20714 viewport.maxDepth = 1.0f;
20715 viewport.minDepth = 0.0f;
20716 viewport.width = 512;
20717 viewport.height = 512;
20718 viewport.x = 0;
20719 viewport.y = 0;
20720 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20721 vkEndCommandBuffer(command_buffer[1]);
20722 }
20723 {
20724 VkSubmitInfo submit_info{};
20725 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20726 submit_info.commandBufferCount = 1;
20727 submit_info.pCommandBuffers = &command_buffer[0];
20728 submit_info.signalSemaphoreCount = 1;
20729 submit_info.pSignalSemaphores = &semaphore;
20730 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20731 }
20732 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020733 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020734 VkSubmitInfo submit_info{};
20735 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20736 submit_info.commandBufferCount = 1;
20737 submit_info.pCommandBuffers = &command_buffer[1];
20738 submit_info.waitSemaphoreCount = 1;
20739 submit_info.pWaitSemaphores = &semaphore;
20740 submit_info.pWaitDstStageMask = flags;
20741 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20742 }
20743
20744 vkQueueWaitIdle(m_device->m_queue);
20745
20746 vkDestroyFence(m_device->device(), fence, nullptr);
20747 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20748 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20749 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20750
20751 m_errorMonitor->VerifyNotFound();
20752}
20753
20754// This is a positive test. No errors should be generated.
20755TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020756 TEST_DESCRIPTION(
20757 "Two command buffers, each in a separate QueueSubmit call "
20758 "submitted on separate queues, the second having a fence"
20759 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020760
20761 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020762 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020763
20764 m_errorMonitor->ExpectSuccess();
20765
20766 VkFence fence;
20767 VkFenceCreateInfo fence_create_info{};
20768 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20769 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20770
20771 VkSemaphore semaphore;
20772 VkSemaphoreCreateInfo semaphore_create_info{};
20773 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20774 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20775
20776 VkCommandPool command_pool;
20777 VkCommandPoolCreateInfo pool_create_info{};
20778 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20779 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20780 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20781 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20782
20783 VkCommandBuffer command_buffer[2];
20784 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20785 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20786 command_buffer_allocate_info.commandPool = command_pool;
20787 command_buffer_allocate_info.commandBufferCount = 2;
20788 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20789 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20790
20791 VkQueue queue = VK_NULL_HANDLE;
20792 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20793
20794 {
20795 VkCommandBufferBeginInfo begin_info{};
20796 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20797 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20798
20799 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 -070020800 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020801
20802 VkViewport viewport{};
20803 viewport.maxDepth = 1.0f;
20804 viewport.minDepth = 0.0f;
20805 viewport.width = 512;
20806 viewport.height = 512;
20807 viewport.x = 0;
20808 viewport.y = 0;
20809 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20810 vkEndCommandBuffer(command_buffer[0]);
20811 }
20812 {
20813 VkCommandBufferBeginInfo begin_info{};
20814 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20815 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20816
20817 VkViewport viewport{};
20818 viewport.maxDepth = 1.0f;
20819 viewport.minDepth = 0.0f;
20820 viewport.width = 512;
20821 viewport.height = 512;
20822 viewport.x = 0;
20823 viewport.y = 0;
20824 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20825 vkEndCommandBuffer(command_buffer[1]);
20826 }
20827 {
20828 VkSubmitInfo submit_info{};
20829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20830 submit_info.commandBufferCount = 1;
20831 submit_info.pCommandBuffers = &command_buffer[0];
20832 submit_info.signalSemaphoreCount = 1;
20833 submit_info.pSignalSemaphores = &semaphore;
20834 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20835 }
20836 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020837 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020838 VkSubmitInfo submit_info{};
20839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20840 submit_info.commandBufferCount = 1;
20841 submit_info.pCommandBuffers = &command_buffer[1];
20842 submit_info.waitSemaphoreCount = 1;
20843 submit_info.pWaitSemaphores = &semaphore;
20844 submit_info.pWaitDstStageMask = flags;
20845 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20846 }
20847
20848 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20849 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20850
20851 vkDestroyFence(m_device->device(), fence, nullptr);
20852 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20853 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20855
20856 m_errorMonitor->VerifyNotFound();
20857}
20858
20859TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020860 ASSERT_NO_FATAL_FAILURE(InitState());
20861 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020862 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020863 return;
20864 }
20865
20866 VkResult err;
20867
20868 m_errorMonitor->ExpectSuccess();
20869
20870 VkQueue q0 = m_device->m_queue;
20871 VkQueue q1 = nullptr;
20872 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20873 ASSERT_NE(q1, nullptr);
20874
20875 // An (empty) command buffer. We must have work in the first submission --
20876 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020877 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020878 VkCommandPool pool;
20879 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020881 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20882 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020883 VkCommandBuffer cb;
20884 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20885 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020886 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020887 err = vkBeginCommandBuffer(cb, &cbbi);
20888 ASSERT_VK_SUCCESS(err);
20889 err = vkEndCommandBuffer(cb);
20890 ASSERT_VK_SUCCESS(err);
20891
20892 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020893 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020894 VkSemaphore s;
20895 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20896 ASSERT_VK_SUCCESS(err);
20897
20898 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020899 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020900
20901 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20902 ASSERT_VK_SUCCESS(err);
20903
20904 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020905 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020906 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020907
20908 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20909 ASSERT_VK_SUCCESS(err);
20910
20911 // Wait for q0 idle
20912 err = vkQueueWaitIdle(q0);
20913 ASSERT_VK_SUCCESS(err);
20914
20915 // Command buffer should have been completed (it was on q0); reset the pool.
20916 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20917
20918 m_errorMonitor->VerifyNotFound();
20919
20920 // Force device completely idle and clean up resources
20921 vkDeviceWaitIdle(m_device->device());
20922 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20923 vkDestroySemaphore(m_device->device(), s, nullptr);
20924}
20925
20926// This is a positive test. No errors should be generated.
20927TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020928 TEST_DESCRIPTION(
20929 "Two command buffers, each in a separate QueueSubmit call "
20930 "submitted on separate queues, the second having a fence, "
20931 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020932
20933 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020934 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020935
20936 m_errorMonitor->ExpectSuccess();
20937
20938 ASSERT_NO_FATAL_FAILURE(InitState());
20939 VkFence fence;
20940 VkFenceCreateInfo fence_create_info{};
20941 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20942 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20943
20944 VkSemaphore semaphore;
20945 VkSemaphoreCreateInfo semaphore_create_info{};
20946 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20947 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20948
20949 VkCommandPool command_pool;
20950 VkCommandPoolCreateInfo pool_create_info{};
20951 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20952 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20953 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20954 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20955
20956 VkCommandBuffer command_buffer[2];
20957 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20958 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20959 command_buffer_allocate_info.commandPool = command_pool;
20960 command_buffer_allocate_info.commandBufferCount = 2;
20961 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20962 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20963
20964 VkQueue queue = VK_NULL_HANDLE;
20965 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20966
20967 {
20968 VkCommandBufferBeginInfo begin_info{};
20969 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20970 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20971
20972 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 -070020973 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020974
20975 VkViewport viewport{};
20976 viewport.maxDepth = 1.0f;
20977 viewport.minDepth = 0.0f;
20978 viewport.width = 512;
20979 viewport.height = 512;
20980 viewport.x = 0;
20981 viewport.y = 0;
20982 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20983 vkEndCommandBuffer(command_buffer[0]);
20984 }
20985 {
20986 VkCommandBufferBeginInfo begin_info{};
20987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20988 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20989
20990 VkViewport viewport{};
20991 viewport.maxDepth = 1.0f;
20992 viewport.minDepth = 0.0f;
20993 viewport.width = 512;
20994 viewport.height = 512;
20995 viewport.x = 0;
20996 viewport.y = 0;
20997 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20998 vkEndCommandBuffer(command_buffer[1]);
20999 }
21000 {
21001 VkSubmitInfo submit_info{};
21002 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21003 submit_info.commandBufferCount = 1;
21004 submit_info.pCommandBuffers = &command_buffer[0];
21005 submit_info.signalSemaphoreCount = 1;
21006 submit_info.pSignalSemaphores = &semaphore;
21007 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21008 }
21009 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021010 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021011 VkSubmitInfo submit_info{};
21012 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21013 submit_info.commandBufferCount = 1;
21014 submit_info.pCommandBuffers = &command_buffer[1];
21015 submit_info.waitSemaphoreCount = 1;
21016 submit_info.pWaitSemaphores = &semaphore;
21017 submit_info.pWaitDstStageMask = flags;
21018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21019 }
21020
21021 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21022
21023 vkDestroyFence(m_device->device(), fence, nullptr);
21024 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21025 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21026 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21027
21028 m_errorMonitor->VerifyNotFound();
21029}
21030
21031// This is a positive test. No errors should be generated.
21032TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021033 TEST_DESCRIPTION(
21034 "Two command buffers, each in a separate QueueSubmit call "
21035 "on the same queue, sharing a signal/wait semaphore, the "
21036 "second having a fence, "
21037 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021038
21039 m_errorMonitor->ExpectSuccess();
21040
21041 ASSERT_NO_FATAL_FAILURE(InitState());
21042 VkFence fence;
21043 VkFenceCreateInfo fence_create_info{};
21044 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21045 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21046
21047 VkSemaphore semaphore;
21048 VkSemaphoreCreateInfo semaphore_create_info{};
21049 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21050 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21051
21052 VkCommandPool command_pool;
21053 VkCommandPoolCreateInfo pool_create_info{};
21054 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21055 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21056 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21057 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21058
21059 VkCommandBuffer command_buffer[2];
21060 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21061 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21062 command_buffer_allocate_info.commandPool = command_pool;
21063 command_buffer_allocate_info.commandBufferCount = 2;
21064 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21065 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21066
21067 {
21068 VkCommandBufferBeginInfo begin_info{};
21069 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21070 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21071
21072 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 -070021073 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021074
21075 VkViewport viewport{};
21076 viewport.maxDepth = 1.0f;
21077 viewport.minDepth = 0.0f;
21078 viewport.width = 512;
21079 viewport.height = 512;
21080 viewport.x = 0;
21081 viewport.y = 0;
21082 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21083 vkEndCommandBuffer(command_buffer[0]);
21084 }
21085 {
21086 VkCommandBufferBeginInfo begin_info{};
21087 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21088 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21089
21090 VkViewport viewport{};
21091 viewport.maxDepth = 1.0f;
21092 viewport.minDepth = 0.0f;
21093 viewport.width = 512;
21094 viewport.height = 512;
21095 viewport.x = 0;
21096 viewport.y = 0;
21097 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21098 vkEndCommandBuffer(command_buffer[1]);
21099 }
21100 {
21101 VkSubmitInfo submit_info{};
21102 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21103 submit_info.commandBufferCount = 1;
21104 submit_info.pCommandBuffers = &command_buffer[0];
21105 submit_info.signalSemaphoreCount = 1;
21106 submit_info.pSignalSemaphores = &semaphore;
21107 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21108 }
21109 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021110 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021111 VkSubmitInfo submit_info{};
21112 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21113 submit_info.commandBufferCount = 1;
21114 submit_info.pCommandBuffers = &command_buffer[1];
21115 submit_info.waitSemaphoreCount = 1;
21116 submit_info.pWaitSemaphores = &semaphore;
21117 submit_info.pWaitDstStageMask = flags;
21118 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21119 }
21120
21121 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21122
21123 vkDestroyFence(m_device->device(), fence, nullptr);
21124 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21125 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21126 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21127
21128 m_errorMonitor->VerifyNotFound();
21129}
21130
21131// This is a positive test. No errors should be generated.
21132TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021133 TEST_DESCRIPTION(
21134 "Two command buffers, each in a separate QueueSubmit call "
21135 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21136 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021137
21138 m_errorMonitor->ExpectSuccess();
21139
21140 ASSERT_NO_FATAL_FAILURE(InitState());
21141 VkFence fence;
21142 VkFenceCreateInfo fence_create_info{};
21143 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21144 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21145
21146 VkCommandPool command_pool;
21147 VkCommandPoolCreateInfo pool_create_info{};
21148 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21149 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21150 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21151 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21152
21153 VkCommandBuffer command_buffer[2];
21154 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21155 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21156 command_buffer_allocate_info.commandPool = command_pool;
21157 command_buffer_allocate_info.commandBufferCount = 2;
21158 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21159 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21160
21161 {
21162 VkCommandBufferBeginInfo begin_info{};
21163 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21164 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21165
21166 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 -070021167 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021168
21169 VkViewport viewport{};
21170 viewport.maxDepth = 1.0f;
21171 viewport.minDepth = 0.0f;
21172 viewport.width = 512;
21173 viewport.height = 512;
21174 viewport.x = 0;
21175 viewport.y = 0;
21176 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21177 vkEndCommandBuffer(command_buffer[0]);
21178 }
21179 {
21180 VkCommandBufferBeginInfo begin_info{};
21181 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21182 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21183
21184 VkViewport viewport{};
21185 viewport.maxDepth = 1.0f;
21186 viewport.minDepth = 0.0f;
21187 viewport.width = 512;
21188 viewport.height = 512;
21189 viewport.x = 0;
21190 viewport.y = 0;
21191 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21192 vkEndCommandBuffer(command_buffer[1]);
21193 }
21194 {
21195 VkSubmitInfo submit_info{};
21196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21197 submit_info.commandBufferCount = 1;
21198 submit_info.pCommandBuffers = &command_buffer[0];
21199 submit_info.signalSemaphoreCount = 0;
21200 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21201 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21202 }
21203 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021204 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021205 VkSubmitInfo submit_info{};
21206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21207 submit_info.commandBufferCount = 1;
21208 submit_info.pCommandBuffers = &command_buffer[1];
21209 submit_info.waitSemaphoreCount = 0;
21210 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21211 submit_info.pWaitDstStageMask = flags;
21212 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21213 }
21214
21215 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21216
21217 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21218 ASSERT_VK_SUCCESS(err);
21219
21220 vkDestroyFence(m_device->device(), fence, nullptr);
21221 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21222 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21223
21224 m_errorMonitor->VerifyNotFound();
21225}
21226
21227// This is a positive test. No errors should be generated.
21228TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021229 TEST_DESCRIPTION(
21230 "Two command buffers, each in a separate QueueSubmit call "
21231 "on the same queue, the second having a fence, followed "
21232 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021233
21234 m_errorMonitor->ExpectSuccess();
21235
21236 ASSERT_NO_FATAL_FAILURE(InitState());
21237 VkFence fence;
21238 VkFenceCreateInfo fence_create_info{};
21239 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21240 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21241
21242 VkCommandPool command_pool;
21243 VkCommandPoolCreateInfo pool_create_info{};
21244 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21245 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21246 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21247 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21248
21249 VkCommandBuffer command_buffer[2];
21250 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21251 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21252 command_buffer_allocate_info.commandPool = command_pool;
21253 command_buffer_allocate_info.commandBufferCount = 2;
21254 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21255 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21256
21257 {
21258 VkCommandBufferBeginInfo begin_info{};
21259 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21260 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21261
21262 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 -070021263 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021264
21265 VkViewport viewport{};
21266 viewport.maxDepth = 1.0f;
21267 viewport.minDepth = 0.0f;
21268 viewport.width = 512;
21269 viewport.height = 512;
21270 viewport.x = 0;
21271 viewport.y = 0;
21272 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21273 vkEndCommandBuffer(command_buffer[0]);
21274 }
21275 {
21276 VkCommandBufferBeginInfo begin_info{};
21277 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21278 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21279
21280 VkViewport viewport{};
21281 viewport.maxDepth = 1.0f;
21282 viewport.minDepth = 0.0f;
21283 viewport.width = 512;
21284 viewport.height = 512;
21285 viewport.x = 0;
21286 viewport.y = 0;
21287 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21288 vkEndCommandBuffer(command_buffer[1]);
21289 }
21290 {
21291 VkSubmitInfo submit_info{};
21292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21293 submit_info.commandBufferCount = 1;
21294 submit_info.pCommandBuffers = &command_buffer[0];
21295 submit_info.signalSemaphoreCount = 0;
21296 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21297 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21298 }
21299 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021300 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021301 VkSubmitInfo submit_info{};
21302 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21303 submit_info.commandBufferCount = 1;
21304 submit_info.pCommandBuffers = &command_buffer[1];
21305 submit_info.waitSemaphoreCount = 0;
21306 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21307 submit_info.pWaitDstStageMask = flags;
21308 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21309 }
21310
21311 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21312
21313 vkDestroyFence(m_device->device(), fence, nullptr);
21314 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21315 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21316
21317 m_errorMonitor->VerifyNotFound();
21318}
21319
21320// This is a positive test. No errors should be generated.
21321TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021322 TEST_DESCRIPTION(
21323 "Two command buffers each in a separate SubmitInfo sent in a single "
21324 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021325 ASSERT_NO_FATAL_FAILURE(InitState());
21326
21327 m_errorMonitor->ExpectSuccess();
21328
21329 VkFence fence;
21330 VkFenceCreateInfo fence_create_info{};
21331 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21332 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21333
21334 VkSemaphore semaphore;
21335 VkSemaphoreCreateInfo semaphore_create_info{};
21336 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21337 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21338
21339 VkCommandPool command_pool;
21340 VkCommandPoolCreateInfo pool_create_info{};
21341 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21342 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21343 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21344 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21345
21346 VkCommandBuffer command_buffer[2];
21347 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21348 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21349 command_buffer_allocate_info.commandPool = command_pool;
21350 command_buffer_allocate_info.commandBufferCount = 2;
21351 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21352 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21353
21354 {
21355 VkCommandBufferBeginInfo begin_info{};
21356 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21357 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21358
21359 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 -070021360 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021361
21362 VkViewport viewport{};
21363 viewport.maxDepth = 1.0f;
21364 viewport.minDepth = 0.0f;
21365 viewport.width = 512;
21366 viewport.height = 512;
21367 viewport.x = 0;
21368 viewport.y = 0;
21369 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21370 vkEndCommandBuffer(command_buffer[0]);
21371 }
21372 {
21373 VkCommandBufferBeginInfo begin_info{};
21374 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21375 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21376
21377 VkViewport viewport{};
21378 viewport.maxDepth = 1.0f;
21379 viewport.minDepth = 0.0f;
21380 viewport.width = 512;
21381 viewport.height = 512;
21382 viewport.x = 0;
21383 viewport.y = 0;
21384 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21385 vkEndCommandBuffer(command_buffer[1]);
21386 }
21387 {
21388 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021389 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021390
21391 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21392 submit_info[0].pNext = NULL;
21393 submit_info[0].commandBufferCount = 1;
21394 submit_info[0].pCommandBuffers = &command_buffer[0];
21395 submit_info[0].signalSemaphoreCount = 1;
21396 submit_info[0].pSignalSemaphores = &semaphore;
21397 submit_info[0].waitSemaphoreCount = 0;
21398 submit_info[0].pWaitSemaphores = NULL;
21399 submit_info[0].pWaitDstStageMask = 0;
21400
21401 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21402 submit_info[1].pNext = NULL;
21403 submit_info[1].commandBufferCount = 1;
21404 submit_info[1].pCommandBuffers = &command_buffer[1];
21405 submit_info[1].waitSemaphoreCount = 1;
21406 submit_info[1].pWaitSemaphores = &semaphore;
21407 submit_info[1].pWaitDstStageMask = flags;
21408 submit_info[1].signalSemaphoreCount = 0;
21409 submit_info[1].pSignalSemaphores = NULL;
21410 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21411 }
21412
21413 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21414
21415 vkDestroyFence(m_device->device(), fence, nullptr);
21416 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21417 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21418 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21419
21420 m_errorMonitor->VerifyNotFound();
21421}
21422
21423TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21424 m_errorMonitor->ExpectSuccess();
21425
21426 ASSERT_NO_FATAL_FAILURE(InitState());
21427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21428
Tony Barbour552f6c02016-12-21 14:34:07 -070021429 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021430
21431 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21432 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21433 m_errorMonitor->VerifyNotFound();
21434 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21435 m_errorMonitor->VerifyNotFound();
21436 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21437 m_errorMonitor->VerifyNotFound();
21438
21439 m_commandBuffer->EndCommandBuffer();
21440 m_errorMonitor->VerifyNotFound();
21441}
21442
21443TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021444 TEST_DESCRIPTION(
21445 "Positive test where we create a renderpass with an "
21446 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21447 "has a valid layout, and a second subpass then uses a "
21448 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021449 m_errorMonitor->ExpectSuccess();
21450 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021451 auto depth_format = find_depth_stencil_format(m_device);
21452 if (!depth_format) {
21453 printf(" No Depth + Stencil format found. Skipped.\n");
21454 return;
21455 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021456
21457 VkAttachmentReference attach[2] = {};
21458 attach[0].attachment = 0;
21459 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21460 attach[1].attachment = 0;
21461 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21462 VkSubpassDescription subpasses[2] = {};
21463 // First subpass clears DS attach on load
21464 subpasses[0].pDepthStencilAttachment = &attach[0];
21465 // 2nd subpass reads in DS as input attachment
21466 subpasses[1].inputAttachmentCount = 1;
21467 subpasses[1].pInputAttachments = &attach[1];
21468 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021469 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021470 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21471 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21472 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21473 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21474 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21475 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21476 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21477 VkRenderPassCreateInfo rpci = {};
21478 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21479 rpci.attachmentCount = 1;
21480 rpci.pAttachments = &attach_desc;
21481 rpci.subpassCount = 2;
21482 rpci.pSubpasses = subpasses;
21483
21484 // Now create RenderPass and verify no errors
21485 VkRenderPass rp;
21486 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21487 m_errorMonitor->VerifyNotFound();
21488
21489 vkDestroyRenderPass(m_device->device(), rp, NULL);
21490}
21491
Tobin Ehlis01103de2017-02-16 13:22:47 -070021492TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21493 TEST_DESCRIPTION(
21494 "Create a render pass with depth-stencil attachment where layout transition "
21495 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21496 "transition has correctly occurred at queue submit time with no validation errors.");
21497
Tony Barbourf887b162017-03-09 10:06:46 -070021498 ASSERT_NO_FATAL_FAILURE(InitState());
21499 auto depth_format = find_depth_stencil_format(m_device);
21500 if (!depth_format) {
21501 printf(" No Depth + Stencil format found. Skipped.\n");
21502 return;
21503 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021504 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021505 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021506 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21507 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021508 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021509 return;
21510 }
21511
21512 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21514
21515 // A renderpass with one depth/stencil attachment.
21516 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021517 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021518 VK_SAMPLE_COUNT_1_BIT,
21519 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21520 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21521 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21522 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21523 VK_IMAGE_LAYOUT_UNDEFINED,
21524 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21525
21526 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21527
21528 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21529
21530 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21531
21532 VkRenderPass rp;
21533 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21534 ASSERT_VK_SUCCESS(err);
21535 // A compatible ds image.
21536 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021537 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 -070021538 ASSERT_TRUE(image.initialized());
21539
21540 VkImageViewCreateInfo ivci = {
21541 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21542 nullptr,
21543 0,
21544 image.handle(),
21545 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021546 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021547 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21548 VK_COMPONENT_SWIZZLE_IDENTITY},
21549 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21550 };
21551 VkImageView view;
21552 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21553 ASSERT_VK_SUCCESS(err);
21554
21555 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21556 VkFramebuffer fb;
21557 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21558 ASSERT_VK_SUCCESS(err);
21559
21560 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21561 m_commandBuffer->BeginCommandBuffer();
21562 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21563 vkCmdEndRenderPass(m_commandBuffer->handle());
21564 m_commandBuffer->EndCommandBuffer();
21565 QueueCommandBuffer(false);
21566 m_errorMonitor->VerifyNotFound();
21567
21568 // Cleanup
21569 vkDestroyImageView(m_device->device(), view, NULL);
21570 vkDestroyRenderPass(m_device->device(), rp, NULL);
21571 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21572}
21573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021574TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021575 TEST_DESCRIPTION(
21576 "Test that pipeline validation accepts matrices passed "
21577 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021578 m_errorMonitor->ExpectSuccess();
21579
21580 ASSERT_NO_FATAL_FAILURE(InitState());
21581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21582
21583 VkVertexInputBindingDescription input_binding;
21584 memset(&input_binding, 0, sizeof(input_binding));
21585
21586 VkVertexInputAttributeDescription input_attribs[2];
21587 memset(input_attribs, 0, sizeof(input_attribs));
21588
21589 for (int i = 0; i < 2; i++) {
21590 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21591 input_attribs[i].location = i;
21592 }
21593
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021594 char const *vsSource =
21595 "#version 450\n"
21596 "\n"
21597 "layout(location=0) in mat2x4 x;\n"
21598 "out gl_PerVertex {\n"
21599 " vec4 gl_Position;\n"
21600 "};\n"
21601 "void main(){\n"
21602 " gl_Position = x[0] + x[1];\n"
21603 "}\n";
21604 char const *fsSource =
21605 "#version 450\n"
21606 "\n"
21607 "layout(location=0) out vec4 color;\n"
21608 "void main(){\n"
21609 " color = vec4(1);\n"
21610 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021611
21612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21614
21615 VkPipelineObj pipe(m_device);
21616 pipe.AddColorAttachment();
21617 pipe.AddShader(&vs);
21618 pipe.AddShader(&fs);
21619
21620 pipe.AddVertexInputBindings(&input_binding, 1);
21621 pipe.AddVertexInputAttribs(input_attribs, 2);
21622
21623 VkDescriptorSetObj descriptorSet(m_device);
21624 descriptorSet.AppendDummy();
21625 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21626
21627 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21628
21629 /* expect success */
21630 m_errorMonitor->VerifyNotFound();
21631}
21632
21633TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21634 m_errorMonitor->ExpectSuccess();
21635
21636 ASSERT_NO_FATAL_FAILURE(InitState());
21637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21638
21639 VkVertexInputBindingDescription input_binding;
21640 memset(&input_binding, 0, sizeof(input_binding));
21641
21642 VkVertexInputAttributeDescription input_attribs[2];
21643 memset(input_attribs, 0, sizeof(input_attribs));
21644
21645 for (int i = 0; i < 2; i++) {
21646 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21647 input_attribs[i].location = i;
21648 }
21649
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021650 char const *vsSource =
21651 "#version 450\n"
21652 "\n"
21653 "layout(location=0) in vec4 x[2];\n"
21654 "out gl_PerVertex {\n"
21655 " vec4 gl_Position;\n"
21656 "};\n"
21657 "void main(){\n"
21658 " gl_Position = x[0] + x[1];\n"
21659 "}\n";
21660 char const *fsSource =
21661 "#version 450\n"
21662 "\n"
21663 "layout(location=0) out vec4 color;\n"
21664 "void main(){\n"
21665 " color = vec4(1);\n"
21666 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021667
21668 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21669 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21670
21671 VkPipelineObj pipe(m_device);
21672 pipe.AddColorAttachment();
21673 pipe.AddShader(&vs);
21674 pipe.AddShader(&fs);
21675
21676 pipe.AddVertexInputBindings(&input_binding, 1);
21677 pipe.AddVertexInputAttribs(input_attribs, 2);
21678
21679 VkDescriptorSetObj descriptorSet(m_device);
21680 descriptorSet.AppendDummy();
21681 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21682
21683 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21684
21685 m_errorMonitor->VerifyNotFound();
21686}
21687
21688TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021689 TEST_DESCRIPTION(
21690 "Test that pipeline validation accepts consuming a vertex attribute "
21691 "through multiple vertex shader inputs, each consuming a different "
21692 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021693 m_errorMonitor->ExpectSuccess();
21694
21695 ASSERT_NO_FATAL_FAILURE(InitState());
21696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21697
21698 VkVertexInputBindingDescription input_binding;
21699 memset(&input_binding, 0, sizeof(input_binding));
21700
21701 VkVertexInputAttributeDescription input_attribs[3];
21702 memset(input_attribs, 0, sizeof(input_attribs));
21703
21704 for (int i = 0; i < 3; i++) {
21705 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21706 input_attribs[i].location = i;
21707 }
21708
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021709 char const *vsSource =
21710 "#version 450\n"
21711 "\n"
21712 "layout(location=0) in vec4 x;\n"
21713 "layout(location=1) in vec3 y1;\n"
21714 "layout(location=1, component=3) in float y2;\n"
21715 "layout(location=2) in vec4 z;\n"
21716 "out gl_PerVertex {\n"
21717 " vec4 gl_Position;\n"
21718 "};\n"
21719 "void main(){\n"
21720 " gl_Position = x + vec4(y1, y2) + z;\n"
21721 "}\n";
21722 char const *fsSource =
21723 "#version 450\n"
21724 "\n"
21725 "layout(location=0) out vec4 color;\n"
21726 "void main(){\n"
21727 " color = vec4(1);\n"
21728 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021729
21730 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21731 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21732
21733 VkPipelineObj pipe(m_device);
21734 pipe.AddColorAttachment();
21735 pipe.AddShader(&vs);
21736 pipe.AddShader(&fs);
21737
21738 pipe.AddVertexInputBindings(&input_binding, 1);
21739 pipe.AddVertexInputAttribs(input_attribs, 3);
21740
21741 VkDescriptorSetObj descriptorSet(m_device);
21742 descriptorSet.AppendDummy();
21743 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21744
21745 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21746
21747 m_errorMonitor->VerifyNotFound();
21748}
21749
21750TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21751 m_errorMonitor->ExpectSuccess();
21752
21753 ASSERT_NO_FATAL_FAILURE(InitState());
21754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021756 char const *vsSource =
21757 "#version 450\n"
21758 "out gl_PerVertex {\n"
21759 " vec4 gl_Position;\n"
21760 "};\n"
21761 "void main(){\n"
21762 " gl_Position = vec4(0);\n"
21763 "}\n";
21764 char const *fsSource =
21765 "#version 450\n"
21766 "\n"
21767 "layout(location=0) out vec4 color;\n"
21768 "void main(){\n"
21769 " color = vec4(1);\n"
21770 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021771
21772 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21773 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21774
21775 VkPipelineObj pipe(m_device);
21776 pipe.AddColorAttachment();
21777 pipe.AddShader(&vs);
21778 pipe.AddShader(&fs);
21779
21780 VkDescriptorSetObj descriptorSet(m_device);
21781 descriptorSet.AppendDummy();
21782 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21783
21784 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21785
21786 m_errorMonitor->VerifyNotFound();
21787}
21788
21789TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021790 TEST_DESCRIPTION(
21791 "Test that pipeline validation accepts the relaxed type matching rules "
21792 "set out in 14.1.3: fundamental type must match, and producer side must "
21793 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021794 m_errorMonitor->ExpectSuccess();
21795
21796 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21797
21798 ASSERT_NO_FATAL_FAILURE(InitState());
21799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021801 char const *vsSource =
21802 "#version 450\n"
21803 "out gl_PerVertex {\n"
21804 " vec4 gl_Position;\n"
21805 "};\n"
21806 "layout(location=0) out vec3 x;\n"
21807 "layout(location=1) out ivec3 y;\n"
21808 "layout(location=2) out vec3 z;\n"
21809 "void main(){\n"
21810 " gl_Position = vec4(0);\n"
21811 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21812 "}\n";
21813 char const *fsSource =
21814 "#version 450\n"
21815 "\n"
21816 "layout(location=0) out vec4 color;\n"
21817 "layout(location=0) in float x;\n"
21818 "layout(location=1) flat in int y;\n"
21819 "layout(location=2) in vec2 z;\n"
21820 "void main(){\n"
21821 " color = vec4(1 + x + y + z.x);\n"
21822 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021823
21824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21826
21827 VkPipelineObj pipe(m_device);
21828 pipe.AddColorAttachment();
21829 pipe.AddShader(&vs);
21830 pipe.AddShader(&fs);
21831
21832 VkDescriptorSetObj descriptorSet(m_device);
21833 descriptorSet.AppendDummy();
21834 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21835
21836 VkResult err = VK_SUCCESS;
21837 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21838 ASSERT_VK_SUCCESS(err);
21839
21840 m_errorMonitor->VerifyNotFound();
21841}
21842
21843TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021844 TEST_DESCRIPTION(
21845 "Test that pipeline validation accepts per-vertex variables "
21846 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021847 m_errorMonitor->ExpectSuccess();
21848
21849 ASSERT_NO_FATAL_FAILURE(InitState());
21850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21851
21852 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021853 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021854 return;
21855 }
21856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021857 char const *vsSource =
21858 "#version 450\n"
21859 "void main(){}\n";
21860 char const *tcsSource =
21861 "#version 450\n"
21862 "layout(location=0) out int x[];\n"
21863 "layout(vertices=3) out;\n"
21864 "void main(){\n"
21865 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21866 " gl_TessLevelInner[0] = 1;\n"
21867 " x[gl_InvocationID] = gl_InvocationID;\n"
21868 "}\n";
21869 char const *tesSource =
21870 "#version 450\n"
21871 "layout(triangles, equal_spacing, cw) in;\n"
21872 "layout(location=0) in int x[];\n"
21873 "out gl_PerVertex { vec4 gl_Position; };\n"
21874 "void main(){\n"
21875 " gl_Position.xyz = gl_TessCoord;\n"
21876 " gl_Position.w = x[0] + x[1] + x[2];\n"
21877 "}\n";
21878 char const *fsSource =
21879 "#version 450\n"
21880 "layout(location=0) out vec4 color;\n"
21881 "void main(){\n"
21882 " color = vec4(1);\n"
21883 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021884
21885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21886 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21887 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21888 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21889
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021890 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21891 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021892
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021893 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021894
21895 VkPipelineObj pipe(m_device);
21896 pipe.SetInputAssembly(&iasci);
21897 pipe.SetTessellation(&tsci);
21898 pipe.AddColorAttachment();
21899 pipe.AddShader(&vs);
21900 pipe.AddShader(&tcs);
21901 pipe.AddShader(&tes);
21902 pipe.AddShader(&fs);
21903
21904 VkDescriptorSetObj descriptorSet(m_device);
21905 descriptorSet.AppendDummy();
21906 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21907
21908 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21909
21910 m_errorMonitor->VerifyNotFound();
21911}
21912
21913TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021914 TEST_DESCRIPTION(
21915 "Test that pipeline validation accepts a user-defined "
21916 "interface block passed into the geometry shader. This "
21917 "is interesting because the 'extra' array level is not "
21918 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021919 m_errorMonitor->ExpectSuccess();
21920
21921 ASSERT_NO_FATAL_FAILURE(InitState());
21922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21923
21924 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021925 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021926 return;
21927 }
21928
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021929 char const *vsSource =
21930 "#version 450\n"
21931 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21932 "void main(){\n"
21933 " vs_out.x = vec4(1);\n"
21934 "}\n";
21935 char const *gsSource =
21936 "#version 450\n"
21937 "layout(triangles) in;\n"
21938 "layout(triangle_strip, max_vertices=3) out;\n"
21939 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21940 "out gl_PerVertex { vec4 gl_Position; };\n"
21941 "void main() {\n"
21942 " gl_Position = gs_in[0].x;\n"
21943 " EmitVertex();\n"
21944 "}\n";
21945 char const *fsSource =
21946 "#version 450\n"
21947 "layout(location=0) out vec4 color;\n"
21948 "void main(){\n"
21949 " color = vec4(1);\n"
21950 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021951
21952 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21953 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21955
21956 VkPipelineObj pipe(m_device);
21957 pipe.AddColorAttachment();
21958 pipe.AddShader(&vs);
21959 pipe.AddShader(&gs);
21960 pipe.AddShader(&fs);
21961
21962 VkDescriptorSetObj descriptorSet(m_device);
21963 descriptorSet.AppendDummy();
21964 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21965
21966 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21967
21968 m_errorMonitor->VerifyNotFound();
21969}
21970
21971TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021972 TEST_DESCRIPTION(
21973 "Test that pipeline validation accepts basic use of 64bit vertex "
21974 "attributes. This is interesting because they consume multiple "
21975 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021976 m_errorMonitor->ExpectSuccess();
21977
21978 ASSERT_NO_FATAL_FAILURE(InitState());
21979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21980
21981 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021982 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021983 return;
21984 }
21985
21986 VkVertexInputBindingDescription input_bindings[1];
21987 memset(input_bindings, 0, sizeof(input_bindings));
21988
21989 VkVertexInputAttributeDescription input_attribs[4];
21990 memset(input_attribs, 0, sizeof(input_attribs));
21991 input_attribs[0].location = 0;
21992 input_attribs[0].offset = 0;
21993 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21994 input_attribs[1].location = 2;
21995 input_attribs[1].offset = 32;
21996 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21997 input_attribs[2].location = 4;
21998 input_attribs[2].offset = 64;
21999 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22000 input_attribs[3].location = 6;
22001 input_attribs[3].offset = 96;
22002 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022004 char const *vsSource =
22005 "#version 450\n"
22006 "\n"
22007 "layout(location=0) in dmat4 x;\n"
22008 "out gl_PerVertex {\n"
22009 " vec4 gl_Position;\n"
22010 "};\n"
22011 "void main(){\n"
22012 " gl_Position = vec4(x[0][0]);\n"
22013 "}\n";
22014 char const *fsSource =
22015 "#version 450\n"
22016 "\n"
22017 "layout(location=0) out vec4 color;\n"
22018 "void main(){\n"
22019 " color = vec4(1);\n"
22020 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022021
22022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22024
22025 VkPipelineObj pipe(m_device);
22026 pipe.AddColorAttachment();
22027 pipe.AddShader(&vs);
22028 pipe.AddShader(&fs);
22029
22030 pipe.AddVertexInputBindings(input_bindings, 1);
22031 pipe.AddVertexInputAttribs(input_attribs, 4);
22032
22033 VkDescriptorSetObj descriptorSet(m_device);
22034 descriptorSet.AppendDummy();
22035 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22036
22037 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22038
22039 m_errorMonitor->VerifyNotFound();
22040}
22041
22042TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22043 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22044 m_errorMonitor->ExpectSuccess();
22045
22046 ASSERT_NO_FATAL_FAILURE(InitState());
22047
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022048 char const *vsSource =
22049 "#version 450\n"
22050 "\n"
22051 "out gl_PerVertex {\n"
22052 " vec4 gl_Position;\n"
22053 "};\n"
22054 "void main(){\n"
22055 " gl_Position = vec4(1);\n"
22056 "}\n";
22057 char const *fsSource =
22058 "#version 450\n"
22059 "\n"
22060 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22061 "layout(location=0) out vec4 color;\n"
22062 "void main() {\n"
22063 " color = subpassLoad(x);\n"
22064 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022065
22066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22067 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22068
22069 VkPipelineObj pipe(m_device);
22070 pipe.AddShader(&vs);
22071 pipe.AddShader(&fs);
22072 pipe.AddColorAttachment();
22073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22074
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022075 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22076 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022077 VkDescriptorSetLayout dsl;
22078 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22079 ASSERT_VK_SUCCESS(err);
22080
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022081 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022082 VkPipelineLayout pl;
22083 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22084 ASSERT_VK_SUCCESS(err);
22085
22086 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022087 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22088 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22089 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22090 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22091 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 -060022092 };
22093 VkAttachmentReference color = {
22094 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22095 };
22096 VkAttachmentReference input = {
22097 1, VK_IMAGE_LAYOUT_GENERAL,
22098 };
22099
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022100 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022101
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022102 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022103 VkRenderPass rp;
22104 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22105 ASSERT_VK_SUCCESS(err);
22106
22107 // should be OK. would go wrong here if it's going to...
22108 pipe.CreateVKPipeline(pl, rp);
22109
22110 m_errorMonitor->VerifyNotFound();
22111
22112 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22113 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22114 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22115}
22116
22117TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022118 TEST_DESCRIPTION(
22119 "Test that pipeline validation accepts a compute pipeline which declares a "
22120 "descriptor-backed resource which is not provided, but the shader does not "
22121 "statically use it. This is interesting because it requires compute pipelines "
22122 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022123 m_errorMonitor->ExpectSuccess();
22124
22125 ASSERT_NO_FATAL_FAILURE(InitState());
22126
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022127 char const *csSource =
22128 "#version 450\n"
22129 "\n"
22130 "layout(local_size_x=1) in;\n"
22131 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22132 "void main(){\n"
22133 " // x is not used.\n"
22134 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022135
22136 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22137
22138 VkDescriptorSetObj descriptorSet(m_device);
22139 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22140
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022141 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22142 nullptr,
22143 0,
22144 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22145 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22146 descriptorSet.GetPipelineLayout(),
22147 VK_NULL_HANDLE,
22148 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022149
22150 VkPipeline pipe;
22151 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22152
22153 m_errorMonitor->VerifyNotFound();
22154
22155 if (err == VK_SUCCESS) {
22156 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22157 }
22158}
22159
22160TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022161 TEST_DESCRIPTION(
22162 "Test that pipeline validation accepts a shader consuming only the "
22163 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022164 m_errorMonitor->ExpectSuccess();
22165
22166 ASSERT_NO_FATAL_FAILURE(InitState());
22167
22168 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022169 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22170 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22171 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022172 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022173 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022174 VkDescriptorSetLayout dsl;
22175 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22176 ASSERT_VK_SUCCESS(err);
22177
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022178 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022179 VkPipelineLayout pl;
22180 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22181 ASSERT_VK_SUCCESS(err);
22182
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022183 char const *csSource =
22184 "#version 450\n"
22185 "\n"
22186 "layout(local_size_x=1) in;\n"
22187 "layout(set=0, binding=0) uniform sampler s;\n"
22188 "layout(set=0, binding=1) uniform texture2D t;\n"
22189 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22190 "void main() {\n"
22191 " x = texture(sampler2D(t, s), vec2(0));\n"
22192 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022193 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22194
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022195 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22196 nullptr,
22197 0,
22198 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22199 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22200 pl,
22201 VK_NULL_HANDLE,
22202 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022203
22204 VkPipeline pipe;
22205 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22206
22207 m_errorMonitor->VerifyNotFound();
22208
22209 if (err == VK_SUCCESS) {
22210 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22211 }
22212
22213 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22214 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22215}
22216
22217TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022218 TEST_DESCRIPTION(
22219 "Test that pipeline validation accepts a shader consuming only the "
22220 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022221 m_errorMonitor->ExpectSuccess();
22222
22223 ASSERT_NO_FATAL_FAILURE(InitState());
22224
22225 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022226 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22227 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22228 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022229 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022230 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022231 VkDescriptorSetLayout dsl;
22232 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22233 ASSERT_VK_SUCCESS(err);
22234
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022235 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022236 VkPipelineLayout pl;
22237 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22238 ASSERT_VK_SUCCESS(err);
22239
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022240 char const *csSource =
22241 "#version 450\n"
22242 "\n"
22243 "layout(local_size_x=1) in;\n"
22244 "layout(set=0, binding=0) uniform texture2D t;\n"
22245 "layout(set=0, binding=1) uniform sampler s;\n"
22246 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22247 "void main() {\n"
22248 " x = texture(sampler2D(t, s), vec2(0));\n"
22249 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022250 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22251
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022252 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22253 nullptr,
22254 0,
22255 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22256 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22257 pl,
22258 VK_NULL_HANDLE,
22259 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022260
22261 VkPipeline pipe;
22262 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22263
22264 m_errorMonitor->VerifyNotFound();
22265
22266 if (err == VK_SUCCESS) {
22267 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22268 }
22269
22270 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22271 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22272}
22273
22274TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022275 TEST_DESCRIPTION(
22276 "Test that pipeline validation accepts a shader consuming "
22277 "both the sampler and the image of a combined image+sampler "
22278 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022279 m_errorMonitor->ExpectSuccess();
22280
22281 ASSERT_NO_FATAL_FAILURE(InitState());
22282
22283 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022284 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22285 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022286 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022287 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022288 VkDescriptorSetLayout dsl;
22289 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22290 ASSERT_VK_SUCCESS(err);
22291
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022292 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022293 VkPipelineLayout pl;
22294 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22295 ASSERT_VK_SUCCESS(err);
22296
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022297 char const *csSource =
22298 "#version 450\n"
22299 "\n"
22300 "layout(local_size_x=1) in;\n"
22301 "layout(set=0, binding=0) uniform texture2D t;\n"
22302 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22303 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22304 "void main() {\n"
22305 " x = texture(sampler2D(t, s), vec2(0));\n"
22306 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022307 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22308
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022309 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22310 nullptr,
22311 0,
22312 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22313 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22314 pl,
22315 VK_NULL_HANDLE,
22316 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022317
22318 VkPipeline pipe;
22319 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22320
22321 m_errorMonitor->VerifyNotFound();
22322
22323 if (err == VK_SUCCESS) {
22324 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22325 }
22326
22327 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22328 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22329}
22330
22331TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22332 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22333
22334 ASSERT_NO_FATAL_FAILURE(InitState());
22335
22336 // Positive test to check parameter_validation and unique_objects support
22337 // for NV_dedicated_allocation
22338 uint32_t extension_count = 0;
22339 bool supports_nv_dedicated_allocation = false;
22340 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22341 ASSERT_VK_SUCCESS(err);
22342
22343 if (extension_count > 0) {
22344 std::vector<VkExtensionProperties> available_extensions(extension_count);
22345
22346 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22347 ASSERT_VK_SUCCESS(err);
22348
22349 for (const auto &extension_props : available_extensions) {
22350 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22351 supports_nv_dedicated_allocation = true;
22352 }
22353 }
22354 }
22355
22356 if (supports_nv_dedicated_allocation) {
22357 m_errorMonitor->ExpectSuccess();
22358
22359 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22360 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22361 dedicated_buffer_create_info.pNext = nullptr;
22362 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22363
22364 uint32_t queue_family_index = 0;
22365 VkBufferCreateInfo buffer_create_info = {};
22366 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22367 buffer_create_info.pNext = &dedicated_buffer_create_info;
22368 buffer_create_info.size = 1024;
22369 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22370 buffer_create_info.queueFamilyIndexCount = 1;
22371 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22372
22373 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022374 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022375 ASSERT_VK_SUCCESS(err);
22376
22377 VkMemoryRequirements memory_reqs;
22378 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22379
22380 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22381 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22382 dedicated_memory_info.pNext = nullptr;
22383 dedicated_memory_info.buffer = buffer;
22384 dedicated_memory_info.image = VK_NULL_HANDLE;
22385
22386 VkMemoryAllocateInfo memory_info = {};
22387 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22388 memory_info.pNext = &dedicated_memory_info;
22389 memory_info.allocationSize = memory_reqs.size;
22390
22391 bool pass;
22392 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22393 ASSERT_TRUE(pass);
22394
22395 VkDeviceMemory buffer_memory;
22396 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22397 ASSERT_VK_SUCCESS(err);
22398
22399 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22400 ASSERT_VK_SUCCESS(err);
22401
22402 vkDestroyBuffer(m_device->device(), buffer, NULL);
22403 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22404
22405 m_errorMonitor->VerifyNotFound();
22406 }
22407}
22408
22409TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22410 VkResult err;
22411
22412 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22413
22414 ASSERT_NO_FATAL_FAILURE(InitState());
22415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22416
22417 std::vector<const char *> device_extension_names;
22418 auto features = m_device->phy().features();
22419 // Artificially disable support for non-solid fill modes
22420 features.fillModeNonSolid = false;
22421 // The sacrificial device object
22422 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22423
22424 VkRenderpassObj render_pass(&test_device);
22425
22426 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22427 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22428 pipeline_layout_ci.setLayoutCount = 0;
22429 pipeline_layout_ci.pSetLayouts = NULL;
22430
22431 VkPipelineLayout pipeline_layout;
22432 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22433 ASSERT_VK_SUCCESS(err);
22434
22435 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22436 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22437 rs_ci.pNext = nullptr;
22438 rs_ci.lineWidth = 1.0f;
22439 rs_ci.rasterizerDiscardEnable = true;
22440
22441 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22442 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22443
22444 // Set polygonMode=FILL. No error is expected
22445 m_errorMonitor->ExpectSuccess();
22446 {
22447 VkPipelineObj pipe(&test_device);
22448 pipe.AddShader(&vs);
22449 pipe.AddShader(&fs);
22450 pipe.AddColorAttachment();
22451 // Set polygonMode to a good value
22452 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22453 pipe.SetRasterization(&rs_ci);
22454 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22455 }
22456 m_errorMonitor->VerifyNotFound();
22457
22458 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22459}
22460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022461#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022462TEST_F(VkPositiveLayerTest, LongFenceChain)
22463{
22464 m_errorMonitor->ExpectSuccess();
22465
22466 ASSERT_NO_FATAL_FAILURE(InitState());
22467 VkResult err;
22468
22469 std::vector<VkFence> fences;
22470
22471 const int chainLength = 32768;
22472
22473 for (int i = 0; i < chainLength; i++) {
22474 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22475 VkFence fence;
22476 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22477 ASSERT_VK_SUCCESS(err);
22478
22479 fences.push_back(fence);
22480
22481 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22482 0, nullptr, 0, nullptr };
22483 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22484 ASSERT_VK_SUCCESS(err);
22485
22486 }
22487
22488 // BOOM, stack overflow.
22489 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22490
22491 for (auto fence : fences)
22492 vkDestroyFence(m_device->device(), fence, nullptr);
22493
22494 m_errorMonitor->VerifyNotFound();
22495}
22496#endif
22497
Cody Northrop1242dfd2016-07-13 17:24:59 -060022498#if defined(ANDROID) && defined(VALIDATION_APK)
22499static bool initialized = false;
22500static bool active = false;
22501
22502// Convert Intents to argv
22503// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022504std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022505 std::vector<std::string> args;
22506 JavaVM &vm = *app.activity->vm;
22507 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022508 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022509
22510 JNIEnv &env = *p_env;
22511 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022512 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022513 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022514 jmethodID get_string_extra_method =
22515 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022516 jvalue get_string_extra_args;
22517 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022518 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022519
22520 std::string args_str;
22521 if (extra_str) {
22522 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22523 args_str = extra_utf;
22524 env.ReleaseStringUTFChars(extra_str, extra_utf);
22525 env.DeleteLocalRef(extra_str);
22526 }
22527
22528 env.DeleteLocalRef(get_string_extra_args.l);
22529 env.DeleteLocalRef(intent);
22530 vm.DetachCurrentThread();
22531
22532 // split args_str
22533 std::stringstream ss(args_str);
22534 std::string arg;
22535 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022536 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022537 }
22538
22539 return args;
22540}
22541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022542static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022544static void processCommand(struct android_app *app, int32_t cmd) {
22545 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022546 case APP_CMD_INIT_WINDOW: {
22547 if (app->window) {
22548 initialized = true;
22549 }
22550 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022551 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022552 case APP_CMD_GAINED_FOCUS: {
22553 active = true;
22554 break;
22555 }
22556 case APP_CMD_LOST_FOCUS: {
22557 active = false;
22558 break;
22559 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022560 }
22561}
22562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022563void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022564 app_dummy();
22565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022566 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022567
22568 int vulkanSupport = InitVulkan();
22569 if (vulkanSupport == 0) {
22570 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22571 return;
22572 }
22573
22574 app->onAppCmd = processCommand;
22575 app->onInputEvent = processInput;
22576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022577 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022578 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022579 struct android_poll_source *source;
22580 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022581 if (source) {
22582 source->process(app, source);
22583 }
22584
22585 if (app->destroyRequested != 0) {
22586 VkTestFramework::Finish();
22587 return;
22588 }
22589 }
22590
22591 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022592 // Use the following key to send arguments to gtest, i.e.
22593 // --es args "--gtest_filter=-VkLayerTest.foo"
22594 const char key[] = "args";
22595 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022597 std::string filter = "";
22598 if (args.size() > 0) {
22599 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22600 filter += args[0];
22601 } else {
22602 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22603 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022605 int argc = 2;
22606 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22607 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022609 // Route output to files until we can override the gtest output
22610 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22611 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022613 ::testing::InitGoogleTest(&argc, argv);
22614 VkTestFramework::InitArgs(&argc, argv);
22615 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022617 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022619 if (result != 0) {
22620 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22621 } else {
22622 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22623 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022625 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022626
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022627 fclose(stdout);
22628 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022630 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022631 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022632 }
22633 }
22634}
22635#endif
22636
Tony Barbour300a6082015-04-07 13:44:53 -060022637int main(int argc, char **argv) {
22638 int result;
22639
Cody Northrop8e54a402016-03-08 22:25:52 -070022640#ifdef ANDROID
22641 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022642 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022643#endif
22644
Tony Barbour300a6082015-04-07 13:44:53 -060022645 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022646 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022647
22648 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22649
22650 result = RUN_ALL_TESTS();
22651
Tony Barbour6918cd52015-04-09 12:58:51 -060022652 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022653 return result;
22654}