blob: 2e1ca06710d943fbc785eef36ff4824c40fb5bd3 [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
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002587 const int32_t tex_width = 256;
2588 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002609 buffer_create_info.size = 4 * 1024 * 1024;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort Strattonde748202017-02-17 12:50:01 -08002704 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002717 // Leave some extra space for alignment wiggle room
2718 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002719 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002720 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002721 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2722 ASSERT_TRUE(pass);
2723 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2724 ASSERT_TRUE(pass);
2725 VkDeviceMemory image_mem, buffer_mem;
2726 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2727 ASSERT_VK_SUCCESS(err);
2728 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2729 ASSERT_VK_SUCCESS(err);
2730
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Test unaligned memory offset
2732 {
2733 if (image_mem_reqs.alignment > 1) {
2734 VkDeviceSize image_offset = 1;
2735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2736 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2737 (void)err; // This may very well return an error.
2738 m_errorMonitor->VerifyFound();
2739 }
Cort6c7dff72017-01-27 18:34:50 -08002740
Cort Strattonde748202017-02-17 12:50:01 -08002741 if (buffer_mem_reqs.alignment > 1) {
2742 VkDeviceSize buffer_offset = 1;
2743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2744 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2745 (void)err; // This may very well return an error.
2746 m_errorMonitor->VerifyFound();
2747 }
2748 }
2749
2750 // Test memory offsets outside the memory allocation
2751 {
2752 VkDeviceSize image_offset =
2753 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2755 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2756 (void)err; // This may very well return an error.
2757 m_errorMonitor->VerifyFound();
2758
2759 VkDeviceSize buffer_offset =
2760 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2762 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2763 (void)err; // This may very well return an error.
2764 m_errorMonitor->VerifyFound();
2765 }
2766
2767 // Test memory offsets within the memory allocation, but which leave too little memory for
2768 // the resource.
2769 {
2770 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2771 if (image_offset > 0) {
2772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2773 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2774 (void)err; // This may very well return an error.
2775 m_errorMonitor->VerifyFound();
2776 }
2777
2778 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2779 if (buffer_offset > 0) {
2780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2781 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2782 (void)err; // This may very well return an error.
2783 m_errorMonitor->VerifyFound();
2784 }
2785 }
Cort6c7dff72017-01-27 18:34:50 -08002786
2787 vkFreeMemory(device(), image_mem, NULL);
2788 vkFreeMemory(device(), buffer_mem, NULL);
2789 vkDestroyImage(device(), image, NULL);
2790 vkDestroyBuffer(device(), buffer, NULL);
2791 }
2792
Cort Stratton4c38bb52017-01-28 13:33:10 -08002793 // Try to bind memory to an object with an invalid memory type
2794 {
2795 VkImage image = VK_NULL_HANDLE;
2796 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2797 ASSERT_VK_SUCCESS(err);
2798 VkBuffer buffer = VK_NULL_HANDLE;
2799 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2800 ASSERT_VK_SUCCESS(err);
2801 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2802 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2803 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2804 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2805 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2806 image_alloc_info.allocationSize = image_mem_reqs.size;
2807 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2808 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002809 // Create a mask of available memory types *not* supported by these resources,
2810 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002811 VkPhysicalDeviceMemoryProperties memory_properties = {};
2812 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002813 VkDeviceMemory image_mem, buffer_mem;
2814
Cort Stratton4c38bb52017-01-28 13:33:10 -08002815 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002816 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002817 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2818 ASSERT_TRUE(pass);
2819 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2820 ASSERT_VK_SUCCESS(err);
2821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2822 err = vkBindImageMemory(device(), image, image_mem, 0);
2823 (void)err; // This may very well return an error.
2824 m_errorMonitor->VerifyFound();
2825 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002826 }
2827
Cort Stratton4c38bb52017-01-28 13:33:10 -08002828 uint32_t buffer_unsupported_mem_type_bits =
2829 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2836 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 vkDestroyImage(device(), image, NULL);
2843 vkDestroyBuffer(device(), buffer, NULL);
2844 }
2845
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002846 // Try to bind memory to an image created with sparse memory flags
2847 {
2848 VkImageCreateInfo sparse_image_create_info = image_create_info;
2849 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 VkImageFormatProperties image_format_properties = {};
2851 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2852 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2853 sparse_image_create_info.usage, sparse_image_create_info.flags,
2854 &image_format_properties);
2855 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2856 // most likely means sparse formats aren't supported here; skip this test.
2857 } else {
2858 ASSERT_VK_SUCCESS(err);
2859 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002860 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002861 return;
2862 } else {
2863 VkImage sparse_image = VK_NULL_HANDLE;
2864 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2865 ASSERT_VK_SUCCESS(err);
2866 VkMemoryRequirements sparse_mem_reqs = {};
2867 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2868 if (sparse_mem_reqs.memoryTypeBits != 0) {
2869 VkMemoryAllocateInfo sparse_mem_alloc = {};
2870 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2871 sparse_mem_alloc.pNext = NULL;
2872 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2873 sparse_mem_alloc.memoryTypeIndex = 0;
2874 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2875 ASSERT_TRUE(pass);
2876 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2877 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2878 ASSERT_VK_SUCCESS(err);
2879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2880 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2881 // This may very well return an error.
2882 (void)err;
2883 m_errorMonitor->VerifyFound();
2884 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2885 }
2886 vkDestroyImage(m_device->device(), sparse_image, NULL);
2887 }
2888 }
2889 }
2890
2891 // Try to bind memory to a buffer created with sparse memory flags
2892 {
2893 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2894 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2895 if (!m_device->phy().features().sparseResidencyBuffer) {
2896 // most likely means sparse formats aren't supported here; skip this test.
2897 } else {
2898 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2899 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2900 ASSERT_VK_SUCCESS(err);
2901 VkMemoryRequirements sparse_mem_reqs = {};
2902 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2903 if (sparse_mem_reqs.memoryTypeBits != 0) {
2904 VkMemoryAllocateInfo sparse_mem_alloc = {};
2905 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2906 sparse_mem_alloc.pNext = NULL;
2907 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2908 sparse_mem_alloc.memoryTypeIndex = 0;
2909 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2910 ASSERT_TRUE(pass);
2911 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2912 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2913 ASSERT_VK_SUCCESS(err);
2914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2915 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2916 // This may very well return an error.
2917 (void)err;
2918 m_errorMonitor->VerifyFound();
2919 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2920 }
2921 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2922 }
2923 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002924}
2925
Karl Schultz6addd812016-02-02 17:17:23 -07002926TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2927 VkResult err;
2928 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002929
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002931
Tobin Ehlisec598302015-09-15 15:02:17 -06002932 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002933
Karl Schultz6addd812016-02-02 17:17:23 -07002934 // Create an image object, allocate memory, destroy the object and then try
2935 // to bind it
2936 VkImage image;
2937 VkDeviceMemory mem;
2938 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002939
Karl Schultz6addd812016-02-02 17:17:23 -07002940 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2941 const int32_t tex_width = 32;
2942 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
2944 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2946 image_create_info.pNext = NULL;
2947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2948 image_create_info.format = tex_format;
2949 image_create_info.extent.width = tex_width;
2950 image_create_info.extent.height = tex_height;
2951 image_create_info.extent.depth = 1;
2952 image_create_info.mipLevels = 1;
2953 image_create_info.arrayLayers = 1;
2954 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2955 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2956 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2957 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002958
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002959 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002960 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2961 mem_alloc.pNext = NULL;
2962 mem_alloc.allocationSize = 0;
2963 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002964
Chia-I Wuf7458c52015-10-26 21:10:41 +08002965 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002966 ASSERT_VK_SUCCESS(err);
2967
Karl Schultz6addd812016-02-02 17:17:23 -07002968 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002969
2970 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002972 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002975 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002976 ASSERT_VK_SUCCESS(err);
2977
2978 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 // Now Try to bind memory to this destroyed object
2983 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2984 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002985 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002987 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002988
Chia-I Wuf7458c52015-10-26 21:10:41 +08002989 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002990}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002991
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002992TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2993 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2994
2995 ASSERT_NO_FATAL_FAILURE(InitState());
2996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2997
2998 VkVertexInputBindingDescription input_binding;
2999 memset(&input_binding, 0, sizeof(input_binding));
3000
3001 VkVertexInputAttributeDescription input_attribs;
3002 memset(&input_attribs, 0, sizeof(input_attribs));
3003
3004 // Pick a really bad format for this purpose and make sure it should fail
3005 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3006 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3007 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003008 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003009 return;
3010 }
3011
3012 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003013 char const *vsSource =
3014 "#version 450\n"
3015 "\n"
3016 "out gl_PerVertex {\n"
3017 " vec4 gl_Position;\n"
3018 "};\n"
3019 "void main(){\n"
3020 " gl_Position = vec4(1);\n"
3021 "}\n";
3022 char const *fsSource =
3023 "#version 450\n"
3024 "\n"
3025 "layout(location=0) out vec4 color;\n"
3026 "void main(){\n"
3027 " color = vec4(1);\n"
3028 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003029
3030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3033
3034 VkPipelineObj pipe(m_device);
3035 pipe.AddColorAttachment();
3036 pipe.AddShader(&vs);
3037 pipe.AddShader(&fs);
3038
3039 pipe.AddVertexInputBindings(&input_binding, 1);
3040 pipe.AddVertexInputAttribs(&input_attribs, 1);
3041
3042 VkDescriptorSetObj descriptorSet(m_device);
3043 descriptorSet.AppendDummy();
3044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3045
3046 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3047
3048 m_errorMonitor->VerifyFound();
3049}
3050
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003051TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003052 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3053 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003054
3055 VkMemoryPropertyFlags reqs = 0;
3056 VkImageCreateInfo image_create_info = {};
3057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3058 image_create_info.pNext = NULL;
3059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3061 image_create_info.extent.width = 256;
3062 image_create_info.extent.height = 256;
3063 image_create_info.extent.depth = 1;
3064 image_create_info.mipLevels = 1;
3065 image_create_info.arrayLayers = 1;
3066 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3067 image_create_info.flags = 0;
3068
3069 VkImageBlit blit_region = {};
3070 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3071 blit_region.srcSubresource.baseArrayLayer = 0;
3072 blit_region.srcSubresource.layerCount = 1;
3073 blit_region.srcSubresource.mipLevel = 0;
3074 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3075 blit_region.dstSubresource.baseArrayLayer = 0;
3076 blit_region.dstSubresource.layerCount = 1;
3077 blit_region.dstSubresource.mipLevel = 0;
3078
3079 // Create two images, the source with sampleCount = 2, and attempt to blit
3080 // between them
3081 {
3082 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003084 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003086 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003088 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003090 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003091 m_errorMonitor->SetDesiredFailureMsg(
3092 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3093 "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 -06003094 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3095 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003096 m_errorMonitor->VerifyFound();
3097 m_commandBuffer->EndCommandBuffer();
3098 }
3099
3100 // Create two images, the dest with sampleCount = 4, and attempt to blit
3101 // between them
3102 {
3103 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003105 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003112 m_errorMonitor->SetDesiredFailureMsg(
3113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "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 -06003115 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3116 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003117 m_errorMonitor->VerifyFound();
3118 m_commandBuffer->EndCommandBuffer();
3119 }
3120
3121 VkBufferImageCopy copy_region = {};
3122 copy_region.bufferRowLength = 128;
3123 copy_region.bufferImageHeight = 128;
3124 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3125 copy_region.imageSubresource.layerCount = 1;
3126 copy_region.imageExtent.height = 64;
3127 copy_region.imageExtent.width = 64;
3128 copy_region.imageExtent.depth = 1;
3129
3130 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3131 // buffer to image
3132 {
3133 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003134 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3135 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003139 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003140 m_errorMonitor->SetDesiredFailureMsg(
3141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3142 "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 -06003143 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3144 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003145 m_errorMonitor->VerifyFound();
3146 m_commandBuffer->EndCommandBuffer();
3147 }
3148
3149 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3150 // image to buffer
3151 {
3152 vk_testing::Buffer dst_buffer;
3153 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3154 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003156 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003158 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003159 m_errorMonitor->SetDesiredFailureMsg(
3160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3161 "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 -06003162 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003163 dst_buffer.handle(), 1, &copy_region);
3164 m_errorMonitor->VerifyFound();
3165 m_commandBuffer->EndCommandBuffer();
3166 }
3167}
3168
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003169TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003170 ASSERT_NO_FATAL_FAILURE(InitState());
3171
3172 VkImageObj src_image(m_device);
3173 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3174 VkImageObj dst_image(m_device);
3175 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3176 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003177 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 -06003178
3179 VkImageBlit blitRegion = {};
3180 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3181 blitRegion.srcSubresource.baseArrayLayer = 0;
3182 blitRegion.srcSubresource.layerCount = 1;
3183 blitRegion.srcSubresource.mipLevel = 0;
3184 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3185 blitRegion.dstSubresource.baseArrayLayer = 0;
3186 blitRegion.dstSubresource.layerCount = 1;
3187 blitRegion.dstSubresource.mipLevel = 0;
3188
Dave Houlton34df4cb2016-12-01 16:43:06 -07003189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3190
3191 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3192 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003193
3194 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003195 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3197 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003198
3199 m_errorMonitor->VerifyFound();
3200
Dave Houlton34df4cb2016-12-01 16:43:06 -07003201 // Test should generate 2 VU failures
3202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003204
3205 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003206 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3207 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
Dave Houlton34df4cb2016-12-01 16:43:06 -07003209 // TODO: Note that this only verifies that at least one of the VU enums was found
3210 // 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 -06003211 m_errorMonitor->VerifyFound();
3212
Tony Barbour552f6c02016-12-21 14:34:07 -07003213 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003214}
3215
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003216TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3217 VkResult err;
3218 bool pass;
3219
3220 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3221 ASSERT_NO_FATAL_FAILURE(InitState());
3222
3223 // If w/d/h granularity is 1, test is not meaningful
3224 // TODO: When virtual device limits are available, create a set of limits for this test that
3225 // will always have a granularity of > 1 for w, h, and d
3226 auto index = m_device->graphics_queue_node_index_;
3227 auto queue_family_properties = m_device->phy().queue_properties();
3228
3229 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3230 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3231 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3232 return;
3233 }
3234
3235 // Create two images of different types and try to copy between them
3236 VkImage srcImage;
3237 VkImage dstImage;
3238 VkDeviceMemory srcMem;
3239 VkDeviceMemory destMem;
3240 VkMemoryRequirements memReqs;
3241
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003242 VkImageCreateInfo image_create_info = {};
3243 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3244 image_create_info.pNext = NULL;
3245 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3246 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3247 image_create_info.extent.width = 32;
3248 image_create_info.extent.height = 32;
3249 image_create_info.extent.depth = 1;
3250 image_create_info.mipLevels = 1;
3251 image_create_info.arrayLayers = 4;
3252 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3253 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3254 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3255 image_create_info.flags = 0;
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003258 ASSERT_VK_SUCCESS(err);
3259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003260 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003261 ASSERT_VK_SUCCESS(err);
3262
3263 // Allocate memory
3264 VkMemoryAllocateInfo memAlloc = {};
3265 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3266 memAlloc.pNext = NULL;
3267 memAlloc.allocationSize = 0;
3268 memAlloc.memoryTypeIndex = 0;
3269
3270 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3271 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003273 ASSERT_TRUE(pass);
3274 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3275 ASSERT_VK_SUCCESS(err);
3276
3277 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3278 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 ASSERT_VK_SUCCESS(err);
3281 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3282 ASSERT_VK_SUCCESS(err);
3283
3284 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3285 ASSERT_VK_SUCCESS(err);
3286 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3287 ASSERT_VK_SUCCESS(err);
3288
Tony Barbour552f6c02016-12-21 14:34:07 -07003289 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003290 VkImageCopy copyRegion;
3291 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3292 copyRegion.srcSubresource.mipLevel = 0;
3293 copyRegion.srcSubresource.baseArrayLayer = 0;
3294 copyRegion.srcSubresource.layerCount = 1;
3295 copyRegion.srcOffset.x = 0;
3296 copyRegion.srcOffset.y = 0;
3297 copyRegion.srcOffset.z = 0;
3298 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3299 copyRegion.dstSubresource.mipLevel = 0;
3300 copyRegion.dstSubresource.baseArrayLayer = 0;
3301 copyRegion.dstSubresource.layerCount = 1;
3302 copyRegion.dstOffset.x = 0;
3303 copyRegion.dstOffset.y = 0;
3304 copyRegion.dstOffset.z = 0;
3305 copyRegion.extent.width = 1;
3306 copyRegion.extent.height = 1;
3307 copyRegion.extent.depth = 1;
3308
3309 // Introduce failure by setting srcOffset to a bad granularity value
3310 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3312 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003313 m_errorMonitor->VerifyFound();
3314
3315 // Introduce failure by setting extent to a bad granularity value
3316 copyRegion.srcOffset.y = 0;
3317 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3319 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003320 m_errorMonitor->VerifyFound();
3321
3322 // Now do some buffer/image copies
3323 vk_testing::Buffer buffer;
3324 VkMemoryPropertyFlags reqs = 0;
3325 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3326 VkBufferImageCopy region = {};
3327 region.bufferOffset = 0;
3328 region.bufferRowLength = 3;
3329 region.bufferImageHeight = 128;
3330 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3331 region.imageSubresource.layerCount = 1;
3332 region.imageExtent.height = 16;
3333 region.imageExtent.width = 16;
3334 region.imageExtent.depth = 1;
3335 region.imageOffset.x = 0;
3336 region.imageOffset.y = 0;
3337 region.imageOffset.z = 0;
3338
3339 // Introduce failure by setting bufferRowLength to a bad granularity value
3340 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3342 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3343 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003344 m_errorMonitor->VerifyFound();
3345 region.bufferRowLength = 128;
3346
3347 // Introduce failure by setting bufferOffset to a bad granularity value
3348 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3350 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3351 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003352 m_errorMonitor->VerifyFound();
3353 region.bufferOffset = 0;
3354
3355 // Introduce failure by setting bufferImageHeight to a bad granularity value
3356 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3359 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003360 m_errorMonitor->VerifyFound();
3361 region.bufferImageHeight = 128;
3362
3363 // Introduce failure by setting imageExtent to a bad granularity value
3364 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3366 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3367 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003368 m_errorMonitor->VerifyFound();
3369 region.imageExtent.width = 16;
3370
3371 // Introduce failure by setting imageOffset to a bad granularity value
3372 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3374 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3375 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003376 m_errorMonitor->VerifyFound();
3377
Tony Barbour552f6c02016-12-21 14:34:07 -07003378 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003379
3380 vkDestroyImage(m_device->device(), srcImage, NULL);
3381 vkDestroyImage(m_device->device(), dstImage, NULL);
3382 vkFreeMemory(m_device->device(), srcMem, NULL);
3383 vkFreeMemory(m_device->device(), destMem, NULL);
3384}
3385
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003386TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003387 TEST_DESCRIPTION(
3388 "Submit command buffer created using one queue family and "
3389 "attempt to submit them on a queue created in a different "
3390 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003391
Cody Northropc31a84f2016-08-22 10:41:47 -06003392 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003393
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003394 // This test is meaningless unless we have multiple queue families
3395 auto queue_family_properties = m_device->phy().queue_properties();
3396 if (queue_family_properties.size() < 2) {
3397 return;
3398 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400 // Get safe index of another queue family
3401 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3402 ASSERT_NO_FATAL_FAILURE(InitState());
3403 // Create a second queue using a different queue family
3404 VkQueue other_queue;
3405 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3406
3407 // Record an empty cmd buffer
3408 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3409 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3410 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3411 vkEndCommandBuffer(m_commandBuffer->handle());
3412
3413 // And submit on the wrong queue
3414 VkSubmitInfo submit_info = {};
3415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3416 submit_info.commandBufferCount = 1;
3417 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003418 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003419
3420 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003421}
3422
Chris Forbes4c24a922016-11-16 08:59:10 +13003423TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3424 ASSERT_NO_FATAL_FAILURE(InitState());
3425
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003426 // There are no attachments, but refer to attachment 0.
3427 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003428 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003429 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003430 };
3431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003432 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003433 VkRenderPass rp;
3434
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003435 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003437 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3438 m_errorMonitor->VerifyFound();
3439}
3440
Chris Forbesa58c4522016-09-28 15:19:39 +13003441TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3442 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3443 ASSERT_NO_FATAL_FAILURE(InitState());
3444
3445 // A renderpass with two subpasses, both writing the same attachment.
3446 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003447 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3448 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3449 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003450 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003452 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3454 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003455 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003456 VkSubpassDependency dep = {0,
3457 1,
3458 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3459 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3460 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3461 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3462 VK_DEPENDENCY_BY_REGION_BIT};
3463 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 VkRenderPass rp;
3465 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3466 ASSERT_VK_SUCCESS(err);
3467
3468 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003469 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 +13003470 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3471
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003472 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003473 VkFramebuffer fb;
3474 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3475 ASSERT_VK_SUCCESS(err);
3476
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003477 char const *vsSource =
3478 "#version 450\n"
3479 "void main() { gl_Position = vec4(1); }\n";
3480 char const *fsSource =
3481 "#version 450\n"
3482 "layout(location=0) out vec4 color;\n"
3483 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003484
3485 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3486 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3487 VkPipelineObj pipe(m_device);
3488 pipe.AddColorAttachment();
3489 pipe.AddShader(&vs);
3490 pipe.AddShader(&fs);
3491 VkViewport view_port = {};
3492 m_viewports.push_back(view_port);
3493 pipe.SetViewport(m_viewports);
3494 VkRect2D rect = {};
3495 m_scissors.push_back(rect);
3496 pipe.SetScissor(m_scissors);
3497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003498 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003499 VkPipelineLayout pl;
3500 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3501 ASSERT_VK_SUCCESS(err);
3502 pipe.CreateVKPipeline(pl, rp);
3503
Tony Barbour552f6c02016-12-21 14:34:07 -07003504 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003505
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003506 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3507 nullptr,
3508 rp,
3509 fb,
3510 {{
3511 0, 0,
3512 },
3513 {32, 32}},
3514 0,
3515 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003516
3517 // subtest 1: bind in the wrong subpass
3518 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3519 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 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 +13003521 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3522 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3523 m_errorMonitor->VerifyFound();
3524
3525 vkCmdEndRenderPass(m_commandBuffer->handle());
3526
3527 // subtest 2: bind in correct subpass, then transition to next subpass
3528 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3529 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3530 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003531 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 +13003532 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3533 m_errorMonitor->VerifyFound();
3534
3535 vkCmdEndRenderPass(m_commandBuffer->handle());
3536
Tony Barbour552f6c02016-12-21 14:34:07 -07003537 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003538
3539 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3540 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3541 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3542}
3543
Tony Barbour4e919972016-08-09 13:27:40 -06003544TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003545 TEST_DESCRIPTION(
3546 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3547 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
3549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3550
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3552 "Cannot execute a render pass with renderArea "
3553 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003554
3555 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3556 m_renderPassBeginInfo.renderArea.extent.width = 257;
3557 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003558 m_commandBuffer->BeginCommandBuffer();
3559 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003560 m_errorMonitor->VerifyFound();
3561}
3562
3563TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003564 TEST_DESCRIPTION(
3565 "Generate INDEPENDENT_BLEND by disabling independent "
3566 "blend and then specifying different blend states for two "
3567 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003568 VkPhysicalDeviceFeatures features = {};
3569 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003570 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3573 "Invalid Pipeline CreateInfo: If independent blend feature not "
3574 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 VkDescriptorSetObj descriptorSet(m_device);
3577 descriptorSet.AppendDummy();
3578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003579
Cody Northropc31a84f2016-08-22 10:41:47 -06003580 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003581 // Create a renderPass with two color attachments
3582 VkAttachmentReference attachments[2] = {};
3583 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3584 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3585
3586 VkSubpassDescription subpass = {};
3587 subpass.pColorAttachments = attachments;
3588 subpass.colorAttachmentCount = 2;
3589
3590 VkRenderPassCreateInfo rpci = {};
3591 rpci.subpassCount = 1;
3592 rpci.pSubpasses = &subpass;
3593 rpci.attachmentCount = 1;
3594
3595 VkAttachmentDescription attach_desc = {};
3596 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3597 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3598 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3599 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 rpci.pAttachments = &attach_desc;
3602 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3603
3604 VkRenderPass renderpass;
3605 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003607 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003608
Cody Northropc31a84f2016-08-22 10:41:47 -06003609 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3610 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3611 att_state1.blendEnable = VK_TRUE;
3612 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3613 att_state2.blendEnable = VK_FALSE;
3614 pipeline.AddColorAttachment(0, &att_state1);
3615 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003616 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003617 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003618 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003619}
3620
Mike Weiblen40b160e2017-02-06 19:21:52 -07003621// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3622TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3623 TEST_DESCRIPTION(
3624 "Create a graphics pipeline that is incompatible with the requirements "
3625 "of its contained Renderpass/subpasses.");
3626 ASSERT_NO_FATAL_FAILURE(InitState());
3627
3628 VkDescriptorSetObj ds_obj(m_device);
3629 ds_obj.AppendDummy();
3630 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3631
3632 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3633
3634 VkPipelineColorBlendAttachmentState att_state1 = {};
3635 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3636 att_state1.blendEnable = VK_TRUE;
3637
3638 VkRenderpassObj rp_obj(m_device);
3639
3640 {
3641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3642 VkPipelineObj pipeline(m_device);
3643 pipeline.AddShader(&vs_obj);
3644 pipeline.AddColorAttachment(0, &att_state1);
3645
3646 VkGraphicsPipelineCreateInfo info = {};
3647 pipeline.InitGraphicsPipelineCreateInfo(&info);
3648 info.pColorBlendState = nullptr;
3649
3650 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3651 m_errorMonitor->VerifyFound();
3652 }
3653}
3654
Chris Forbes26ec2122016-11-29 08:58:33 +13003655#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003656TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3657 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3658 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003659 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3662 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003663
3664 // Create a renderPass with a single color attachment
3665 VkAttachmentReference attach = {};
3666 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3667 VkSubpassDescription subpass = {};
3668 VkRenderPassCreateInfo rpci = {};
3669 rpci.subpassCount = 1;
3670 rpci.pSubpasses = &subpass;
3671 rpci.attachmentCount = 1;
3672 VkAttachmentDescription attach_desc = {};
3673 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3675 rpci.pAttachments = &attach_desc;
3676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3677 VkRenderPass rp;
3678 subpass.pDepthStencilAttachment = &attach;
3679 subpass.pColorAttachments = NULL;
3680 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3681 m_errorMonitor->VerifyFound();
3682}
Chris Forbes26ec2122016-11-29 08:58:33 +13003683#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003684
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003685TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003686 TEST_DESCRIPTION(
3687 "Create a framebuffer where a subpass has a preserve "
3688 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003689
3690 ASSERT_NO_FATAL_FAILURE(InitState());
3691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694
3695 VkAttachmentReference color_attach = {};
3696 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3697 color_attach.attachment = 0;
3698 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3699 VkSubpassDescription subpass = {};
3700 subpass.colorAttachmentCount = 1;
3701 subpass.pColorAttachments = &color_attach;
3702 subpass.preserveAttachmentCount = 1;
3703 subpass.pPreserveAttachments = &preserve_attachment;
3704
3705 VkRenderPassCreateInfo rpci = {};
3706 rpci.subpassCount = 1;
3707 rpci.pSubpasses = &subpass;
3708 rpci.attachmentCount = 1;
3709 VkAttachmentDescription attach_desc = {};
3710 attach_desc.format = VK_FORMAT_UNDEFINED;
3711 rpci.pAttachments = &attach_desc;
3712 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3713 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003714 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003715
3716 m_errorMonitor->VerifyFound();
3717
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003718 if (result == VK_SUCCESS) {
3719 vkDestroyRenderPass(m_device->device(), rp, NULL);
3720 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003721}
3722
Chris Forbesc5389742016-06-29 11:49:23 +12003723TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003724 TEST_DESCRIPTION(
3725 "Ensure that CreateRenderPass produces a validation error "
3726 "when the source of a subpass multisample resolve "
3727 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003728
Chris Forbesc5389742016-06-29 11:49:23 +12003729 ASSERT_NO_FATAL_FAILURE(InitState());
3730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3732 "Subpass 0 requests multisample resolve from attachment 0 which has "
3733 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003734
3735 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003736 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3737 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3739 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3740 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3741 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003742 };
3743
3744 VkAttachmentReference color = {
3745 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3746 };
3747
3748 VkAttachmentReference resolve = {
3749 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 };
3751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003752 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003754 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003755
3756 VkRenderPass rp;
3757 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3758
3759 m_errorMonitor->VerifyFound();
3760
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003761 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003762}
3763
3764TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003765 TEST_DESCRIPTION(
3766 "Ensure CreateRenderPass produces a validation error "
3767 "when a subpass multisample resolve operation is "
3768 "requested, and the destination of that resolve has "
3769 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003770
Chris Forbesc5389742016-06-29 11:49:23 +12003771 ASSERT_NO_FATAL_FAILURE(InitState());
3772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3774 "Subpass 0 requests multisample resolve into attachment 1, which "
3775 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003776
3777 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3779 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3780 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3781 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3782 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3783 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003784 };
3785
3786 VkAttachmentReference color = {
3787 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3788 };
3789
3790 VkAttachmentReference resolve = {
3791 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3792 };
3793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003796 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003797
3798 VkRenderPass rp;
3799 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3800
3801 m_errorMonitor->VerifyFound();
3802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003803 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003804}
3805
Chris Forbes3f128ef2016-06-29 14:58:53 +12003806TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003807 TEST_DESCRIPTION(
3808 "Ensure CreateRenderPass produces a validation error "
3809 "when the color and depth attachments used by a subpass "
3810 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003811
Chris Forbes3f128ef2016-06-29 14:58:53 +12003812 ASSERT_NO_FATAL_FAILURE(InitState());
3813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3815 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003816
3817 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003818 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3819 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3820 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3821 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3822 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3823 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003824 };
3825
3826 VkAttachmentReference color[] = {
3827 {
3828 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3829 },
3830 {
3831 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3832 },
3833 };
3834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003835 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003838
3839 VkRenderPass rp;
3840 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3841
3842 m_errorMonitor->VerifyFound();
3843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003844 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003845}
3846
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003847TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003848 TEST_DESCRIPTION(
3849 "Hit errors when attempting to create a framebuffer :\n"
3850 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3851 " 2. Use a color image as depthStencil attachment\n"
3852 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3853 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3854 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3855 " 6. Framebuffer attachment where dimensions don't match\n"
3856 " 7. Framebuffer attachment w/o identity swizzle\n"
3857 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003858
3859 ASSERT_NO_FATAL_FAILURE(InitState());
3860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3861
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003862 m_errorMonitor->SetDesiredFailureMsg(
3863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3864 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003867 VkAttachmentReference attach = {};
3868 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3869 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003870 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003871 VkRenderPassCreateInfo rpci = {};
3872 rpci.subpassCount = 1;
3873 rpci.pSubpasses = &subpass;
3874 rpci.attachmentCount = 1;
3875 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003876 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003877 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003878 rpci.pAttachments = &attach_desc;
3879 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3880 VkRenderPass rp;
3881 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3882 ASSERT_VK_SUCCESS(err);
3883
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003884 VkImageView ivs[2];
3885 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3886 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003887 VkFramebufferCreateInfo fb_info = {};
3888 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3889 fb_info.pNext = NULL;
3890 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003891 // Set mis-matching attachmentCount
3892 fb_info.attachmentCount = 2;
3893 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003894 fb_info.width = 100;
3895 fb_info.height = 100;
3896 fb_info.layers = 1;
3897
3898 VkFramebuffer fb;
3899 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3900
3901 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003902 if (err == VK_SUCCESS) {
3903 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3904 }
3905 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003906
3907 // Create a renderPass with a depth-stencil attachment created with
3908 // IMAGE_USAGE_COLOR_ATTACHMENT
3909 // Add our color attachment to pDepthStencilAttachment
3910 subpass.pDepthStencilAttachment = &attach;
3911 subpass.pColorAttachments = NULL;
3912 VkRenderPass rp_ds;
3913 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3914 ASSERT_VK_SUCCESS(err);
3915 // Set correct attachment count, but attachment has COLOR usage bit set
3916 fb_info.attachmentCount = 1;
3917 fb_info.renderPass = rp_ds;
3918
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003920 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3921
3922 m_errorMonitor->VerifyFound();
3923 if (err == VK_SUCCESS) {
3924 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3925 }
3926 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003927
3928 // Create new renderpass with alternate attachment format from fb
3929 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3930 subpass.pDepthStencilAttachment = NULL;
3931 subpass.pColorAttachments = &attach;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3933 ASSERT_VK_SUCCESS(err);
3934
3935 // Cause error due to mis-matched formats between rp & fb
3936 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3937 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3939 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003940 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3941
3942 m_errorMonitor->VerifyFound();
3943 if (err == VK_SUCCESS) {
3944 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3945 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003946 vkDestroyRenderPass(m_device->device(), rp, NULL);
3947
3948 // Create new renderpass with alternate sample count from fb
3949 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3950 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched sample count between rp & fb
3955 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003957 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003958 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3959
3960 m_errorMonitor->VerifyFound();
3961 if (err == VK_SUCCESS) {
3962 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3963 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003964
3965 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003966
3967 // Create a custom imageView with non-1 mip levels
3968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003969 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 -06003970 ASSERT_TRUE(image.initialized());
3971
3972 VkImageView view;
3973 VkImageViewCreateInfo ivci = {};
3974 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3975 ivci.image = image.handle();
3976 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3977 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3978 ivci.subresourceRange.layerCount = 1;
3979 ivci.subresourceRange.baseMipLevel = 0;
3980 // Set level count 2 (only 1 is allowed for FB attachment)
3981 ivci.subresourceRange.levelCount = 2;
3982 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3983 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3984 ASSERT_VK_SUCCESS(err);
3985 // Re-create renderpass to have matching sample count
3986 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3987 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3988 ASSERT_VK_SUCCESS(err);
3989
3990 fb_info.renderPass = rp;
3991 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003993 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3994
3995 m_errorMonitor->VerifyFound();
3996 if (err == VK_SUCCESS) {
3997 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3998 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003999 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004000 // Update view to original color buffer and grow FB dimensions too big
4001 fb_info.pAttachments = ivs;
4002 fb_info.height = 1024;
4003 fb_info.width = 1024;
4004 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004006 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4007
4008 m_errorMonitor->VerifyFound();
4009 if (err == VK_SUCCESS) {
4010 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4011 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004012 // Create view attachment with non-identity swizzle
4013 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4014 ivci.image = image.handle();
4015 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4016 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4017 ivci.subresourceRange.layerCount = 1;
4018 ivci.subresourceRange.baseMipLevel = 0;
4019 ivci.subresourceRange.levelCount = 1;
4020 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4021 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4022 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4023 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4024 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4025 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 fb_info.pAttachments = &view;
4029 fb_info.height = 100;
4030 fb_info.width = 100;
4031 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004032 m_errorMonitor->SetDesiredFailureMsg(
4033 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4034 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004035 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4036
4037 m_errorMonitor->VerifyFound();
4038 if (err == VK_SUCCESS) {
4039 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4040 }
4041 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004042 // reset attachment to color attachment
4043 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004044
4045 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004046 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004047 fb_info.height = 100;
4048 fb_info.layers = 1;
4049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004050 m_errorMonitor->SetDesiredFailureMsg(
4051 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004052 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4053 "Here are the respective dimensions for attachment");
4054
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004055 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4056
4057 m_errorMonitor->VerifyFound();
4058 if (err == VK_SUCCESS) {
4059 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4060 }
4061
4062 // Request fb that exceeds max height
4063 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004064 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004065 fb_info.layers = 1;
4066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004067 m_errorMonitor->SetDesiredFailureMsg(
4068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004069 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4070 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4072
4073 m_errorMonitor->VerifyFound();
4074 if (err == VK_SUCCESS) {
4075 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4076 }
4077
4078 // Request fb that exceeds max layers
4079 fb_info.width = 100;
4080 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004081 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004083 m_errorMonitor->SetDesiredFailureMsg(
4084 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004085 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4086 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004087 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4088
4089 m_errorMonitor->VerifyFound();
4090 if (err == VK_SUCCESS) {
4091 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4092 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004093
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004094 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004095}
4096
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004097TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004098 TEST_DESCRIPTION(
4099 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4100 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004101
Cody Northropc31a84f2016-08-22 10:41:47 -06004102 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004103 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4105 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106 m_errorMonitor->VerifyFound();
4107}
4108
4109TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004110 TEST_DESCRIPTION(
4111 "Run a simple draw calls to validate failure when Line Width dynamic "
4112 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004113
Cody Northropc31a84f2016-08-22 10:41:47 -06004114 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004115 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004118 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004119}
4120
4121TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Viewport dynamic "
4124 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125
Cody Northropc31a84f2016-08-22 10:41:47 -06004126 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4129 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004131 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004132}
4133
4134TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004135 TEST_DESCRIPTION(
4136 "Run a simple draw calls to validate failure when Scissor dynamic "
4137 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138
Cody Northropc31a84f2016-08-22 10:41:47 -06004139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004140 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004145}
4146
Cortd713fe82016-07-27 09:51:27 -07004147TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004148 TEST_DESCRIPTION(
4149 "Run a simple draw calls to validate failure when Blend Constants "
4150 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004151
4152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004153 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4155 "Dynamic blend constants state not set for this command buffer");
4156 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004157 m_errorMonitor->VerifyFound();
4158}
4159
4160TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004161 TEST_DESCRIPTION(
4162 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4163 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004164
4165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004166 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004167 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004168 return;
4169 }
4170 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4172 "Dynamic depth bounds state not set for this command buffer");
4173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004175}
4176
4177TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004178 TEST_DESCRIPTION(
4179 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4180 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004181
4182 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004183 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4185 "Dynamic stencil read mask state not set for this command buffer");
4186 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004187 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004188}
4189
4190TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004191 TEST_DESCRIPTION(
4192 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4193 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004194
4195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004196 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4198 "Dynamic stencil write mask state not set for this command buffer");
4199 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004200 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004201}
4202
4203TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004204 TEST_DESCRIPTION(
4205 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4206 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004207
4208 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004209 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4211 "Dynamic stencil reference state not set for this command buffer");
4212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004213 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004214}
4215
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004216TEST_F(VkLayerTest, IndexBufferNotBound) {
4217 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004218
4219 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4221 "Index buffer object not bound to this command buffer when Indexed ");
4222 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004223 m_errorMonitor->VerifyFound();
4224}
4225
Karl Schultz6addd812016-02-02 17:17:23 -07004226TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4228 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4229 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004230
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004231 ASSERT_NO_FATAL_FAILURE(InitState());
4232 ASSERT_NO_FATAL_FAILURE(InitViewport());
4233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4234
Karl Schultz6addd812016-02-02 17:17:23 -07004235 // We luck out b/c by default the framework creates CB w/ the
4236 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004237 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004238 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004239 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004240
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004241 // Bypass framework since it does the waits automatically
4242 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004243 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4245 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004246 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004247 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004248 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004249 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004250 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004251 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004252 submit_info.pSignalSemaphores = NULL;
4253
Chris Forbes40028e22016-06-13 09:59:34 +12004254 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004256 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004257
Karl Schultz6addd812016-02-02 17:17:23 -07004258 // Cause validation error by re-submitting cmd buffer that should only be
4259 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004260 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004261 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004263 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004264}
4265
Karl Schultz6addd812016-02-02 17:17:23 -07004266TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004267 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004268 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004269
4270 ASSERT_NO_FATAL_FAILURE(InitState());
4271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004272
Karl Schultz6addd812016-02-02 17:17:23 -07004273 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4274 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004276 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004277 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278
4279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4281 ds_pool_ci.pNext = NULL;
4282 ds_pool_ci.flags = 0;
4283 ds_pool_ci.maxSets = 1;
4284 ds_pool_ci.poolSizeCount = 1;
4285 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
4287 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004289 ASSERT_VK_SUCCESS(err);
4290
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4292 dsl_binding_samp.binding = 0;
4293 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4294 dsl_binding_samp.descriptorCount = 1;
4295 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4296 dsl_binding_samp.pImmutableSamplers = NULL;
4297
4298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4300 ds_layout_ci.pNext = NULL;
4301 ds_layout_ci.bindingCount = 1;
4302 ds_layout_ci.pBindings = &dsl_binding_samp;
4303
4304 VkDescriptorSetLayout ds_layout_samp;
4305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4306 ASSERT_VK_SUCCESS(err);
4307
4308 // Try to allocate 2 sets when pool only has 1 set
4309 VkDescriptorSet descriptor_sets[2];
4310 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4311 VkDescriptorSetAllocateInfo alloc_info = {};
4312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4313 alloc_info.descriptorSetCount = 2;
4314 alloc_info.descriptorPool = ds_pool;
4315 alloc_info.pSetLayouts = set_layouts;
4316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4317 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4318 m_errorMonitor->VerifyFound();
4319
4320 alloc_info.descriptorSetCount = 1;
4321 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004322 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004323 dsl_binding.binding = 0;
4324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4325 dsl_binding.descriptorCount = 1;
4326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4327 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 ds_layout_ci.bindingCount = 1;
4330 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004332 VkDescriptorSetLayout ds_layout_ub;
4333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004334 ASSERT_VK_SUCCESS(err);
4335
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004336 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004337 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004338 alloc_info.pSetLayouts = &ds_layout_ub;
4339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4340 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004342 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343
Karl Schultz2825ab92016-12-02 08:23:14 -07004344 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347}
4348
Karl Schultz6addd812016-02-02 17:17:23 -07004349TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4350 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004351
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004353
Tobin Ehlise735c692015-10-08 13:13:50 -06004354 ASSERT_NO_FATAL_FAILURE(InitState());
4355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004356
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004357 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004358 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4359 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004360
4361 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004362 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4363 ds_pool_ci.pNext = NULL;
4364 ds_pool_ci.maxSets = 1;
4365 ds_pool_ci.poolSizeCount = 1;
4366 ds_pool_ci.flags = 0;
4367 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4368 // app can only call vkResetDescriptorPool on this pool.;
4369 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
4371 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004372 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_VK_SUCCESS(err);
4374
4375 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004376 dsl_binding.binding = 0;
4377 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 dsl_binding.descriptorCount = 1;
4379 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4380 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004381
4382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4384 ds_layout_ci.pNext = NULL;
4385 ds_layout_ci.bindingCount = 1;
4386 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004387
4388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004390 ASSERT_VK_SUCCESS(err);
4391
4392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004396 alloc_info.descriptorPool = ds_pool;
4397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004399 ASSERT_VK_SUCCESS(err);
4400
4401 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004402 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004403
Chia-I Wuf7458c52015-10-26 21:10:41 +08004404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4405 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004406}
4407
Karl Schultz6addd812016-02-02 17:17:23 -07004408TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004409 // Attempt to clear Descriptor Pool with bad object.
4410 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004411
4412 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004414 uint64_t fake_pool_handle = 0xbaad6001;
4415 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4416 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004417 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004418}
4419
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004420TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004421 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4422 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004423 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004424 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004425
4426 uint64_t fake_set_handle = 0xbaad6001;
4427 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
4432
4433 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4434 layout_bindings[0].binding = 0;
4435 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4436 layout_bindings[0].descriptorCount = 1;
4437 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4438 layout_bindings[0].pImmutableSamplers = NULL;
4439
4440 VkDescriptorSetLayout descriptor_set_layout;
4441 VkDescriptorSetLayoutCreateInfo dslci = {};
4442 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4443 dslci.pNext = NULL;
4444 dslci.bindingCount = 1;
4445 dslci.pBindings = layout_bindings;
4446 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004447 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004448
4449 VkPipelineLayout pipeline_layout;
4450 VkPipelineLayoutCreateInfo plci = {};
4451 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4452 plci.pNext = NULL;
4453 plci.setLayoutCount = 1;
4454 plci.pSetLayouts = &descriptor_set_layout;
4455 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004456 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004457
Tony Barbour552f6c02016-12-21 14:34:07 -07004458 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004459 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4460 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004461 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004462 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004463 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4464 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004465}
4466
Karl Schultz6addd812016-02-02 17:17:23 -07004467TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004468 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4469 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004470 uint64_t fake_layout_handle = 0xbaad6001;
4471 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004473 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004474 VkPipelineLayout pipeline_layout;
4475 VkPipelineLayoutCreateInfo plci = {};
4476 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4477 plci.pNext = NULL;
4478 plci.setLayoutCount = 1;
4479 plci.pSetLayouts = &bad_layout;
4480 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4481
4482 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004483}
4484
Mark Muellerd4914412016-06-13 17:52:06 -06004485TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004486 TEST_DESCRIPTION(
4487 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4488 "1) A uniform buffer update must have a valid buffer index."
4489 "2) When using an array of descriptors in a single WriteDescriptor,"
4490 " the descriptor types and stageflags must all be the same."
4491 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004492
Mike Weiblena6666382017-01-05 15:16:11 -07004493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004494
4495 ASSERT_NO_FATAL_FAILURE(InitState());
4496 VkDescriptorPoolSize ds_type_count[4] = {};
4497 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4498 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004499 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004500 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004501 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004502 ds_type_count[2].descriptorCount = 1;
4503 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4504 ds_type_count[3].descriptorCount = 1;
4505
4506 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4507 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4508 ds_pool_ci.maxSets = 1;
4509 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4510 ds_pool_ci.pPoolSizes = ds_type_count;
4511
4512 VkDescriptorPool ds_pool;
4513 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4514 ASSERT_VK_SUCCESS(err);
4515
Mark Muellerb9896722016-06-16 09:54:29 -06004516 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004517 layout_binding[0].binding = 0;
4518 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4519 layout_binding[0].descriptorCount = 1;
4520 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4521 layout_binding[0].pImmutableSamplers = NULL;
4522
4523 layout_binding[1].binding = 1;
4524 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4525 layout_binding[1].descriptorCount = 1;
4526 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4527 layout_binding[1].pImmutableSamplers = NULL;
4528
4529 VkSamplerCreateInfo sampler_ci = {};
4530 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4531 sampler_ci.pNext = NULL;
4532 sampler_ci.magFilter = VK_FILTER_NEAREST;
4533 sampler_ci.minFilter = VK_FILTER_NEAREST;
4534 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4535 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4536 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4537 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4538 sampler_ci.mipLodBias = 1.0;
4539 sampler_ci.anisotropyEnable = VK_FALSE;
4540 sampler_ci.maxAnisotropy = 1;
4541 sampler_ci.compareEnable = VK_FALSE;
4542 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4543 sampler_ci.minLod = 1.0;
4544 sampler_ci.maxLod = 1.0;
4545 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4546 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4547 VkSampler sampler;
4548
4549 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 layout_binding[2].binding = 2;
4553 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4554 layout_binding[2].descriptorCount = 1;
4555 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4556 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4557
Mark Muellerd4914412016-06-13 17:52:06 -06004558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4560 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4561 ds_layout_ci.pBindings = layout_binding;
4562 VkDescriptorSetLayout ds_layout;
4563 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 VkDescriptorSetAllocateInfo alloc_info = {};
4567 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4568 alloc_info.descriptorSetCount = 1;
4569 alloc_info.descriptorPool = ds_pool;
4570 alloc_info.pSetLayouts = &ds_layout;
4571 VkDescriptorSet descriptorSet;
4572 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4576 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4577 pipeline_layout_ci.pNext = NULL;
4578 pipeline_layout_ci.setLayoutCount = 1;
4579 pipeline_layout_ci.pSetLayouts = &ds_layout;
4580
4581 VkPipelineLayout pipeline_layout;
4582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
Mark Mueller5c838ce2016-06-16 09:54:29 -06004585 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4587 descriptor_write.dstSet = descriptorSet;
4588 descriptor_write.dstBinding = 0;
4589 descriptor_write.descriptorCount = 1;
4590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4591
Mark Mueller5c838ce2016-06-16 09:54:29 -06004592 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4594 m_errorMonitor->VerifyFound();
4595
4596 // Create a buffer to update the descriptor with
4597 uint32_t qfi = 0;
4598 VkBufferCreateInfo buffCI = {};
4599 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4600 buffCI.size = 1024;
4601 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4602 buffCI.queueFamilyIndexCount = 1;
4603 buffCI.pQueueFamilyIndices = &qfi;
4604
4605 VkBuffer dyub;
4606 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4607 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004608
Tony Barboure132c5f2016-12-12 11:50:20 -07004609 VkDeviceMemory mem;
4610 VkMemoryRequirements mem_reqs;
4611 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4612
4613 VkMemoryAllocateInfo mem_alloc_info = {};
4614 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4615 mem_alloc_info.allocationSize = mem_reqs.size;
4616 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4617 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4618 ASSERT_VK_SUCCESS(err);
4619
4620 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 VkDescriptorBufferInfo buffInfo[2] = {};
4624 buffInfo[0].buffer = dyub;
4625 buffInfo[0].offset = 0;
4626 buffInfo[0].range = 1024;
4627 buffInfo[1].buffer = dyub;
4628 buffInfo[1].offset = 0;
4629 buffInfo[1].range = 1024;
4630 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004631 descriptor_write.descriptorCount = 2;
4632
Mark Mueller5c838ce2016-06-16 09:54:29 -06004633 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4636 m_errorMonitor->VerifyFound();
4637
Mark Mueller5c838ce2016-06-16 09:54:29 -06004638 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4639 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004640 descriptor_write.dstBinding = 1;
4641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004642
Mark Mueller5c838ce2016-06-16 09:54:29 -06004643 // Make pImageInfo index non-null to avoid complaints of it missing
4644 VkDescriptorImageInfo imageInfo = {};
4645 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4646 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4649 m_errorMonitor->VerifyFound();
4650
Mark Muellerd4914412016-06-13 17:52:06 -06004651 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004652 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004653 vkDestroySampler(m_device->device(), sampler, NULL);
4654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4657}
4658
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004659TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004660 TEST_DESCRIPTION(
4661 "Attempt to draw with a command buffer that is invalid "
4662 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004663 ASSERT_NO_FATAL_FAILURE(InitState());
4664
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004665 VkBuffer buffer;
4666 VkDeviceMemory mem;
4667 VkMemoryRequirements mem_reqs;
4668
4669 VkBufferCreateInfo buf_info = {};
4670 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004671 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004672 buf_info.size = 256;
4673 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4674 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4675 ASSERT_VK_SUCCESS(err);
4676
4677 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4678
4679 VkMemoryAllocateInfo alloc_info = {};
4680 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4681 alloc_info.allocationSize = 256;
4682 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004683 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 -06004684 if (!pass) {
4685 vkDestroyBuffer(m_device->device(), buffer, NULL);
4686 return;
4687 }
4688 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4692 ASSERT_VK_SUCCESS(err);
4693
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004694 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004695 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004696 m_commandBuffer->EndCommandBuffer();
4697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004699 // Destroy buffer dependency prior to submit to cause ERROR
4700 vkDestroyBuffer(m_device->device(), buffer, NULL);
4701
4702 VkSubmitInfo submit_info = {};
4703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4704 submit_info.commandBufferCount = 1;
4705 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4707
4708 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004709 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 vkFreeMemory(m_device->handle(), mem, NULL);
4711}
4712
Tobin Ehlisea413442016-09-28 10:23:59 -06004713TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4714 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4715
4716 ASSERT_NO_FATAL_FAILURE(InitState());
4717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4718
4719 VkDescriptorPoolSize ds_type_count;
4720 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4721 ds_type_count.descriptorCount = 1;
4722
4723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4725 ds_pool_ci.maxSets = 1;
4726 ds_pool_ci.poolSizeCount = 1;
4727 ds_pool_ci.pPoolSizes = &ds_type_count;
4728
4729 VkDescriptorPool ds_pool;
4730 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4731 ASSERT_VK_SUCCESS(err);
4732
4733 VkDescriptorSetLayoutBinding layout_binding;
4734 layout_binding.binding = 0;
4735 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4736 layout_binding.descriptorCount = 1;
4737 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4738 layout_binding.pImmutableSamplers = NULL;
4739
4740 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4741 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4742 ds_layout_ci.bindingCount = 1;
4743 ds_layout_ci.pBindings = &layout_binding;
4744 VkDescriptorSetLayout ds_layout;
4745 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 VkDescriptorSetAllocateInfo alloc_info = {};
4749 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4750 alloc_info.descriptorSetCount = 1;
4751 alloc_info.descriptorPool = ds_pool;
4752 alloc_info.pSetLayouts = &ds_layout;
4753 VkDescriptorSet descriptor_set;
4754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4758 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4759 pipeline_layout_ci.pNext = NULL;
4760 pipeline_layout_ci.setLayoutCount = 1;
4761 pipeline_layout_ci.pSetLayouts = &ds_layout;
4762
4763 VkPipelineLayout pipeline_layout;
4764 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkBuffer buffer;
4768 uint32_t queue_family_index = 0;
4769 VkBufferCreateInfo buffer_create_info = {};
4770 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4771 buffer_create_info.size = 1024;
4772 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4773 buffer_create_info.queueFamilyIndexCount = 1;
4774 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4775
4776 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4777 ASSERT_VK_SUCCESS(err);
4778
4779 VkMemoryRequirements memory_reqs;
4780 VkDeviceMemory buffer_memory;
4781
4782 VkMemoryAllocateInfo memory_info = {};
4783 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4784 memory_info.allocationSize = 0;
4785 memory_info.memoryTypeIndex = 0;
4786
4787 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4788 memory_info.allocationSize = memory_reqs.size;
4789 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4790 ASSERT_TRUE(pass);
4791
4792 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4793 ASSERT_VK_SUCCESS(err);
4794 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4795 ASSERT_VK_SUCCESS(err);
4796
4797 VkBufferView view;
4798 VkBufferViewCreateInfo bvci = {};
4799 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4800 bvci.buffer = buffer;
4801 bvci.format = VK_FORMAT_R8_UNORM;
4802 bvci.range = VK_WHOLE_SIZE;
4803
4804 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4805 ASSERT_VK_SUCCESS(err);
4806
4807 VkWriteDescriptorSet descriptor_write = {};
4808 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4809 descriptor_write.dstSet = descriptor_set;
4810 descriptor_write.dstBinding = 0;
4811 descriptor_write.descriptorCount = 1;
4812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4813 descriptor_write.pTexelBufferView = &view;
4814
4815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4816
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004817 char const *vsSource =
4818 "#version 450\n"
4819 "\n"
4820 "out gl_PerVertex { \n"
4821 " vec4 gl_Position;\n"
4822 "};\n"
4823 "void main(){\n"
4824 " gl_Position = vec4(1);\n"
4825 "}\n";
4826 char const *fsSource =
4827 "#version 450\n"
4828 "\n"
4829 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4830 "layout(location=0) out vec4 x;\n"
4831 "void main(){\n"
4832 " x = imageLoad(s, 0);\n"
4833 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4836 VkPipelineObj pipe(m_device);
4837 pipe.AddShader(&vs);
4838 pipe.AddShader(&fs);
4839 pipe.AddColorAttachment();
4840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4841
Tobin Ehlisea413442016-09-28 10:23:59 -06004842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4843
Tony Barbour552f6c02016-12-21 14:34:07 -07004844 m_commandBuffer->BeginCommandBuffer();
4845 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4846
Tobin Ehlisea413442016-09-28 10:23:59 -06004847 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4848 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4849 VkRect2D scissor = {{0, 0}, {16, 16}};
4850 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4851 // Bind pipeline to cmd buffer
4852 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4854 &descriptor_set, 0, nullptr);
4855 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004856 m_commandBuffer->EndRenderPass();
4857 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004858
4859 // Delete BufferView in order to invalidate cmd buffer
4860 vkDestroyBufferView(m_device->device(), view, NULL);
4861 // Now attempt submit of cmd buffer
4862 VkSubmitInfo submit_info = {};
4863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4864 submit_info.commandBufferCount = 1;
4865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4867 m_errorMonitor->VerifyFound();
4868
4869 // Clean-up
4870 vkDestroyBuffer(m_device->device(), buffer, NULL);
4871 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4872 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4875}
4876
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004877TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004878 TEST_DESCRIPTION(
4879 "Attempt to draw with a command buffer that is invalid "
4880 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004881 ASSERT_NO_FATAL_FAILURE(InitState());
4882
4883 VkImage image;
4884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4885 VkImageCreateInfo image_create_info = {};
4886 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4887 image_create_info.pNext = NULL;
4888 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4889 image_create_info.format = tex_format;
4890 image_create_info.extent.width = 32;
4891 image_create_info.extent.height = 32;
4892 image_create_info.extent.depth = 1;
4893 image_create_info.mipLevels = 1;
4894 image_create_info.arrayLayers = 1;
4895 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4896 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004897 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004898 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004901 // Have to bind memory to image before recording cmd in cmd buffer using it
4902 VkMemoryRequirements mem_reqs;
4903 VkDeviceMemory image_mem;
4904 bool pass;
4905 VkMemoryAllocateInfo mem_alloc = {};
4906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4907 mem_alloc.pNext = NULL;
4908 mem_alloc.memoryTypeIndex = 0;
4909 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4910 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004912 ASSERT_TRUE(pass);
4913 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4914 ASSERT_VK_SUCCESS(err);
4915 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004918 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004919 VkClearColorValue ccv;
4920 ccv.float32[0] = 1.0f;
4921 ccv.float32[1] = 1.0f;
4922 ccv.float32[2] = 1.0f;
4923 ccv.float32[3] = 1.0f;
4924 VkImageSubresourceRange isr = {};
4925 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004926 isr.baseArrayLayer = 0;
4927 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004928 isr.layerCount = 1;
4929 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004931 m_commandBuffer->EndCommandBuffer();
4932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004934 // Destroy image dependency prior to submit to cause ERROR
4935 vkDestroyImage(m_device->device(), image, NULL);
4936
4937 VkSubmitInfo submit_info = {};
4938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4939 submit_info.commandBufferCount = 1;
4940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4941 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4942
4943 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004944 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945}
4946
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004947TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004948 TEST_DESCRIPTION(
4949 "Attempt to draw with a command buffer that is invalid "
4950 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004951 VkFormatProperties format_properties;
4952 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4954 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004955 return;
4956 }
4957
4958 ASSERT_NO_FATAL_FAILURE(InitState());
4959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4960
4961 VkImageCreateInfo image_ci = {};
4962 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4963 image_ci.pNext = NULL;
4964 image_ci.imageType = VK_IMAGE_TYPE_2D;
4965 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4966 image_ci.extent.width = 32;
4967 image_ci.extent.height = 32;
4968 image_ci.extent.depth = 1;
4969 image_ci.mipLevels = 1;
4970 image_ci.arrayLayers = 1;
4971 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4972 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004973 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4975 image_ci.flags = 0;
4976 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004977 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004978
4979 VkMemoryRequirements memory_reqs;
4980 VkDeviceMemory image_memory;
4981 bool pass;
4982 VkMemoryAllocateInfo memory_info = {};
4983 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4984 memory_info.pNext = NULL;
4985 memory_info.allocationSize = 0;
4986 memory_info.memoryTypeIndex = 0;
4987 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4988 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004990 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992 ASSERT_VK_SUCCESS(err);
4993 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4994 ASSERT_VK_SUCCESS(err);
4995
4996 VkImageViewCreateInfo ivci = {
4997 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4998 nullptr,
4999 0,
5000 image,
5001 VK_IMAGE_VIEW_TYPE_2D,
5002 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5005 };
5006 VkImageView view;
5007 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5008 ASSERT_VK_SUCCESS(err);
5009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 VkFramebuffer fb;
5012 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 // Just use default renderpass with our framebuffer
5016 m_renderPassBeginInfo.framebuffer = fb;
5017 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005018 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005019 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07005020 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5021 m_commandBuffer->EndRenderPass();
5022 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 // Destroy image attached to framebuffer to invalidate cmd buffer
5024 vkDestroyImage(m_device->device(), image, NULL);
5025 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005027 QueueCommandBuffer(false);
5028 m_errorMonitor->VerifyFound();
5029
5030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5031 vkDestroyImageView(m_device->device(), view, nullptr);
5032 vkFreeMemory(m_device->device(), image_memory, nullptr);
5033}
5034
Tobin Ehlisb329f992016-10-12 13:20:29 -06005035TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5036 TEST_DESCRIPTION("Delete in-use framebuffer.");
5037 VkFormatProperties format_properties;
5038 VkResult err = VK_SUCCESS;
5039 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5040
5041 ASSERT_NO_FATAL_FAILURE(InitState());
5042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5043
5044 VkImageObj image(m_device);
5045 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5046 ASSERT_TRUE(image.initialized());
5047 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5048
5049 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5050 VkFramebuffer fb;
5051 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5052 ASSERT_VK_SUCCESS(err);
5053
5054 // Just use default renderpass with our framebuffer
5055 m_renderPassBeginInfo.framebuffer = fb;
5056 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005057 m_commandBuffer->BeginCommandBuffer();
5058 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5059 m_commandBuffer->EndRenderPass();
5060 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005061 // Submit cmd buffer to put it in-flight
5062 VkSubmitInfo submit_info = {};
5063 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5064 submit_info.commandBufferCount = 1;
5065 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5067 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005069 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5070 m_errorMonitor->VerifyFound();
5071 // Wait for queue to complete so we can safely destroy everything
5072 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005073 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5074 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005075 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5076}
5077
Tobin Ehlis88becd72016-09-21 14:33:41 -06005078TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5079 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5080 VkFormatProperties format_properties;
5081 VkResult err = VK_SUCCESS;
5082 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005083
5084 ASSERT_NO_FATAL_FAILURE(InitState());
5085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5086
5087 VkImageCreateInfo image_ci = {};
5088 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5089 image_ci.pNext = NULL;
5090 image_ci.imageType = VK_IMAGE_TYPE_2D;
5091 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5092 image_ci.extent.width = 256;
5093 image_ci.extent.height = 256;
5094 image_ci.extent.depth = 1;
5095 image_ci.mipLevels = 1;
5096 image_ci.arrayLayers = 1;
5097 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5098 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005099 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005100 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5101 image_ci.flags = 0;
5102 VkImage image;
5103 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5104
5105 VkMemoryRequirements memory_reqs;
5106 VkDeviceMemory image_memory;
5107 bool pass;
5108 VkMemoryAllocateInfo memory_info = {};
5109 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5110 memory_info.pNext = NULL;
5111 memory_info.allocationSize = 0;
5112 memory_info.memoryTypeIndex = 0;
5113 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5114 memory_info.allocationSize = memory_reqs.size;
5115 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5116 ASSERT_TRUE(pass);
5117 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5118 ASSERT_VK_SUCCESS(err);
5119 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5120 ASSERT_VK_SUCCESS(err);
5121
5122 VkImageViewCreateInfo ivci = {
5123 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5124 nullptr,
5125 0,
5126 image,
5127 VK_IMAGE_VIEW_TYPE_2D,
5128 VK_FORMAT_B8G8R8A8_UNORM,
5129 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5130 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5131 };
5132 VkImageView view;
5133 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5134 ASSERT_VK_SUCCESS(err);
5135
5136 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5137 VkFramebuffer fb;
5138 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5139 ASSERT_VK_SUCCESS(err);
5140
5141 // Just use default renderpass with our framebuffer
5142 m_renderPassBeginInfo.framebuffer = fb;
5143 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005144 m_commandBuffer->BeginCommandBuffer();
5145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5146 m_commandBuffer->EndRenderPass();
5147 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005148 // Submit cmd buffer to put it (and attached imageView) in-flight
5149 VkSubmitInfo submit_info = {};
5150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5151 submit_info.commandBufferCount = 1;
5152 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5153 // Submit cmd buffer to put framebuffer and children in-flight
5154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5155 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 vkDestroyImage(m_device->device(), image, NULL);
5158 m_errorMonitor->VerifyFound();
5159 // Wait for queue to complete so we can safely destroy image and other objects
5160 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005161 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5162 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005163 vkDestroyImage(m_device->device(), image, NULL);
5164 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5165 vkDestroyImageView(m_device->device(), view, nullptr);
5166 vkFreeMemory(m_device->device(), image_memory, nullptr);
5167}
5168
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005169TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5170 TEST_DESCRIPTION("Delete in-use renderPass.");
5171
5172 ASSERT_NO_FATAL_FAILURE(InitState());
5173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5174
5175 // Create simple renderpass
5176 VkAttachmentReference attach = {};
5177 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5178 VkSubpassDescription subpass = {};
5179 subpass.pColorAttachments = &attach;
5180 VkRenderPassCreateInfo rpci = {};
5181 rpci.subpassCount = 1;
5182 rpci.pSubpasses = &subpass;
5183 rpci.attachmentCount = 1;
5184 VkAttachmentDescription attach_desc = {};
5185 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5186 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5187 rpci.pAttachments = &attach_desc;
5188 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5189 VkRenderPass rp;
5190 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5191 ASSERT_VK_SUCCESS(err);
5192
5193 // Create a pipeline that uses the given renderpass
5194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5196
5197 VkPipelineLayout pipeline_layout;
5198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5199 ASSERT_VK_SUCCESS(err);
5200
5201 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5202 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5203 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005204 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005205 vp_state_ci.pViewports = &vp;
5206 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005207 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005208 vp_state_ci.pScissors = &scissors;
5209
5210 VkPipelineShaderStageCreateInfo shaderStages[2];
5211 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5212
5213 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005214 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 -06005215 // but add it to be able to run on more devices
5216 shaderStages[0] = vs.GetStageCreateInfo();
5217 shaderStages[1] = fs.GetStageCreateInfo();
5218
5219 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5220 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5221
5222 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5223 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5224 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5225
5226 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5227 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5228 rs_ci.rasterizerDiscardEnable = true;
5229 rs_ci.lineWidth = 1.0f;
5230
5231 VkPipelineColorBlendAttachmentState att = {};
5232 att.blendEnable = VK_FALSE;
5233 att.colorWriteMask = 0xf;
5234
5235 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5236 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5237 cb_ci.attachmentCount = 1;
5238 cb_ci.pAttachments = &att;
5239
5240 VkGraphicsPipelineCreateInfo gp_ci = {};
5241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5242 gp_ci.stageCount = 2;
5243 gp_ci.pStages = shaderStages;
5244 gp_ci.pVertexInputState = &vi_ci;
5245 gp_ci.pInputAssemblyState = &ia_ci;
5246 gp_ci.pViewportState = &vp_state_ci;
5247 gp_ci.pRasterizationState = &rs_ci;
5248 gp_ci.pColorBlendState = &cb_ci;
5249 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5250 gp_ci.layout = pipeline_layout;
5251 gp_ci.renderPass = rp;
5252
5253 VkPipelineCacheCreateInfo pc_ci = {};
5254 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5255
5256 VkPipeline pipeline;
5257 VkPipelineCache pipe_cache;
5258 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5259 ASSERT_VK_SUCCESS(err);
5260
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005261 m_errorMonitor->SetUnexpectedError(
5262 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5263 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005264 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5265 ASSERT_VK_SUCCESS(err);
5266 // Bind pipeline to cmd buffer, will also bind renderpass
5267 m_commandBuffer->BeginCommandBuffer();
5268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5269 m_commandBuffer->EndCommandBuffer();
5270
5271 VkSubmitInfo submit_info = {};
5272 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5273 submit_info.commandBufferCount = 1;
5274 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5275 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5276
5277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5278 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5279 m_errorMonitor->VerifyFound();
5280
5281 // Wait for queue to complete so we can safely destroy everything
5282 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005283 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5284 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005285 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5286 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5287 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5289}
5290
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005291TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005293 ASSERT_NO_FATAL_FAILURE(InitState());
5294
5295 VkImage image;
5296 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5297 VkImageCreateInfo image_create_info = {};
5298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5299 image_create_info.pNext = NULL;
5300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5301 image_create_info.format = tex_format;
5302 image_create_info.extent.width = 32;
5303 image_create_info.extent.height = 32;
5304 image_create_info.extent.depth = 1;
5305 image_create_info.mipLevels = 1;
5306 image_create_info.arrayLayers = 1;
5307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5308 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005310 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005311 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005312 ASSERT_VK_SUCCESS(err);
5313 // Have to bind memory to image before recording cmd in cmd buffer using it
5314 VkMemoryRequirements mem_reqs;
5315 VkDeviceMemory image_mem;
5316 bool pass;
5317 VkMemoryAllocateInfo mem_alloc = {};
5318 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5319 mem_alloc.pNext = NULL;
5320 mem_alloc.memoryTypeIndex = 0;
5321 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5322 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005324 ASSERT_TRUE(pass);
5325 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5326 ASSERT_VK_SUCCESS(err);
5327
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005328 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005330 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005331
5332 m_commandBuffer->BeginCommandBuffer();
5333 VkClearColorValue ccv;
5334 ccv.float32[0] = 1.0f;
5335 ccv.float32[1] = 1.0f;
5336 ccv.float32[2] = 1.0f;
5337 ccv.float32[3] = 1.0f;
5338 VkImageSubresourceRange isr = {};
5339 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5340 isr.baseArrayLayer = 0;
5341 isr.baseMipLevel = 0;
5342 isr.layerCount = 1;
5343 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005344 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005345 m_commandBuffer->EndCommandBuffer();
5346
5347 m_errorMonitor->VerifyFound();
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 vkFreeMemory(m_device->device(), image_mem, nullptr);
5350}
5351
5352TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005353 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005354 ASSERT_NO_FATAL_FAILURE(InitState());
5355
5356 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005357 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 -06005358 VK_IMAGE_TILING_OPTIMAL, 0);
5359 ASSERT_TRUE(image.initialized());
5360
5361 VkBuffer buffer;
5362 VkDeviceMemory mem;
5363 VkMemoryRequirements mem_reqs;
5364
5365 VkBufferCreateInfo buf_info = {};
5366 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005367 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005368 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005369 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5370 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5374
5375 VkMemoryAllocateInfo alloc_info = {};
5376 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005377 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 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 -06005380 if (!pass) {
5381 vkDestroyBuffer(m_device->device(), buffer, NULL);
5382 return;
5383 }
5384 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5385 ASSERT_VK_SUCCESS(err);
5386
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005387 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005389 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005390 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005391 region.bufferRowLength = 16;
5392 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005393 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5394
5395 region.imageSubresource.layerCount = 1;
5396 region.imageExtent.height = 4;
5397 region.imageExtent.width = 4;
5398 region.imageExtent.depth = 1;
5399 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5401 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005402 m_commandBuffer->EndCommandBuffer();
5403
5404 m_errorMonitor->VerifyFound();
5405
5406 vkDestroyBuffer(m_device->device(), buffer, NULL);
5407 vkFreeMemory(m_device->handle(), mem, NULL);
5408}
5409
Tobin Ehlis85940f52016-07-07 16:57:21 -06005410TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005411 TEST_DESCRIPTION(
5412 "Attempt to draw with a command buffer that is invalid "
5413 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005414 ASSERT_NO_FATAL_FAILURE(InitState());
5415
5416 VkEvent event;
5417 VkEventCreateInfo evci = {};
5418 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5419 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5420 ASSERT_VK_SUCCESS(result);
5421
5422 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005423 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005424 m_commandBuffer->EndCommandBuffer();
5425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005427 // Destroy event dependency prior to submit to cause ERROR
5428 vkDestroyEvent(m_device->device(), event, NULL);
5429
5430 VkSubmitInfo submit_info = {};
5431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5432 submit_info.commandBufferCount = 1;
5433 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5434 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5435
5436 m_errorMonitor->VerifyFound();
5437}
5438
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005439TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005440 TEST_DESCRIPTION(
5441 "Attempt to draw with a command buffer that is invalid "
5442 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005443 ASSERT_NO_FATAL_FAILURE(InitState());
5444
5445 VkQueryPool query_pool;
5446 VkQueryPoolCreateInfo qpci{};
5447 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5448 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5449 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005450 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005451 ASSERT_VK_SUCCESS(result);
5452
5453 m_commandBuffer->BeginCommandBuffer();
5454 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5455 m_commandBuffer->EndCommandBuffer();
5456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005458 // Destroy query pool dependency prior to submit to cause ERROR
5459 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5460
5461 VkSubmitInfo submit_info = {};
5462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5463 submit_info.commandBufferCount = 1;
5464 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5466
5467 m_errorMonitor->VerifyFound();
5468}
5469
Tobin Ehlis24130d92016-07-08 15:50:53 -06005470TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005471 TEST_DESCRIPTION(
5472 "Attempt to draw with a command buffer that is invalid "
5473 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005474 ASSERT_NO_FATAL_FAILURE(InitState());
5475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5476
5477 VkResult err;
5478
5479 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5480 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5481
5482 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_VK_SUCCESS(err);
5485
5486 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5487 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5488 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005489 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005490 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005492 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494
5495 VkPipelineShaderStageCreateInfo shaderStages[2];
5496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005499 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 -06005500 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005501 shaderStages[0] = vs.GetStageCreateInfo();
5502 shaderStages[1] = fs.GetStageCreateInfo();
5503
5504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5506
5507 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5508 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5509 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5510
5511 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5512 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005513 rs_ci.rasterizerDiscardEnable = true;
5514 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005515
5516 VkPipelineColorBlendAttachmentState att = {};
5517 att.blendEnable = VK_FALSE;
5518 att.colorWriteMask = 0xf;
5519
5520 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5521 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5522 cb_ci.attachmentCount = 1;
5523 cb_ci.pAttachments = &att;
5524
5525 VkGraphicsPipelineCreateInfo gp_ci = {};
5526 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5527 gp_ci.stageCount = 2;
5528 gp_ci.pStages = shaderStages;
5529 gp_ci.pVertexInputState = &vi_ci;
5530 gp_ci.pInputAssemblyState = &ia_ci;
5531 gp_ci.pViewportState = &vp_state_ci;
5532 gp_ci.pRasterizationState = &rs_ci;
5533 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005534 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5535 gp_ci.layout = pipeline_layout;
5536 gp_ci.renderPass = renderPass();
5537
5538 VkPipelineCacheCreateInfo pc_ci = {};
5539 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5540
5541 VkPipeline pipeline;
5542 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005544 ASSERT_VK_SUCCESS(err);
5545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005546 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005550 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005551 m_commandBuffer->EndCommandBuffer();
5552 // Now destroy pipeline in order to cause error when submitting
5553 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005556
5557 VkSubmitInfo submit_info = {};
5558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5559 submit_info.commandBufferCount = 1;
5560 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5561 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5562
5563 m_errorMonitor->VerifyFound();
5564 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5566}
5567
Tobin Ehlis31289162016-08-17 14:57:58 -06005568TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005569 TEST_DESCRIPTION(
5570 "Attempt to draw with a command buffer that is invalid "
5571 "due to a bound descriptor set with a buffer dependency "
5572 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005573 ASSERT_NO_FATAL_FAILURE(InitState());
5574 ASSERT_NO_FATAL_FAILURE(InitViewport());
5575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5576
5577 VkDescriptorPoolSize ds_type_count = {};
5578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5579 ds_type_count.descriptorCount = 1;
5580
5581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5583 ds_pool_ci.pNext = NULL;
5584 ds_pool_ci.maxSets = 1;
5585 ds_pool_ci.poolSizeCount = 1;
5586 ds_pool_ci.pPoolSizes = &ds_type_count;
5587
5588 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005589 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_VK_SUCCESS(err);
5591
5592 VkDescriptorSetLayoutBinding dsl_binding = {};
5593 dsl_binding.binding = 0;
5594 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5595 dsl_binding.descriptorCount = 1;
5596 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5597 dsl_binding.pImmutableSamplers = NULL;
5598
5599 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5600 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5601 ds_layout_ci.pNext = NULL;
5602 ds_layout_ci.bindingCount = 1;
5603 ds_layout_ci.pBindings = &dsl_binding;
5604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkDescriptorSet descriptorSet;
5609 VkDescriptorSetAllocateInfo alloc_info = {};
5610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5611 alloc_info.descriptorSetCount = 1;
5612 alloc_info.descriptorPool = ds_pool;
5613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5618 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5619 pipeline_layout_ci.pNext = NULL;
5620 pipeline_layout_ci.setLayoutCount = 1;
5621 pipeline_layout_ci.pSetLayouts = &ds_layout;
5622
5623 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 // Create a buffer to update the descriptor with
5628 uint32_t qfi = 0;
5629 VkBufferCreateInfo buffCI = {};
5630 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5631 buffCI.size = 1024;
5632 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5633 buffCI.queueFamilyIndexCount = 1;
5634 buffCI.pQueueFamilyIndices = &qfi;
5635
5636 VkBuffer buffer;
5637 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5638 ASSERT_VK_SUCCESS(err);
5639 // Allocate memory and bind to buffer so we can make it to the appropriate
5640 // error
5641 VkMemoryAllocateInfo mem_alloc = {};
5642 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5643 mem_alloc.pNext = NULL;
5644 mem_alloc.allocationSize = 1024;
5645 mem_alloc.memoryTypeIndex = 0;
5646
5647 VkMemoryRequirements memReqs;
5648 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 if (!pass) {
5651 vkDestroyBuffer(m_device->device(), buffer, NULL);
5652 return;
5653 }
5654
5655 VkDeviceMemory mem;
5656 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5657 ASSERT_VK_SUCCESS(err);
5658 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5659 ASSERT_VK_SUCCESS(err);
5660 // Correctly update descriptor to avoid "NOT_UPDATED" error
5661 VkDescriptorBufferInfo buffInfo = {};
5662 buffInfo.buffer = buffer;
5663 buffInfo.offset = 0;
5664 buffInfo.range = 1024;
5665
5666 VkWriteDescriptorSet descriptor_write;
5667 memset(&descriptor_write, 0, sizeof(descriptor_write));
5668 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5669 descriptor_write.dstSet = descriptorSet;
5670 descriptor_write.dstBinding = 0;
5671 descriptor_write.descriptorCount = 1;
5672 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5673 descriptor_write.pBufferInfo = &buffInfo;
5674
5675 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5676
5677 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005678 char const *vsSource =
5679 "#version 450\n"
5680 "\n"
5681 "out gl_PerVertex { \n"
5682 " vec4 gl_Position;\n"
5683 "};\n"
5684 "void main(){\n"
5685 " gl_Position = vec4(1);\n"
5686 "}\n";
5687 char const *fsSource =
5688 "#version 450\n"
5689 "\n"
5690 "layout(location=0) out vec4 x;\n"
5691 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5692 "void main(){\n"
5693 " x = vec4(bar.y);\n"
5694 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5696 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
5699 pipe.AddShader(&fs);
5700 pipe.AddColorAttachment();
5701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5702
Tony Barbour552f6c02016-12-21 14:34:07 -07005703 m_commandBuffer->BeginCommandBuffer();
5704 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5707 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005708
5709 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5710 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5711
Tobin Ehlis31289162016-08-17 14:57:58 -06005712 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005713 m_commandBuffer->EndRenderPass();
5714 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005716 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5717 vkDestroyBuffer(m_device->device(), buffer, NULL);
5718 // Attempt to submit cmd buffer
5719 VkSubmitInfo submit_info = {};
5720 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5721 submit_info.commandBufferCount = 1;
5722 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5723 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5724 m_errorMonitor->VerifyFound();
5725 // Cleanup
5726 vkFreeMemory(m_device->device(), mem, NULL);
5727
5728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5731}
5732
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005733TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005734 TEST_DESCRIPTION(
5735 "Attempt to draw with a command buffer that is invalid "
5736 "due to a bound descriptor sets with a combined image "
5737 "sampler having their image, sampler, and descriptor set "
5738 "each respectively destroyed and then attempting to "
5739 "submit associated cmd buffers. Attempt to destroy a "
5740 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005741 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005742 ASSERT_NO_FATAL_FAILURE(InitViewport());
5743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5744
5745 VkDescriptorPoolSize ds_type_count = {};
5746 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5747 ds_type_count.descriptorCount = 1;
5748
5749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5751 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005752 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753 ds_pool_ci.maxSets = 1;
5754 ds_pool_ci.poolSizeCount = 1;
5755 ds_pool_ci.pPoolSizes = &ds_type_count;
5756
5757 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005758 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005759 ASSERT_VK_SUCCESS(err);
5760
5761 VkDescriptorSetLayoutBinding dsl_binding = {};
5762 dsl_binding.binding = 0;
5763 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5764 dsl_binding.descriptorCount = 1;
5765 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5766 dsl_binding.pImmutableSamplers = NULL;
5767
5768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5770 ds_layout_ci.pNext = NULL;
5771 ds_layout_ci.bindingCount = 1;
5772 ds_layout_ci.pBindings = &dsl_binding;
5773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776
5777 VkDescriptorSet descriptorSet;
5778 VkDescriptorSetAllocateInfo alloc_info = {};
5779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5780 alloc_info.descriptorSetCount = 1;
5781 alloc_info.descriptorPool = ds_pool;
5782 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5788 pipeline_layout_ci.pNext = NULL;
5789 pipeline_layout_ci.setLayoutCount = 1;
5790 pipeline_layout_ci.pSetLayouts = &ds_layout;
5791
5792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795
5796 // Create images to update the descriptor with
5797 VkImage image;
5798 VkImage image2;
5799 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5800 const int32_t tex_width = 32;
5801 const int32_t tex_height = 32;
5802 VkImageCreateInfo image_create_info = {};
5803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5804 image_create_info.pNext = NULL;
5805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5806 image_create_info.format = tex_format;
5807 image_create_info.extent.width = tex_width;
5808 image_create_info.extent.height = tex_height;
5809 image_create_info.extent.depth = 1;
5810 image_create_info.mipLevels = 1;
5811 image_create_info.arrayLayers = 1;
5812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5813 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5814 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5815 image_create_info.flags = 0;
5816 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5817 ASSERT_VK_SUCCESS(err);
5818 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5819 ASSERT_VK_SUCCESS(err);
5820
5821 VkMemoryRequirements memory_reqs;
5822 VkDeviceMemory image_memory;
5823 bool pass;
5824 VkMemoryAllocateInfo memory_info = {};
5825 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5826 memory_info.pNext = NULL;
5827 memory_info.allocationSize = 0;
5828 memory_info.memoryTypeIndex = 0;
5829 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5830 // Allocate enough memory for both images
5831 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005833 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005835 ASSERT_VK_SUCCESS(err);
5836 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5837 ASSERT_VK_SUCCESS(err);
5838 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005839 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005840 ASSERT_VK_SUCCESS(err);
5841
5842 VkImageViewCreateInfo image_view_create_info = {};
5843 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5844 image_view_create_info.image = image;
5845 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5846 image_view_create_info.format = tex_format;
5847 image_view_create_info.subresourceRange.layerCount = 1;
5848 image_view_create_info.subresourceRange.baseMipLevel = 0;
5849 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005851
5852 VkImageView view;
5853 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 ASSERT_VK_SUCCESS(err);
5859 // Create Samplers
5860 VkSamplerCreateInfo sampler_ci = {};
5861 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5862 sampler_ci.pNext = NULL;
5863 sampler_ci.magFilter = VK_FILTER_NEAREST;
5864 sampler_ci.minFilter = VK_FILTER_NEAREST;
5865 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5866 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5867 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5868 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5869 sampler_ci.mipLodBias = 1.0;
5870 sampler_ci.anisotropyEnable = VK_FALSE;
5871 sampler_ci.maxAnisotropy = 1;
5872 sampler_ci.compareEnable = VK_FALSE;
5873 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5874 sampler_ci.minLod = 1.0;
5875 sampler_ci.maxLod = 1.0;
5876 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5877 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5878 VkSampler sampler;
5879 VkSampler sampler2;
5880 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5881 ASSERT_VK_SUCCESS(err);
5882 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5883 ASSERT_VK_SUCCESS(err);
5884 // Update descriptor with image and sampler
5885 VkDescriptorImageInfo img_info = {};
5886 img_info.sampler = sampler;
5887 img_info.imageView = view;
5888 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5889
5890 VkWriteDescriptorSet descriptor_write;
5891 memset(&descriptor_write, 0, sizeof(descriptor_write));
5892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5893 descriptor_write.dstSet = descriptorSet;
5894 descriptor_write.dstBinding = 0;
5895 descriptor_write.descriptorCount = 1;
5896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5897 descriptor_write.pImageInfo = &img_info;
5898
5899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5900
5901 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005902 char const *vsSource =
5903 "#version 450\n"
5904 "\n"
5905 "out gl_PerVertex { \n"
5906 " vec4 gl_Position;\n"
5907 "};\n"
5908 "void main(){\n"
5909 " gl_Position = vec4(1);\n"
5910 "}\n";
5911 char const *fsSource =
5912 "#version 450\n"
5913 "\n"
5914 "layout(set=0, binding=0) uniform sampler2D s;\n"
5915 "layout(location=0) out vec4 x;\n"
5916 "void main(){\n"
5917 " x = texture(s, vec2(1));\n"
5918 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5921 VkPipelineObj pipe(m_device);
5922 pipe.AddShader(&vs);
5923 pipe.AddShader(&fs);
5924 pipe.AddColorAttachment();
5925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5926
5927 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005929 m_commandBuffer->BeginCommandBuffer();
5930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5932 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5933 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005934 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5935 VkRect2D scissor = {{0, 0}, {16, 16}};
5936 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5937 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005938 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005939 m_commandBuffer->EndRenderPass();
5940 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005941 // Destroy sampler invalidates the cmd buffer, causing error on submit
5942 vkDestroySampler(m_device->device(), sampler, NULL);
5943 // Attempt to submit cmd buffer
5944 VkSubmitInfo submit_info = {};
5945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5946 submit_info.commandBufferCount = 1;
5947 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5948 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5949 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005950
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 // Now re-update descriptor with valid sampler and delete image
5952 img_info.sampler = sampler2;
5953 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005954
5955 VkCommandBufferBeginInfo info = {};
5956 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5957 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005960 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005961 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005962 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5963 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5964 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005965 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5966 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005967 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005968 m_commandBuffer->EndRenderPass();
5969 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005970 // Destroy image invalidates the cmd buffer, causing error on submit
5971 vkDestroyImage(m_device->device(), image, NULL);
5972 // Attempt to submit cmd buffer
5973 submit_info = {};
5974 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5975 submit_info.commandBufferCount = 1;
5976 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5978 m_errorMonitor->VerifyFound();
5979 // Now update descriptor to be valid, but then free descriptor
5980 img_info.imageView = view2;
5981 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005982 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005983 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5985 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5986 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005987 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5988 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005989 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005990 m_commandBuffer->EndRenderPass();
5991 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005993
5994 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005996 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005997 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005998
5999 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006000 // 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 -07006001 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006002 m_errorMonitor->SetUnexpectedError(
6003 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6004 "either be a valid handle or VK_NULL_HANDLE");
6005 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006006 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6007
6008 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 submit_info = {};
6010 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6011 submit_info.commandBufferCount = 1;
6012 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6015 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006016
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006017 // Cleanup
6018 vkFreeMemory(m_device->device(), image_memory, NULL);
6019 vkDestroySampler(m_device->device(), sampler2, NULL);
6020 vkDestroyImage(m_device->device(), image2, NULL);
6021 vkDestroyImageView(m_device->device(), view, NULL);
6022 vkDestroyImageView(m_device->device(), view2, NULL);
6023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6026}
6027
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006028TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6029 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6030 ASSERT_NO_FATAL_FAILURE(InitState());
6031 ASSERT_NO_FATAL_FAILURE(InitViewport());
6032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6033
6034 VkDescriptorPoolSize ds_type_count = {};
6035 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6036 ds_type_count.descriptorCount = 1;
6037
6038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6040 ds_pool_ci.pNext = NULL;
6041 ds_pool_ci.maxSets = 1;
6042 ds_pool_ci.poolSizeCount = 1;
6043 ds_pool_ci.pPoolSizes = &ds_type_count;
6044
6045 VkDescriptorPool ds_pool;
6046 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6047 ASSERT_VK_SUCCESS(err);
6048
6049 VkDescriptorSetLayoutBinding dsl_binding = {};
6050 dsl_binding.binding = 0;
6051 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6052 dsl_binding.descriptorCount = 1;
6053 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6054 dsl_binding.pImmutableSamplers = NULL;
6055
6056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6058 ds_layout_ci.pNext = NULL;
6059 ds_layout_ci.bindingCount = 1;
6060 ds_layout_ci.pBindings = &dsl_binding;
6061 VkDescriptorSetLayout ds_layout;
6062 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6063 ASSERT_VK_SUCCESS(err);
6064
6065 VkDescriptorSet descriptor_set;
6066 VkDescriptorSetAllocateInfo alloc_info = {};
6067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6068 alloc_info.descriptorSetCount = 1;
6069 alloc_info.descriptorPool = ds_pool;
6070 alloc_info.pSetLayouts = &ds_layout;
6071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6072 ASSERT_VK_SUCCESS(err);
6073
6074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6076 pipeline_layout_ci.pNext = NULL;
6077 pipeline_layout_ci.setLayoutCount = 1;
6078 pipeline_layout_ci.pSetLayouts = &ds_layout;
6079
6080 VkPipelineLayout pipeline_layout;
6081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6082 ASSERT_VK_SUCCESS(err);
6083
6084 // Create image to update the descriptor with
6085 VkImageObj image(m_device);
6086 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6087 ASSERT_TRUE(image.initialized());
6088
6089 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6090 // Create Sampler
6091 VkSamplerCreateInfo sampler_ci = {};
6092 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6093 sampler_ci.pNext = NULL;
6094 sampler_ci.magFilter = VK_FILTER_NEAREST;
6095 sampler_ci.minFilter = VK_FILTER_NEAREST;
6096 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6097 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6098 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6099 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6100 sampler_ci.mipLodBias = 1.0;
6101 sampler_ci.anisotropyEnable = VK_FALSE;
6102 sampler_ci.maxAnisotropy = 1;
6103 sampler_ci.compareEnable = VK_FALSE;
6104 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6105 sampler_ci.minLod = 1.0;
6106 sampler_ci.maxLod = 1.0;
6107 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6108 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6109 VkSampler sampler;
6110 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6111 ASSERT_VK_SUCCESS(err);
6112 // Update descriptor with image and sampler
6113 VkDescriptorImageInfo img_info = {};
6114 img_info.sampler = sampler;
6115 img_info.imageView = view;
6116 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6117
6118 VkWriteDescriptorSet descriptor_write;
6119 memset(&descriptor_write, 0, sizeof(descriptor_write));
6120 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6121 descriptor_write.dstSet = descriptor_set;
6122 descriptor_write.dstBinding = 0;
6123 descriptor_write.descriptorCount = 1;
6124 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6125 descriptor_write.pImageInfo = &img_info;
6126
6127 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6128
6129 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006130 char const *vsSource =
6131 "#version 450\n"
6132 "\n"
6133 "out gl_PerVertex { \n"
6134 " vec4 gl_Position;\n"
6135 "};\n"
6136 "void main(){\n"
6137 " gl_Position = vec4(1);\n"
6138 "}\n";
6139 char const *fsSource =
6140 "#version 450\n"
6141 "\n"
6142 "layout(set=0, binding=0) uniform sampler2D s;\n"
6143 "layout(location=0) out vec4 x;\n"
6144 "void main(){\n"
6145 " x = texture(s, vec2(1));\n"
6146 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6149 VkPipelineObj pipe(m_device);
6150 pipe.AddShader(&vs);
6151 pipe.AddShader(&fs);
6152 pipe.AddColorAttachment();
6153 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6154
Tony Barbour552f6c02016-12-21 14:34:07 -07006155 m_commandBuffer->BeginCommandBuffer();
6156 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006157 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6158 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6159 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006160
6161 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6162 VkRect2D scissor = {{0, 0}, {16, 16}};
6163 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6164 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6165
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006166 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006167 m_commandBuffer->EndRenderPass();
6168 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006169 // Submit cmd buffer to put pool in-flight
6170 VkSubmitInfo submit_info = {};
6171 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6172 submit_info.commandBufferCount = 1;
6173 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6175 // Destroy pool while in-flight, causing error
6176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6177 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6178 m_errorMonitor->VerifyFound();
6179 vkQueueWaitIdle(m_device->m_queue);
6180 // Cleanup
6181 vkDestroySampler(m_device->device(), sampler, NULL);
6182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006184 m_errorMonitor->SetUnexpectedError(
6185 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6186 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006188 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189}
6190
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006191TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6192 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6193 ASSERT_NO_FATAL_FAILURE(InitState());
6194 ASSERT_NO_FATAL_FAILURE(InitViewport());
6195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6196
6197 VkDescriptorPoolSize ds_type_count = {};
6198 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6199 ds_type_count.descriptorCount = 1;
6200
6201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6203 ds_pool_ci.pNext = NULL;
6204 ds_pool_ci.maxSets = 1;
6205 ds_pool_ci.poolSizeCount = 1;
6206 ds_pool_ci.pPoolSizes = &ds_type_count;
6207
6208 VkDescriptorPool ds_pool;
6209 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6210 ASSERT_VK_SUCCESS(err);
6211
6212 VkDescriptorSetLayoutBinding dsl_binding = {};
6213 dsl_binding.binding = 0;
6214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6215 dsl_binding.descriptorCount = 1;
6216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6217 dsl_binding.pImmutableSamplers = NULL;
6218
6219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6221 ds_layout_ci.pNext = NULL;
6222 ds_layout_ci.bindingCount = 1;
6223 ds_layout_ci.pBindings = &dsl_binding;
6224 VkDescriptorSetLayout ds_layout;
6225 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6226 ASSERT_VK_SUCCESS(err);
6227
6228 VkDescriptorSet descriptorSet;
6229 VkDescriptorSetAllocateInfo alloc_info = {};
6230 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6231 alloc_info.descriptorSetCount = 1;
6232 alloc_info.descriptorPool = ds_pool;
6233 alloc_info.pSetLayouts = &ds_layout;
6234 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6235 ASSERT_VK_SUCCESS(err);
6236
6237 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6238 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6239 pipeline_layout_ci.pNext = NULL;
6240 pipeline_layout_ci.setLayoutCount = 1;
6241 pipeline_layout_ci.pSetLayouts = &ds_layout;
6242
6243 VkPipelineLayout pipeline_layout;
6244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6245 ASSERT_VK_SUCCESS(err);
6246
6247 // Create images to update the descriptor with
6248 VkImage image;
6249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6250 const int32_t tex_width = 32;
6251 const int32_t tex_height = 32;
6252 VkImageCreateInfo image_create_info = {};
6253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6254 image_create_info.pNext = NULL;
6255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6256 image_create_info.format = tex_format;
6257 image_create_info.extent.width = tex_width;
6258 image_create_info.extent.height = tex_height;
6259 image_create_info.extent.depth = 1;
6260 image_create_info.mipLevels = 1;
6261 image_create_info.arrayLayers = 1;
6262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6265 image_create_info.flags = 0;
6266 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6267 ASSERT_VK_SUCCESS(err);
6268 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6269 VkMemoryRequirements memory_reqs;
6270 VkDeviceMemory image_memory;
6271 bool pass;
6272 VkMemoryAllocateInfo memory_info = {};
6273 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6274 memory_info.pNext = NULL;
6275 memory_info.allocationSize = 0;
6276 memory_info.memoryTypeIndex = 0;
6277 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6278 // Allocate enough memory for image
6279 memory_info.allocationSize = memory_reqs.size;
6280 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6281 ASSERT_TRUE(pass);
6282 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6283 ASSERT_VK_SUCCESS(err);
6284 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6285 ASSERT_VK_SUCCESS(err);
6286
6287 VkImageViewCreateInfo image_view_create_info = {};
6288 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6289 image_view_create_info.image = image;
6290 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6291 image_view_create_info.format = tex_format;
6292 image_view_create_info.subresourceRange.layerCount = 1;
6293 image_view_create_info.subresourceRange.baseMipLevel = 0;
6294 image_view_create_info.subresourceRange.levelCount = 1;
6295 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6296
6297 VkImageView view;
6298 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6299 ASSERT_VK_SUCCESS(err);
6300 // Create Samplers
6301 VkSamplerCreateInfo sampler_ci = {};
6302 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6303 sampler_ci.pNext = NULL;
6304 sampler_ci.magFilter = VK_FILTER_NEAREST;
6305 sampler_ci.minFilter = VK_FILTER_NEAREST;
6306 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6307 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6308 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6309 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6310 sampler_ci.mipLodBias = 1.0;
6311 sampler_ci.anisotropyEnable = VK_FALSE;
6312 sampler_ci.maxAnisotropy = 1;
6313 sampler_ci.compareEnable = VK_FALSE;
6314 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6315 sampler_ci.minLod = 1.0;
6316 sampler_ci.maxLod = 1.0;
6317 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6318 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6319 VkSampler sampler;
6320 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6321 ASSERT_VK_SUCCESS(err);
6322 // Update descriptor with image and sampler
6323 VkDescriptorImageInfo img_info = {};
6324 img_info.sampler = sampler;
6325 img_info.imageView = view;
6326 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6327
6328 VkWriteDescriptorSet descriptor_write;
6329 memset(&descriptor_write, 0, sizeof(descriptor_write));
6330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6331 descriptor_write.dstSet = descriptorSet;
6332 descriptor_write.dstBinding = 0;
6333 descriptor_write.descriptorCount = 1;
6334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6335 descriptor_write.pImageInfo = &img_info;
6336 // Break memory binding and attempt update
6337 vkFreeMemory(m_device->device(), image_memory, nullptr);
6338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006339 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6341 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6342 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6343 m_errorMonitor->VerifyFound();
6344 // Cleanup
6345 vkDestroyImage(m_device->device(), image, NULL);
6346 vkDestroySampler(m_device->device(), sampler, NULL);
6347 vkDestroyImageView(m_device->device(), view, NULL);
6348 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6350 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6351}
6352
Karl Schultz6addd812016-02-02 17:17:23 -07006353TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006354 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6355 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006356 // Create a valid cmd buffer
6357 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006358 uint64_t fake_pipeline_handle = 0xbaad6001;
6359 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006360 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6362
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006364 m_commandBuffer->BeginCommandBuffer();
6365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006367 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006368
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006369 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 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 -06006371 Draw(1, 0, 0, 0);
6372 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006373
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006374 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 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 -07006376 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006377 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6378 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006379}
6380
Karl Schultz6addd812016-02-02 17:17:23 -07006381TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006382 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006383 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006386
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006387 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006388 ASSERT_NO_FATAL_FAILURE(InitViewport());
6389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006390 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6392 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006393
6394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6396 ds_pool_ci.pNext = NULL;
6397 ds_pool_ci.maxSets = 1;
6398 ds_pool_ci.poolSizeCount = 1;
6399 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006400
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006401 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006403 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Tony Barboureb254902015-07-15 12:50:33 -06006405 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006406 dsl_binding.binding = 0;
6407 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6408 dsl_binding.descriptorCount = 1;
6409 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6410 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006411
Tony Barboureb254902015-07-15 12:50:33 -06006412 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6414 ds_layout_ci.pNext = NULL;
6415 ds_layout_ci.bindingCount = 1;
6416 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006417 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006422 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006424 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006425 alloc_info.descriptorPool = ds_pool;
6426 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006428 ASSERT_VK_SUCCESS(err);
6429
Tony Barboureb254902015-07-15 12:50:33 -06006430 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006431 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6432 pipeline_layout_ci.pNext = NULL;
6433 pipeline_layout_ci.setLayoutCount = 1;
6434 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006435
6436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006438 ASSERT_VK_SUCCESS(err);
6439
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006442 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006444
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006445 VkPipelineObj pipe(m_device);
6446 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006447 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006448 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006449 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006450
Tony Barbour552f6c02016-12-21 14:34:07 -07006451 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6453 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6454 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006456 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006457
Chia-I Wuf7458c52015-10-26 21:10:41 +08006458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006461}
6462
Karl Schultz6addd812016-02-02 17:17:23 -07006463TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006464 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006465 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006468
6469 ASSERT_NO_FATAL_FAILURE(InitState());
6470 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6472 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006473
6474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6476 ds_pool_ci.pNext = NULL;
6477 ds_pool_ci.maxSets = 1;
6478 ds_pool_ci.poolSizeCount = 1;
6479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006480
6481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006483 ASSERT_VK_SUCCESS(err);
6484
6485 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006486 dsl_binding.binding = 0;
6487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6488 dsl_binding.descriptorCount = 1;
6489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6490 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006491
6492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6494 ds_layout_ci.pNext = NULL;
6495 ds_layout_ci.bindingCount = 1;
6496 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006497 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006498 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006499 ASSERT_VK_SUCCESS(err);
6500
6501 VkDescriptorSet descriptorSet;
6502 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006504 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006505 alloc_info.descriptorPool = ds_pool;
6506 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006508 ASSERT_VK_SUCCESS(err);
6509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006510 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511 VkWriteDescriptorSet descriptor_write;
6512 memset(&descriptor_write, 0, sizeof(descriptor_write));
6513 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6514 descriptor_write.dstSet = descriptorSet;
6515 descriptor_write.dstBinding = 0;
6516 descriptor_write.descriptorCount = 1;
6517 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6518 descriptor_write.pTexelBufferView = &view;
6519
6520 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6521
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006522 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006523
6524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6525 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6526}
6527
Mark Youngd339ba32016-05-30 13:28:35 -06006528TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006529 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 -06006530
6531 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006533 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006534
6535 ASSERT_NO_FATAL_FAILURE(InitState());
6536
6537 // Create a buffer with no bound memory and then attempt to create
6538 // a buffer view.
6539 VkBufferCreateInfo buff_ci = {};
6540 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006541 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006542 buff_ci.size = 256;
6543 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6544 VkBuffer buffer;
6545 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6546 ASSERT_VK_SUCCESS(err);
6547
6548 VkBufferViewCreateInfo buff_view_ci = {};
6549 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6550 buff_view_ci.buffer = buffer;
6551 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6552 buff_view_ci.range = VK_WHOLE_SIZE;
6553 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006555
6556 m_errorMonitor->VerifyFound();
6557 vkDestroyBuffer(m_device->device(), buffer, NULL);
6558 // If last error is success, it still created the view, so delete it.
6559 if (err == VK_SUCCESS) {
6560 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6561 }
6562}
6563
Karl Schultz6addd812016-02-02 17:17:23 -07006564TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6565 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6566 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006567 // 1. No dynamicOffset supplied
6568 // 2. Too many dynamicOffsets supplied
6569 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006570 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6572 " requires 1 dynamicOffsets, but only "
6573 "0 dynamicOffsets are left in "
6574 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006575
6576 ASSERT_NO_FATAL_FAILURE(InitState());
6577 ASSERT_NO_FATAL_FAILURE(InitViewport());
6578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6579
6580 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6582 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006583
6584 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006585 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6586 ds_pool_ci.pNext = NULL;
6587 ds_pool_ci.maxSets = 1;
6588 ds_pool_ci.poolSizeCount = 1;
6589 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006590
6591 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006593 ASSERT_VK_SUCCESS(err);
6594
6595 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006596 dsl_binding.binding = 0;
6597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6598 dsl_binding.descriptorCount = 1;
6599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6600 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006601
6602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6604 ds_layout_ci.pNext = NULL;
6605 ds_layout_ci.bindingCount = 1;
6606 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006607 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006609 ASSERT_VK_SUCCESS(err);
6610
6611 VkDescriptorSet descriptorSet;
6612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006614 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006615 alloc_info.descriptorPool = ds_pool;
6616 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006621 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6622 pipeline_layout_ci.pNext = NULL;
6623 pipeline_layout_ci.setLayoutCount = 1;
6624 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006625
6626 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006628 ASSERT_VK_SUCCESS(err);
6629
6630 // Create a buffer to update the descriptor with
6631 uint32_t qfi = 0;
6632 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6634 buffCI.size = 1024;
6635 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6636 buffCI.queueFamilyIndexCount = 1;
6637 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638
6639 VkBuffer dyub;
6640 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6641 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006642 // Allocate memory and bind to buffer so we can make it to the appropriate
6643 // error
6644 VkMemoryAllocateInfo mem_alloc = {};
6645 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6646 mem_alloc.pNext = NULL;
6647 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006648 mem_alloc.memoryTypeIndex = 0;
6649
6650 VkMemoryRequirements memReqs;
6651 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006653 if (!pass) {
6654 vkDestroyBuffer(m_device->device(), dyub, NULL);
6655 return;
6656 }
6657
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006658 VkDeviceMemory mem;
6659 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6660 ASSERT_VK_SUCCESS(err);
6661 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6662 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006663 // Correctly update descriptor to avoid "NOT_UPDATED" error
6664 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006665 buffInfo.buffer = dyub;
6666 buffInfo.offset = 0;
6667 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006668
6669 VkWriteDescriptorSet descriptor_write;
6670 memset(&descriptor_write, 0, sizeof(descriptor_write));
6671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6672 descriptor_write.dstSet = descriptorSet;
6673 descriptor_write.dstBinding = 0;
6674 descriptor_write.descriptorCount = 1;
6675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6676 descriptor_write.pBufferInfo = &buffInfo;
6677
6678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6679
Tony Barbour552f6c02016-12-21 14:34:07 -07006680 m_commandBuffer->BeginCommandBuffer();
6681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6683 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006684 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006685 uint32_t pDynOff[2] = {512, 756};
6686 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6688 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6689 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6690 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006691 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006692 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6694 " dynamic offset 512 combined with "
6695 "offset 0 and range 1024 that "
6696 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006698 char const *vsSource =
6699 "#version 450\n"
6700 "\n"
6701 "out gl_PerVertex { \n"
6702 " vec4 gl_Position;\n"
6703 "};\n"
6704 "void main(){\n"
6705 " gl_Position = vec4(1);\n"
6706 "}\n";
6707 char const *fsSource =
6708 "#version 450\n"
6709 "\n"
6710 "layout(location=0) out vec4 x;\n"
6711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6712 "void main(){\n"
6713 " x = vec4(bar.y);\n"
6714 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6717 VkPipelineObj pipe(m_device);
6718 pipe.AddShader(&vs);
6719 pipe.AddShader(&fs);
6720 pipe.AddColorAttachment();
6721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6722
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006723 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6724 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6725 VkRect2D scissor = {{0, 0}, {16, 16}};
6726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006729 // This update should succeed, but offset size of 512 will overstep buffer
6730 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006731 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6732 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006733 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006734 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006735
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006736 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006737 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006738
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006739 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6742}
6743
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006744TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006745 TEST_DESCRIPTION(
6746 "Attempt to update a descriptor with a non-sparse buffer "
6747 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006748 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006750 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6752 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006753
6754 ASSERT_NO_FATAL_FAILURE(InitState());
6755 ASSERT_NO_FATAL_FAILURE(InitViewport());
6756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6757
6758 VkDescriptorPoolSize ds_type_count = {};
6759 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6760 ds_type_count.descriptorCount = 1;
6761
6762 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6763 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6764 ds_pool_ci.pNext = NULL;
6765 ds_pool_ci.maxSets = 1;
6766 ds_pool_ci.poolSizeCount = 1;
6767 ds_pool_ci.pPoolSizes = &ds_type_count;
6768
6769 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006771 ASSERT_VK_SUCCESS(err);
6772
6773 VkDescriptorSetLayoutBinding dsl_binding = {};
6774 dsl_binding.binding = 0;
6775 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6776 dsl_binding.descriptorCount = 1;
6777 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6778 dsl_binding.pImmutableSamplers = NULL;
6779
6780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6782 ds_layout_ci.pNext = NULL;
6783 ds_layout_ci.bindingCount = 1;
6784 ds_layout_ci.pBindings = &dsl_binding;
6785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006787 ASSERT_VK_SUCCESS(err);
6788
6789 VkDescriptorSet descriptorSet;
6790 VkDescriptorSetAllocateInfo alloc_info = {};
6791 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6792 alloc_info.descriptorSetCount = 1;
6793 alloc_info.descriptorPool = ds_pool;
6794 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006796 ASSERT_VK_SUCCESS(err);
6797
6798 // Create a buffer to update the descriptor with
6799 uint32_t qfi = 0;
6800 VkBufferCreateInfo buffCI = {};
6801 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6802 buffCI.size = 1024;
6803 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6804 buffCI.queueFamilyIndexCount = 1;
6805 buffCI.pQueueFamilyIndices = &qfi;
6806
6807 VkBuffer dyub;
6808 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6809 ASSERT_VK_SUCCESS(err);
6810
6811 // Attempt to update descriptor without binding memory to it
6812 VkDescriptorBufferInfo buffInfo = {};
6813 buffInfo.buffer = dyub;
6814 buffInfo.offset = 0;
6815 buffInfo.range = 1024;
6816
6817 VkWriteDescriptorSet descriptor_write;
6818 memset(&descriptor_write, 0, sizeof(descriptor_write));
6819 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6820 descriptor_write.dstSet = descriptorSet;
6821 descriptor_write.dstBinding = 0;
6822 descriptor_write.descriptorCount = 1;
6823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6824 descriptor_write.pBufferInfo = &buffInfo;
6825
6826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6827 m_errorMonitor->VerifyFound();
6828
6829 vkDestroyBuffer(m_device->device(), dyub, NULL);
6830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6832}
6833
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006834TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006835 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006836 ASSERT_NO_FATAL_FAILURE(InitState());
6837 ASSERT_NO_FATAL_FAILURE(InitViewport());
6838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6839
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006840 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006841 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6844 pipeline_layout_ci.pushConstantRangeCount = 1;
6845 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6846
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006847 //
6848 // Check for invalid push constant ranges in pipeline layouts.
6849 //
6850 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006851 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006852 char const *msg;
6853 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854
Karl Schultzc81037d2016-05-12 08:11:23 -06006855 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6856 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6857 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6858 "vkCreatePipelineLayout() call has push constants index 0 with "
6859 "size 0."},
6860 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6861 "vkCreatePipelineLayout() call has push constants index 0 with "
6862 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006863 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006864 "vkCreatePipelineLayout() call has push constants index 0 with "
6865 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006866 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006867 "vkCreatePipelineLayout() call has push constants index 0 with "
6868 "size 0."},
6869 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6870 "vkCreatePipelineLayout() call has push constants index 0 with "
6871 "offset 1. Offset must"},
6872 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6873 "vkCreatePipelineLayout() call has push constants index 0 "
6874 "with offset "},
6875 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6876 "vkCreatePipelineLayout() call has push constants "
6877 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006878 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006879 "vkCreatePipelineLayout() call has push constants index 0 "
6880 "with offset "},
6881 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6882 "vkCreatePipelineLayout() call has push "
6883 "constants index 0 with offset "},
6884 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6885 "vkCreatePipelineLayout() call has push "
6886 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006887 }};
6888
6889 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006890 for (const auto &iter : range_tests) {
6891 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006894 m_errorMonitor->VerifyFound();
6895 if (VK_SUCCESS == err) {
6896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6897 }
6898 }
6899
6900 // Check for invalid stage flag
6901 pc_range.offset = 0;
6902 pc_range.size = 16;
6903 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006904 m_errorMonitor->SetDesiredFailureMsg(
6905 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6906 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006908 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006909 if (VK_SUCCESS == err) {
6910 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6911 }
6912
Karl Schultzc59b72d2017-02-24 15:45:05 -07006913 // Check for duplicate stage flags in a list of push constant ranges.
6914 // A shader can only have one push constant block and that block is mapped
6915 // to the push constant range that has that shader's stage flag set.
6916 // The shader's stage flag can only appear once in all the ranges, so the
6917 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006918 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006919 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006920 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006921 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006922 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006923 // Overlapping ranges are OK, but a stage flag can appear only once.
6924 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6925 {
6926 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6927 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6928 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6929 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006930 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006931 {
6932 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6933 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6934 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6935 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6936 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6937 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6938 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6939 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6940 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6941 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6942 }},
6943 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6944 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6945 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6946 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6948 {
6949 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6950 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6951 }},
6952 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6953 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6954 {VK_SHADER_STAGE_VERTEX_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 2 and 3.",
6959 }},
6960 },
6961 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006962
Karl Schultzc59b72d2017-02-24 15:45:05 -07006963 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006964 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006965 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006967 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006968 m_errorMonitor->VerifyFound();
6969 if (VK_SUCCESS == err) {
6970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6971 }
6972 }
6973
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006974 //
6975 // CmdPushConstants tests
6976 //
6977
Karl Schultzc59b72d2017-02-24 15:45:05 -07006978 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006979 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07006980 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006981 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006983 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006985 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986
6987 const uint8_t dummy_values[100] = {};
6988
6989 m_commandBuffer->BeginCommandBuffer();
6990 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006991
6992 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07006993 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006995 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 m_errorMonitor->ExpectSuccess();
6999 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7000 m_errorMonitor->VerifyNotFound();
7001 m_errorMonitor->ExpectSuccess();
7002 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7003 m_errorMonitor->VerifyNotFound();
7004 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7005 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7006 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7007 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7008 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7009 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7010 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007011 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007012 for (const auto &iter : cmd_range_tests) {
7013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7014 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7015 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007016 m_errorMonitor->VerifyFound();
7017 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007018
Tony Barbour552f6c02016-12-21 14:34:07 -07007019 m_commandBuffer->EndRenderPass();
7020 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007021 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007022}
7023
Karl Schultz6addd812016-02-02 17:17:23 -07007024TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007025 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007026 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007027
7028 ASSERT_NO_FATAL_FAILURE(InitState());
7029 ASSERT_NO_FATAL_FAILURE(InitViewport());
7030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7031
7032 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7033 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007034 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7035 ds_type_count[0].descriptorCount = 10;
7036 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7037 ds_type_count[1].descriptorCount = 2;
7038 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7039 ds_type_count[2].descriptorCount = 2;
7040 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7041 ds_type_count[3].descriptorCount = 5;
7042 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7043 // type
7044 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7045 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7046 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7050 ds_pool_ci.pNext = NULL;
7051 ds_pool_ci.maxSets = 5;
7052 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7053 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007054
7055 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007057 ASSERT_VK_SUCCESS(err);
7058
7059 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7060 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 dsl_binding[0].binding = 0;
7062 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7063 dsl_binding[0].descriptorCount = 5;
7064 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7065 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007066
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007067 // Create layout identical to set0 layout but w/ different stageFlags
7068 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 dsl_fs_stage_only.binding = 0;
7070 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7071 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007072 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7073 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007074 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7077 ds_layout_ci.pNext = NULL;
7078 ds_layout_ci.bindingCount = 1;
7079 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007080 static const uint32_t NUM_LAYOUTS = 4;
7081 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007082 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007083 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7084 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007087 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007089 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007090 dsl_binding[0].binding = 0;
7091 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007092 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007093 dsl_binding[1].binding = 1;
7094 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7095 dsl_binding[1].descriptorCount = 2;
7096 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7097 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007098 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007099 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007101 ASSERT_VK_SUCCESS(err);
7102 dsl_binding[0].binding = 0;
7103 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007104 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007106 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007107 ASSERT_VK_SUCCESS(err);
7108 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007111 ASSERT_VK_SUCCESS(err);
7112
7113 static const uint32_t NUM_SETS = 4;
7114 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7115 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007116 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007117 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007118 alloc_info.descriptorPool = ds_pool;
7119 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007122 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007123 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007126 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127
7128 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007129 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7130 pipeline_layout_ci.pNext = NULL;
7131 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7132 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007133
7134 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007137 // Create pipelineLayout with only one setLayout
7138 pipeline_layout_ci.setLayoutCount = 1;
7139 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007141 ASSERT_VK_SUCCESS(err);
7142 // Create pipelineLayout with 2 descriptor setLayout at index 0
7143 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7144 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
7147 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7148 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7149 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007151 ASSERT_VK_SUCCESS(err);
7152 // Create pipelineLayout with UB type, but stageFlags for FS only
7153 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7154 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007156 ASSERT_VK_SUCCESS(err);
7157 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7158 VkDescriptorSetLayout pl_bad_s0[2] = {};
7159 pl_bad_s0[0] = ds_layout_fs_only;
7160 pl_bad_s0[1] = ds_layout[1];
7161 pipeline_layout_ci.setLayoutCount = 2;
7162 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7163 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007165 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007166
Tobin Ehlis88452832015-12-03 09:40:56 -07007167 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007168 char const *vsSource =
7169 "#version 450\n"
7170 "\n"
7171 "out gl_PerVertex {\n"
7172 " vec4 gl_Position;\n"
7173 "};\n"
7174 "void main(){\n"
7175 " gl_Position = vec4(1);\n"
7176 "}\n";
7177 char const *fsSource =
7178 "#version 450\n"
7179 "\n"
7180 "layout(location=0) out vec4 x;\n"
7181 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7182 "void main(){\n"
7183 " x = vec4(bar.y);\n"
7184 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007185 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7186 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007187 VkPipelineObj pipe(m_device);
7188 pipe.AddShader(&vs);
7189 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007190 pipe.AddColorAttachment();
7191 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007192
Tony Barbour552f6c02016-12-21 14:34:07 -07007193 m_commandBuffer->BeginCommandBuffer();
7194 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007197 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7198 // of PSO
7199 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7200 // cmd_pipeline.c
7201 // due to the fact that cmd_alloc_dset_data() has not been called in
7202 // cmd_bind_graphics_pipeline()
7203 // TODO : Want to cause various binding incompatibility issues here to test
7204 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007205 // First cause various verify_layout_compatibility() fails
7206 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007207 // verify_set_layout_compatibility fail cases:
7208 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7211 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007212 m_errorMonitor->VerifyFound();
7213
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007214 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7217 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007218 m_errorMonitor->VerifyFound();
7219
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007220 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007221 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7222 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7224 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7225 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007226 m_errorMonitor->VerifyFound();
7227
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007228 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7229 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7232 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007233 m_errorMonitor->VerifyFound();
7234
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007235 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7236 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7238 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7239 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7240 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007241 m_errorMonitor->VerifyFound();
7242
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007243 // Cause INFO messages due to disturbing previously bound Sets
7244 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7246 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007247 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7250 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007251 m_errorMonitor->VerifyFound();
7252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7254 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7257 " newly bound as set #0 so set #1 and "
7258 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis10fad692016-07-07 12:00:36 -06007263 // Now that we're done actively using the pipelineLayout that gfx pipeline
7264 // was created with, we should be able to delete it. Do that now to verify
7265 // that validation obeys pipelineLayout lifetime
7266 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7267
Tobin Ehlis88452832015-12-03 09:40:56 -07007268 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007269 // 1. Error due to not binding required set (we actually use same code as
7270 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7272 &descriptorSet[0], 0, NULL);
7273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7274 &descriptorSet[1], 0, NULL);
7275 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 -07007276
7277 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7278 VkRect2D scissor = {{0, 0}, {16, 16}};
7279 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7280 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7281
Tobin Ehlis88452832015-12-03 09:40:56 -07007282 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007283 m_errorMonitor->VerifyFound();
7284
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007285 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007286 // 2. Error due to bound set not being compatible with PSO's
7287 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007288 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7289 &descriptorSet[0], 0, NULL);
7290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
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 Ehlis8fab6562015-12-01 09:57:09 -07007294 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007295 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7297 }
7298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7301}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007302
Karl Schultz6addd812016-02-02 17:17:23 -07007303TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7305 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007306
7307 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007309 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007310 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007313}
7314
Karl Schultz6addd812016-02-02 17:17:23 -07007315TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7316 VkResult err;
7317 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007318
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007320
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007321 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007323 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007324 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007325 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007326 cmd.commandPool = m_commandPool;
7327 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007328 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007329
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007332
7333 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007334 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007335 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7336
7337 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007338 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007339 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007340 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 -07007341 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
7343 // The error should be caught by validation of the BeginCommandBuffer call
7344 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007346 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007347 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007348}
7349
Karl Schultz6addd812016-02-02 17:17:23 -07007350TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007351 // Cause error due to Begin while recording CB
7352 // Then cause 2 errors for attempting to reset CB w/o having
7353 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7354 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007356
7357 ASSERT_NO_FATAL_FAILURE(InitState());
7358
7359 // Calls AllocateCommandBuffers
7360 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7361
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007362 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007363 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007364 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7365 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007366 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7367 cmd_buf_info.pNext = NULL;
7368 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007369 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007370
7371 // Begin CB to transition to recording state
7372 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7373 // Can't re-begin. This should trigger error
7374 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007375 m_errorMonitor->VerifyFound();
7376
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007378 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007379 // Reset attempt will trigger error due to incorrect CommandPool state
7380 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007381 m_errorMonitor->VerifyFound();
7382
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007384 // Transition CB to RECORDED state
7385 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7386 // Now attempting to Begin will implicitly reset, which triggers error
7387 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007388 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007389}
7390
Karl Schultz6addd812016-02-02 17:17:23 -07007391TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007392 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007393 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007394
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7396 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007397
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007398 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007400
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007401 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007402 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7403 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007404
7405 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007406 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7407 ds_pool_ci.pNext = NULL;
7408 ds_pool_ci.maxSets = 1;
7409 ds_pool_ci.poolSizeCount = 1;
7410 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007411
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007413 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414 ASSERT_VK_SUCCESS(err);
7415
Tony Barboureb254902015-07-15 12:50:33 -06007416 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007417 dsl_binding.binding = 0;
7418 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7419 dsl_binding.descriptorCount = 1;
7420 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7421 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007422
Tony Barboureb254902015-07-15 12:50:33 -06007423 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007424 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7425 ds_layout_ci.pNext = NULL;
7426 ds_layout_ci.bindingCount = 1;
7427 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007428
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007429 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007431 ASSERT_VK_SUCCESS(err);
7432
7433 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007434 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007436 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007437 alloc_info.descriptorPool = ds_pool;
7438 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007440 ASSERT_VK_SUCCESS(err);
7441
Tony Barboureb254902015-07-15 12:50:33 -06007442 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007443 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7444 pipeline_layout_ci.setLayoutCount = 1;
7445 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007446
7447 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 ASSERT_VK_SUCCESS(err);
7450
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007451 VkViewport vp = {}; // Just need dummy vp to point to
7452 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007453
7454 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007455 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7456 vp_state_ci.scissorCount = 1;
7457 vp_state_ci.pScissors = &sc;
7458 vp_state_ci.viewportCount = 1;
7459 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007460
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007461 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7462 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7463 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7464 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7465 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7466 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007467 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007468 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007469 rs_state_ci.lineWidth = 1.0f;
7470
7471 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7472 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7473 vi_ci.pNext = nullptr;
7474 vi_ci.vertexBindingDescriptionCount = 0;
7475 vi_ci.pVertexBindingDescriptions = nullptr;
7476 vi_ci.vertexAttributeDescriptionCount = 0;
7477 vi_ci.pVertexAttributeDescriptions = nullptr;
7478
7479 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7480 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7481 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7482
7483 VkPipelineShaderStageCreateInfo shaderStages[2];
7484 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7485
7486 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7487 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007488 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007490
Tony Barboureb254902015-07-15 12:50:33 -06007491 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007492 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7493 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007494 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7496 gp_ci.layout = pipeline_layout;
7497 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007498 gp_ci.pVertexInputState = &vi_ci;
7499 gp_ci.pInputAssemblyState = &ia_ci;
7500
7501 gp_ci.stageCount = 1;
7502 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007503
7504 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007505 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7506 pc_ci.initialDataSize = 0;
7507 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007508
7509 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007510 VkPipelineCache pipelineCache;
7511
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007513 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007515 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007516
Chia-I Wuf7458c52015-10-26 21:10:41 +08007517 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7518 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7519 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7520 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007521}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007522
Tobin Ehlis912df022015-09-17 08:46:18 -06007523/*// TODO : This test should be good, but needs Tess support in compiler to run
7524TEST_F(VkLayerTest, InvalidPatchControlPoints)
7525{
7526 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007527 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007530 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7531primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007532
Tobin Ehlis912df022015-09-17 08:46:18 -06007533 ASSERT_NO_FATAL_FAILURE(InitState());
7534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007535
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007536 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007537 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007538 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007539
7540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7542 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007543 ds_pool_ci.poolSizeCount = 1;
7544 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007545
7546 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007547 err = vkCreateDescriptorPool(m_device->device(),
7548VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007549 ASSERT_VK_SUCCESS(err);
7550
7551 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007552 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007554 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007555 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7556 dsl_binding.pImmutableSamplers = NULL;
7557
7558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007559 ds_layout_ci.sType =
7560VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007561 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007562 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007563 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564
7565 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7567&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007568 ASSERT_VK_SUCCESS(err);
7569
7570 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007571 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7572VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 ASSERT_VK_SUCCESS(err);
7574
7575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007576 pipeline_layout_ci.sType =
7577VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007579 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007580 pipeline_layout_ci.pSetLayouts = &ds_layout;
7581
7582 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007583 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7584&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007585 ASSERT_VK_SUCCESS(err);
7586
7587 VkPipelineShaderStageCreateInfo shaderStages[3];
7588 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7589
Karl Schultz6addd812016-02-02 17:17:23 -07007590 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7591this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007592 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007593 VkShaderObj
7594tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7595this);
7596 VkShaderObj
7597te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7598this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007599
Karl Schultz6addd812016-02-02 17:17:23 -07007600 shaderStages[0].sType =
7601VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007602 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007603 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007604 shaderStages[1].sType =
7605VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007606 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007607 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007608 shaderStages[2].sType =
7609VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007610 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007611 shaderStages[2].shader = te.handle();
7612
7613 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007614 iaCI.sType =
7615VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007616 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007617
7618 VkPipelineTessellationStateCreateInfo tsCI = {};
7619 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7620 tsCI.patchControlPoints = 0; // This will cause an error
7621
7622 VkGraphicsPipelineCreateInfo gp_ci = {};
7623 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7624 gp_ci.pNext = NULL;
7625 gp_ci.stageCount = 3;
7626 gp_ci.pStages = shaderStages;
7627 gp_ci.pVertexInputState = NULL;
7628 gp_ci.pInputAssemblyState = &iaCI;
7629 gp_ci.pTessellationState = &tsCI;
7630 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007631 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007632 gp_ci.pMultisampleState = NULL;
7633 gp_ci.pDepthStencilState = NULL;
7634 gp_ci.pColorBlendState = NULL;
7635 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7636 gp_ci.layout = pipeline_layout;
7637 gp_ci.renderPass = renderPass();
7638
7639 VkPipelineCacheCreateInfo pc_ci = {};
7640 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7641 pc_ci.pNext = NULL;
7642 pc_ci.initialSize = 0;
7643 pc_ci.initialData = 0;
7644 pc_ci.maxSize = 0;
7645
7646 VkPipeline pipeline;
7647 VkPipelineCache pipelineCache;
7648
Karl Schultz6addd812016-02-02 17:17:23 -07007649 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7650&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007651 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7653&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007655 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007656
Chia-I Wuf7458c52015-10-26 21:10:41 +08007657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7660 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007661}
7662*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007663
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007664TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007665 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007666
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007667 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007668
Tobin Ehlise68360f2015-10-01 11:15:13 -06007669 ASSERT_NO_FATAL_FAILURE(InitState());
7670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007671
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007672 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7674 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007675
7676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7678 ds_pool_ci.maxSets = 1;
7679 ds_pool_ci.poolSizeCount = 1;
7680 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007681
7682 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007683 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007684 ASSERT_VK_SUCCESS(err);
7685
7686 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007687 dsl_binding.binding = 0;
7688 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7689 dsl_binding.descriptorCount = 1;
7690 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
7692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7694 ds_layout_ci.bindingCount = 1;
7695 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007696
7697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007699 ASSERT_VK_SUCCESS(err);
7700
7701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007704 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007705 alloc_info.descriptorPool = ds_pool;
7706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007708 ASSERT_VK_SUCCESS(err);
7709
7710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7712 pipeline_layout_ci.setLayoutCount = 1;
7713 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007714
7715 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007717 ASSERT_VK_SUCCESS(err);
7718
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007719 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007720 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007721 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007722 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007723 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007724 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007725
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007726 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7727 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7728 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7729 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7730 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7731 rs_state_ci.depthClampEnable = VK_FALSE;
7732 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7733 rs_state_ci.depthBiasEnable = VK_FALSE;
7734
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007735 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7736 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7737 vi_ci.pNext = nullptr;
7738 vi_ci.vertexBindingDescriptionCount = 0;
7739 vi_ci.pVertexBindingDescriptions = nullptr;
7740 vi_ci.vertexAttributeDescriptionCount = 0;
7741 vi_ci.pVertexAttributeDescriptions = nullptr;
7742
7743 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7744 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7745 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7746
7747 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7748 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7749 pipe_ms_state_ci.pNext = NULL;
7750 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7751 pipe_ms_state_ci.sampleShadingEnable = 0;
7752 pipe_ms_state_ci.minSampleShading = 1.0;
7753 pipe_ms_state_ci.pSampleMask = NULL;
7754
Cody Northropeb3a6c12015-10-05 14:44:45 -06007755 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007756 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007757
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007759 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007760 shaderStages[0] = vs.GetStageCreateInfo();
7761 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007762
7763 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007764 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7765 gp_ci.stageCount = 2;
7766 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007767 gp_ci.pVertexInputState = &vi_ci;
7768 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007769 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007770 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007771 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007772 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7773 gp_ci.layout = pipeline_layout;
7774 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007775
7776 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007777 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007778
7779 VkPipeline pipeline;
7780 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007781 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007783
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007784 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007785 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007786
7787 // Check case where multiViewport is disabled and viewport count is not 1
7788 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7791 vp_state_ci.scissorCount = 0;
7792 vp_state_ci.viewportCount = 0;
7793 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7794 m_errorMonitor->VerifyFound();
7795 } else {
7796 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007797 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007798 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007799 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007800
7801 // Check is that viewportcount and scissorcount match
7802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7803 vp_state_ci.scissorCount = 1;
7804 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7805 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7806 m_errorMonitor->VerifyFound();
7807
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007808 // Check case where multiViewport is enabled and viewport count is greater than max
7809 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7812 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7813 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7815 m_errorMonitor->VerifyFound();
7816 }
7817 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007818
Chia-I Wuf7458c52015-10-26 21:10:41 +08007819 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7821 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007823}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007824
7825// 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
7826// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007827TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007828 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007829
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007830 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7831
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007833
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834 ASSERT_NO_FATAL_FAILURE(InitState());
7835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007836
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007837 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007838 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7839 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007840
7841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7843 ds_pool_ci.maxSets = 1;
7844 ds_pool_ci.poolSizeCount = 1;
7845 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007846
7847 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849 ASSERT_VK_SUCCESS(err);
7850
7851 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007852 dsl_binding.binding = 0;
7853 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7854 dsl_binding.descriptorCount = 1;
7855 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
7857 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7859 ds_layout_ci.bindingCount = 1;
7860 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007861
7862 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007863 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007864 ASSERT_VK_SUCCESS(err);
7865
7866 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007867 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007868 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007869 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007870 alloc_info.descriptorPool = ds_pool;
7871 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007872 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007873 ASSERT_VK_SUCCESS(err);
7874
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007875 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7876 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7877 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7878
7879 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7880 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7881 vi_ci.pNext = nullptr;
7882 vi_ci.vertexBindingDescriptionCount = 0;
7883 vi_ci.pVertexBindingDescriptions = nullptr;
7884 vi_ci.vertexAttributeDescriptionCount = 0;
7885 vi_ci.pVertexAttributeDescriptions = nullptr;
7886
7887 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7888 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7889 pipe_ms_state_ci.pNext = NULL;
7890 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7891 pipe_ms_state_ci.sampleShadingEnable = 0;
7892 pipe_ms_state_ci.minSampleShading = 1.0;
7893 pipe_ms_state_ci.pSampleMask = NULL;
7894
Tobin Ehlise68360f2015-10-01 11:15:13 -06007895 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007896 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7897 pipeline_layout_ci.setLayoutCount = 1;
7898 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007899
7900 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007902 ASSERT_VK_SUCCESS(err);
7903
7904 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7905 // Set scissor as dynamic to avoid second error
7906 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007907 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7908 dyn_state_ci.dynamicStateCount = 1;
7909 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910
Cody Northropeb3a6c12015-10-05 14:44:45 -06007911 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007912 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007914 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007915 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7916 // 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 +08007917 shaderStages[0] = vs.GetStageCreateInfo();
7918 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007920 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7921 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7922 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7923 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7924 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7925 rs_state_ci.depthClampEnable = VK_FALSE;
7926 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7927 rs_state_ci.depthBiasEnable = VK_FALSE;
7928
Tobin Ehlise68360f2015-10-01 11:15:13 -06007929 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007930 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7931 gp_ci.stageCount = 2;
7932 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007933 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007934 // Not setting VP state w/o dynamic vp state should cause validation error
7935 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007936 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007937 gp_ci.pVertexInputState = &vi_ci;
7938 gp_ci.pInputAssemblyState = &ia_ci;
7939 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007940 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7941 gp_ci.layout = pipeline_layout;
7942 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007943
7944 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007945 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007946
7947 VkPipeline pipeline;
7948 VkPipelineCache pipelineCache;
7949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007954 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955
Chia-I Wuf7458c52015-10-26 21:10:41 +08007956 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7957 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7958 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7959 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007960}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007961
7962// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7963// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007964TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7965 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007968
Tobin Ehlise68360f2015-10-01 11:15:13 -06007969 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007970
7971 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007972 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007973 return;
7974 }
7975
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007977
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007978 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007979 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7980 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007981
7982 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007983 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7984 ds_pool_ci.maxSets = 1;
7985 ds_pool_ci.poolSizeCount = 1;
7986 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007987
7988 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007990 ASSERT_VK_SUCCESS(err);
7991
7992 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007993 dsl_binding.binding = 0;
7994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7995 dsl_binding.descriptorCount = 1;
7996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
7998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8000 ds_layout_ci.bindingCount = 1;
8001 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
8003 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008005 ASSERT_VK_SUCCESS(err);
8006
8007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008010 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008011 alloc_info.descriptorPool = ds_pool;
8012 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008014 ASSERT_VK_SUCCESS(err);
8015
8016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8018 pipeline_layout_ci.setLayoutCount = 1;
8019 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008020
8021 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008023 ASSERT_VK_SUCCESS(err);
8024
8025 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008026 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8027 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008028 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008029 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008030 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008031
8032 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8033 // Set scissor as dynamic to avoid that error
8034 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008035 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8036 dyn_state_ci.dynamicStateCount = 1;
8037 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008038
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008039 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8040 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8041 pipe_ms_state_ci.pNext = NULL;
8042 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8043 pipe_ms_state_ci.sampleShadingEnable = 0;
8044 pipe_ms_state_ci.minSampleShading = 1.0;
8045 pipe_ms_state_ci.pSampleMask = NULL;
8046
Cody Northropeb3a6c12015-10-05 14:44:45 -06008047 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008048 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008051 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8052 // 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 +08008053 shaderStages[0] = vs.GetStageCreateInfo();
8054 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008055
Cody Northropf6622dc2015-10-06 10:33:21 -06008056 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8057 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8058 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008059 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008060 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008061 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008062 vi_ci.pVertexAttributeDescriptions = nullptr;
8063
8064 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8065 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8066 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8067
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008068 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008069 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008070 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008071 rs_ci.pNext = nullptr;
8072
Mark Youngc89c6312016-03-31 16:03:20 -06008073 VkPipelineColorBlendAttachmentState att = {};
8074 att.blendEnable = VK_FALSE;
8075 att.colorWriteMask = 0xf;
8076
Cody Northropf6622dc2015-10-06 10:33:21 -06008077 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8078 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8079 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008080 cb_ci.attachmentCount = 1;
8081 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082
Tobin Ehlise68360f2015-10-01 11:15:13 -06008083 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008084 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8085 gp_ci.stageCount = 2;
8086 gp_ci.pStages = shaderStages;
8087 gp_ci.pVertexInputState = &vi_ci;
8088 gp_ci.pInputAssemblyState = &ia_ci;
8089 gp_ci.pViewportState = &vp_state_ci;
8090 gp_ci.pRasterizationState = &rs_ci;
8091 gp_ci.pColorBlendState = &cb_ci;
8092 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008093 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008094 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8095 gp_ci.layout = pipeline_layout;
8096 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008097
8098 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008100
8101 VkPipeline pipeline;
8102 VkPipelineCache pipelineCache;
8103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008107
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008108 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008109
Tobin Ehlisd332f282015-10-02 11:00:56 -06008110 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008111 // First need to successfully create the PSO from above by setting
8112 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008113 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 -07008114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008115 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008116 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008118 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008119 m_commandBuffer->BeginCommandBuffer();
8120 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008122 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008123 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008124 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008125 Draw(1, 0, 0, 0);
8126
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008127 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008128
8129 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8130 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008133 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008134}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008135
8136// 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 -07008137// viewportCount
8138TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8139 VkResult err;
8140
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008142
8143 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144
8145 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008146 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008147 return;
8148 }
8149
Karl Schultz6addd812016-02-02 17:17:23 -07008150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8151
8152 VkDescriptorPoolSize ds_type_count = {};
8153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8154 ds_type_count.descriptorCount = 1;
8155
8156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8158 ds_pool_ci.maxSets = 1;
8159 ds_pool_ci.poolSizeCount = 1;
8160 ds_pool_ci.pPoolSizes = &ds_type_count;
8161
8162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008164 ASSERT_VK_SUCCESS(err);
8165
8166 VkDescriptorSetLayoutBinding dsl_binding = {};
8167 dsl_binding.binding = 0;
8168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8169 dsl_binding.descriptorCount = 1;
8170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8171
8172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8174 ds_layout_ci.bindingCount = 1;
8175 ds_layout_ci.pBindings = &dsl_binding;
8176
8177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008179 ASSERT_VK_SUCCESS(err);
8180
8181 VkDescriptorSet descriptorSet;
8182 VkDescriptorSetAllocateInfo alloc_info = {};
8183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8184 alloc_info.descriptorSetCount = 1;
8185 alloc_info.descriptorPool = ds_pool;
8186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008188 ASSERT_VK_SUCCESS(err);
8189
8190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8192 pipeline_layout_ci.setLayoutCount = 1;
8193 pipeline_layout_ci.pSetLayouts = &ds_layout;
8194
8195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008197 ASSERT_VK_SUCCESS(err);
8198
8199 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8200 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8201 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008202 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008203 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008204 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008205
8206 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8207 // Set scissor as dynamic to avoid that error
8208 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8209 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8210 dyn_state_ci.dynamicStateCount = 1;
8211 dyn_state_ci.pDynamicStates = &vp_state;
8212
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008213 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8214 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8215 pipe_ms_state_ci.pNext = NULL;
8216 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8217 pipe_ms_state_ci.sampleShadingEnable = 0;
8218 pipe_ms_state_ci.minSampleShading = 1.0;
8219 pipe_ms_state_ci.pSampleMask = NULL;
8220
Karl Schultz6addd812016-02-02 17:17:23 -07008221 VkPipelineShaderStageCreateInfo shaderStages[2];
8222 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8226 // 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 -07008227 shaderStages[0] = vs.GetStageCreateInfo();
8228 shaderStages[1] = fs.GetStageCreateInfo();
8229
8230 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8231 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8232 vi_ci.pNext = nullptr;
8233 vi_ci.vertexBindingDescriptionCount = 0;
8234 vi_ci.pVertexBindingDescriptions = nullptr;
8235 vi_ci.vertexAttributeDescriptionCount = 0;
8236 vi_ci.pVertexAttributeDescriptions = nullptr;
8237
8238 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8239 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8240 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8241
8242 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8243 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008244 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008245 rs_ci.pNext = nullptr;
8246
Mark Youngc89c6312016-03-31 16:03:20 -06008247 VkPipelineColorBlendAttachmentState att = {};
8248 att.blendEnable = VK_FALSE;
8249 att.colorWriteMask = 0xf;
8250
Karl Schultz6addd812016-02-02 17:17:23 -07008251 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8252 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8253 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008254 cb_ci.attachmentCount = 1;
8255 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008256
8257 VkGraphicsPipelineCreateInfo gp_ci = {};
8258 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8259 gp_ci.stageCount = 2;
8260 gp_ci.pStages = shaderStages;
8261 gp_ci.pVertexInputState = &vi_ci;
8262 gp_ci.pInputAssemblyState = &ia_ci;
8263 gp_ci.pViewportState = &vp_state_ci;
8264 gp_ci.pRasterizationState = &rs_ci;
8265 gp_ci.pColorBlendState = &cb_ci;
8266 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008267 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8269 gp_ci.layout = pipeline_layout;
8270 gp_ci.renderPass = renderPass();
8271
8272 VkPipelineCacheCreateInfo pc_ci = {};
8273 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8274
8275 VkPipeline pipeline;
8276 VkPipelineCache pipelineCache;
8277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008279 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008282 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008283
8284 // Now hit second fail case where we set scissor w/ different count than PSO
8285 // First need to successfully create the PSO from above by setting
8286 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8288 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008289
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008290 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008291 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008293 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008294 m_commandBuffer->BeginCommandBuffer();
8295 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008297 VkViewport viewports[1] = {};
8298 viewports[0].width = 8;
8299 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008300 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008301 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008302 Draw(1, 0, 0, 0);
8303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008305
Chia-I Wuf7458c52015-10-26 21:10:41 +08008306 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008310 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008311}
8312
Mark Young7394fdd2016-03-31 14:56:43 -06008313TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8314 VkResult err;
8315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008317
8318 ASSERT_NO_FATAL_FAILURE(InitState());
8319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8320
8321 VkDescriptorPoolSize ds_type_count = {};
8322 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8323 ds_type_count.descriptorCount = 1;
8324
8325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8327 ds_pool_ci.maxSets = 1;
8328 ds_pool_ci.poolSizeCount = 1;
8329 ds_pool_ci.pPoolSizes = &ds_type_count;
8330
8331 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008333 ASSERT_VK_SUCCESS(err);
8334
8335 VkDescriptorSetLayoutBinding dsl_binding = {};
8336 dsl_binding.binding = 0;
8337 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8338 dsl_binding.descriptorCount = 1;
8339 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8340
8341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8343 ds_layout_ci.bindingCount = 1;
8344 ds_layout_ci.pBindings = &dsl_binding;
8345
8346 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008348 ASSERT_VK_SUCCESS(err);
8349
8350 VkDescriptorSet descriptorSet;
8351 VkDescriptorSetAllocateInfo alloc_info = {};
8352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8353 alloc_info.descriptorSetCount = 1;
8354 alloc_info.descriptorPool = ds_pool;
8355 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008357 ASSERT_VK_SUCCESS(err);
8358
8359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8361 pipeline_layout_ci.setLayoutCount = 1;
8362 pipeline_layout_ci.pSetLayouts = &ds_layout;
8363
8364 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008366 ASSERT_VK_SUCCESS(err);
8367
8368 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8369 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8370 vp_state_ci.scissorCount = 1;
8371 vp_state_ci.pScissors = NULL;
8372 vp_state_ci.viewportCount = 1;
8373 vp_state_ci.pViewports = NULL;
8374
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008376 // Set scissor as dynamic to avoid that error
8377 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8378 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8379 dyn_state_ci.dynamicStateCount = 2;
8380 dyn_state_ci.pDynamicStates = dynamic_states;
8381
8382 VkPipelineShaderStageCreateInfo shaderStages[2];
8383 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008387 this); // TODO - We shouldn't need a fragment shader
8388 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008389 shaderStages[0] = vs.GetStageCreateInfo();
8390 shaderStages[1] = fs.GetStageCreateInfo();
8391
8392 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8393 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8394 vi_ci.pNext = nullptr;
8395 vi_ci.vertexBindingDescriptionCount = 0;
8396 vi_ci.pVertexBindingDescriptions = nullptr;
8397 vi_ci.vertexAttributeDescriptionCount = 0;
8398 vi_ci.pVertexAttributeDescriptions = nullptr;
8399
8400 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8401 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8402 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8403
8404 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8405 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8406 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008407 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008408
Mark Young47107952016-05-02 15:59:55 -06008409 // Check too low (line width of -1.0f).
8410 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008411
8412 VkPipelineColorBlendAttachmentState att = {};
8413 att.blendEnable = VK_FALSE;
8414 att.colorWriteMask = 0xf;
8415
8416 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8417 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8418 cb_ci.pNext = nullptr;
8419 cb_ci.attachmentCount = 1;
8420 cb_ci.pAttachments = &att;
8421
8422 VkGraphicsPipelineCreateInfo gp_ci = {};
8423 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8424 gp_ci.stageCount = 2;
8425 gp_ci.pStages = shaderStages;
8426 gp_ci.pVertexInputState = &vi_ci;
8427 gp_ci.pInputAssemblyState = &ia_ci;
8428 gp_ci.pViewportState = &vp_state_ci;
8429 gp_ci.pRasterizationState = &rs_ci;
8430 gp_ci.pColorBlendState = &cb_ci;
8431 gp_ci.pDynamicState = &dyn_state_ci;
8432 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8433 gp_ci.layout = pipeline_layout;
8434 gp_ci.renderPass = renderPass();
8435
8436 VkPipelineCacheCreateInfo pc_ci = {};
8437 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8438
8439 VkPipeline pipeline;
8440 VkPipelineCache pipelineCache;
8441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008443 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008445
8446 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008447 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008450
8451 // Check too high (line width of 65536.0f).
8452 rs_ci.lineWidth = 65536.0f;
8453
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008455 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008457
8458 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008459 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008460
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008462
8463 dyn_state_ci.dynamicStateCount = 3;
8464
8465 rs_ci.lineWidth = 1.0f;
8466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008468 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008470 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008472
8473 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008474 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 m_errorMonitor->VerifyFound();
8476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008478
8479 // Check too high with dynamic setting.
8480 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8481 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008482 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008483
8484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008488 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008489}
8490
Karl Schultz6addd812016-02-02 17:17:23 -07008491TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008492 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008494 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008495
8496 ASSERT_NO_FATAL_FAILURE(InitState());
8497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008498
Tony Barbour552f6c02016-12-21 14:34:07 -07008499 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008500 // Don't care about RenderPass handle b/c error should be flagged before
8501 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008503
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008504 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008505}
8506
Karl Schultz6addd812016-02-02 17:17:23 -07008507TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008508 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8510 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008511
8512 ASSERT_NO_FATAL_FAILURE(InitState());
8513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008514
Tony Barbour552f6c02016-12-21 14:34:07 -07008515 m_commandBuffer->BeginCommandBuffer();
8516 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008517 // Just create a dummy Renderpass that's non-NULL so we can get to the
8518 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008521 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008522}
8523
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008524TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008525 TEST_DESCRIPTION(
8526 "Begin a renderPass where clearValueCount is less than"
8527 "the number of renderPass attachments that use loadOp"
8528 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008529
8530 ASSERT_NO_FATAL_FAILURE(InitState());
8531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8532
8533 // Create a renderPass with a single attachment that uses loadOp CLEAR
8534 VkAttachmentReference attach = {};
8535 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8536 VkSubpassDescription subpass = {};
8537 subpass.inputAttachmentCount = 1;
8538 subpass.pInputAttachments = &attach;
8539 VkRenderPassCreateInfo rpci = {};
8540 rpci.subpassCount = 1;
8541 rpci.pSubpasses = &subpass;
8542 rpci.attachmentCount = 1;
8543 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008544 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008545 // Set loadOp to CLEAR
8546 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8547 rpci.pAttachments = &attach_desc;
8548 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8549 VkRenderPass rp;
8550 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8551
8552 VkCommandBufferInheritanceInfo hinfo = {};
8553 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8554 hinfo.renderPass = VK_NULL_HANDLE;
8555 hinfo.subpass = 0;
8556 hinfo.framebuffer = VK_NULL_HANDLE;
8557 hinfo.occlusionQueryEnable = VK_FALSE;
8558 hinfo.queryFlags = 0;
8559 hinfo.pipelineStatistics = 0;
8560 VkCommandBufferBeginInfo info = {};
8561 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8562 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8563 info.pInheritanceInfo = &hinfo;
8564
8565 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8566 VkRenderPassBeginInfo rp_begin = {};
8567 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8568 rp_begin.pNext = NULL;
8569 rp_begin.renderPass = renderPass();
8570 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008571 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008572
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008576
8577 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008578
8579 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008580}
8581
Slawomir Cygan0808f392016-11-28 17:53:23 +01008582TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008583 TEST_DESCRIPTION(
8584 "Begin a renderPass where clearValueCount is greater than"
8585 "the number of renderPass attachments that use loadOp"
8586 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008587
8588 ASSERT_NO_FATAL_FAILURE(InitState());
8589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8590
8591 // Create a renderPass with a single attachment that uses loadOp CLEAR
8592 VkAttachmentReference attach = {};
8593 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8594 VkSubpassDescription subpass = {};
8595 subpass.inputAttachmentCount = 1;
8596 subpass.pInputAttachments = &attach;
8597 VkRenderPassCreateInfo rpci = {};
8598 rpci.subpassCount = 1;
8599 rpci.pSubpasses = &subpass;
8600 rpci.attachmentCount = 1;
8601 VkAttachmentDescription attach_desc = {};
8602 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8603 // Set loadOp to CLEAR
8604 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8605 rpci.pAttachments = &attach_desc;
8606 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8607 VkRenderPass rp;
8608 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8609
8610 VkCommandBufferBeginInfo info = {};
8611 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8612 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8613
8614 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8615 VkRenderPassBeginInfo rp_begin = {};
8616 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8617 rp_begin.pNext = NULL;
8618 rp_begin.renderPass = renderPass();
8619 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008620 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8623 " has a clearValueCount of"
8624 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008625
8626 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8627
8628 m_errorMonitor->VerifyFound();
8629
8630 vkDestroyRenderPass(m_device->device(), rp, NULL);
8631}
8632
Cody Northrop3bb4d962016-05-09 16:15:57 -06008633TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008634 TEST_DESCRIPTION("End a command buffer with an active render pass");
8635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8637 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008638
8639 ASSERT_NO_FATAL_FAILURE(InitState());
8640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8641
Tony Barbour552f6c02016-12-21 14:34:07 -07008642 m_commandBuffer->BeginCommandBuffer();
8643 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8644 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008645
8646 m_errorMonitor->VerifyFound();
8647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8649 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008650}
8651
Karl Schultz6addd812016-02-02 17:17:23 -07008652TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008653 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8655 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008656
8657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008659
Tony Barbour552f6c02016-12-21 14:34:07 -07008660 m_commandBuffer->BeginCommandBuffer();
8661 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008662
8663 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008664 vk_testing::Buffer dstBuffer;
8665 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008666
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008667 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008668
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008669 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Karl Schultz6addd812016-02-02 17:17:23 -07008687 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008688 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8689 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8690 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008692 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693}
8694
Karl Schultz6addd812016-02-02 17:17:23 -07008695TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8698 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
8700 ASSERT_NO_FATAL_FAILURE(InitState());
8701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
Tony Barbour552f6c02016-12-21 14:34:07 -07008703 m_commandBuffer->BeginCommandBuffer();
8704 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008705
Michael Lentine0a369f62016-02-03 16:51:46 -06008706 VkClearColorValue clear_color;
8707 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008708 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8710 const int32_t tex_width = 32;
8711 const int32_t tex_height = 32;
8712 VkImageCreateInfo image_create_info = {};
8713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8714 image_create_info.pNext = NULL;
8715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8716 image_create_info.format = tex_format;
8717 image_create_info.extent.width = tex_width;
8718 image_create_info.extent.height = tex_height;
8719 image_create_info.extent.depth = 1;
8720 image_create_info.mipLevels = 1;
8721 image_create_info.arrayLayers = 1;
8722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8723 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8724 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008726 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008728
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008729 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008730
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008731 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008733
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008734 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008735}
8736
Karl Schultz6addd812016-02-02 17:17:23 -07008737TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008738 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8740 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008741
8742 ASSERT_NO_FATAL_FAILURE(InitState());
8743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008744
Tony Barbour552f6c02016-12-21 14:34:07 -07008745 m_commandBuffer->BeginCommandBuffer();
8746 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747
8748 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008749 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008750 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8752 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8753 image_create_info.extent.width = 64;
8754 image_create_info.extent.height = 64;
8755 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8756 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008758 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008763 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8764 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008766 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008767}
8768
Karl Schultz6addd812016-02-02 17:17:23 -07008769TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008770 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008771 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8774 "vkCmdClearAttachments(): This call "
8775 "must be issued inside an active "
8776 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008777
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778 ASSERT_NO_FATAL_FAILURE(InitState());
8779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008780
8781 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008782 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008783 ASSERT_VK_SUCCESS(err);
8784
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008785 VkClearAttachment color_attachment;
8786 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8787 color_attachment.clearValue.color.float32[0] = 0;
8788 color_attachment.clearValue.color.float32[1] = 0;
8789 color_attachment.clearValue.color.float32[2] = 0;
8790 color_attachment.clearValue.color.float32[3] = 0;
8791 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008792 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008795 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008796}
8797
Chris Forbes3b97e932016-09-07 11:29:24 +12008798TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008799 TEST_DESCRIPTION(
8800 "Test that an error is produced when CmdNextSubpass is "
8801 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8804 "vkCmdNextSubpass(): Attempted to advance "
8805 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008806
8807 ASSERT_NO_FATAL_FAILURE(InitState());
8808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8809
Tony Barbour552f6c02016-12-21 14:34:07 -07008810 m_commandBuffer->BeginCommandBuffer();
8811 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008812
8813 // error here.
8814 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8815 m_errorMonitor->VerifyFound();
8816
Tony Barbour552f6c02016-12-21 14:34:07 -07008817 m_commandBuffer->EndRenderPass();
8818 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008819}
8820
Chris Forbes6d624702016-09-07 13:57:05 +12008821TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008822 TEST_DESCRIPTION(
8823 "Test that an error is produced when CmdEndRenderPass is "
8824 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8827 "vkCmdEndRenderPass(): Called before reaching "
8828 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008829
8830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8832 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008833
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008834 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008835
8836 VkRenderPass rp;
8837 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8838 ASSERT_VK_SUCCESS(err);
8839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008840 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008841
8842 VkFramebuffer fb;
8843 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8844 ASSERT_VK_SUCCESS(err);
8845
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008846 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 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 +12008849
8850 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8851
8852 // Error here.
8853 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8854 m_errorMonitor->VerifyFound();
8855
8856 // Clean up.
8857 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8858 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8859}
8860
Karl Schultz9e66a292016-04-21 15:57:51 -06008861TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8862 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8864 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008865
8866 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008867 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008868
8869 VkBufferMemoryBarrier buf_barrier = {};
8870 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8871 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8872 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8873 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8874 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8875 buf_barrier.buffer = VK_NULL_HANDLE;
8876 buf_barrier.offset = 0;
8877 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008878 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8879 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008880
8881 m_errorMonitor->VerifyFound();
8882}
8883
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008884TEST_F(VkLayerTest, InvalidBarriers) {
8885 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008888
8889 ASSERT_NO_FATAL_FAILURE(InitState());
8890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8891
8892 VkMemoryBarrier mem_barrier = {};
8893 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8894 mem_barrier.pNext = NULL;
8895 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8896 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008897 m_commandBuffer->BeginCommandBuffer();
8898 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008901 &mem_barrier, 0, nullptr, 0, nullptr);
8902 m_errorMonitor->VerifyFound();
8903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008905 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008906 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 -06008907 ASSERT_TRUE(image.initialized());
8908 VkImageMemoryBarrier img_barrier = {};
8909 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8910 img_barrier.pNext = NULL;
8911 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8912 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8913 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8914 // New layout can't be UNDEFINED
8915 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8916 img_barrier.image = image.handle();
8917 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8918 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8919 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8920 img_barrier.subresourceRange.baseArrayLayer = 0;
8921 img_barrier.subresourceRange.baseMipLevel = 0;
8922 img_barrier.subresourceRange.layerCount = 1;
8923 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8925 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008926 m_errorMonitor->VerifyFound();
8927 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8928
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8930 "Subresource must have the sum of the "
8931 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008932 // baseArrayLayer + layerCount must be <= image's arrayLayers
8933 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8935 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008936 m_errorMonitor->VerifyFound();
8937 img_barrier.subresourceRange.baseArrayLayer = 0;
8938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008940 // baseMipLevel + levelCount must be <= image's mipLevels
8941 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8943 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008944 m_errorMonitor->VerifyFound();
8945 img_barrier.subresourceRange.baseMipLevel = 0;
8946
Mike Weiblen7053aa32017-01-25 15:21:10 -07008947 // levelCount must be non-zero.
8948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8949 img_barrier.subresourceRange.levelCount = 0;
8950 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8951 nullptr, 0, nullptr, 1, &img_barrier);
8952 m_errorMonitor->VerifyFound();
8953 img_barrier.subresourceRange.levelCount = 1;
8954
8955 // layerCount must be non-zero.
8956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8957 img_barrier.subresourceRange.layerCount = 0;
8958 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8959 nullptr, 0, nullptr, 1, &img_barrier);
8960 m_errorMonitor->VerifyFound();
8961 img_barrier.subresourceRange.layerCount = 1;
8962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 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 -06008964 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008965 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8966 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008967 VkBufferMemoryBarrier buf_barrier = {};
8968 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8969 buf_barrier.pNext = NULL;
8970 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8971 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8972 buf_barrier.buffer = buffer.handle();
8973 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8974 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8975 buf_barrier.offset = 0;
8976 buf_barrier.size = VK_WHOLE_SIZE;
8977 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8979 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008980 m_errorMonitor->VerifyFound();
8981 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008984 buf_barrier.offset = 257;
8985 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008986 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8987 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008988 m_errorMonitor->VerifyFound();
8989 buf_barrier.offset = 0;
8990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008992 buf_barrier.size = 257;
8993 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8995 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008996 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008998 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008999 m_errorMonitor->SetDesiredFailureMsg(
9000 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009001 "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 -06009002 VkDepthStencilObj ds_image(m_device);
9003 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9004 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009005 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9006 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009007 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009008
9009 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009010 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9012 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009013 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009014
9015 // Having anything other than DEPTH or STENCIL is an error
9016 m_errorMonitor->SetDesiredFailureMsg(
9017 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9018 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9019 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9020 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9021 nullptr, 0, nullptr, 1, &img_barrier);
9022 m_errorMonitor->VerifyFound();
9023
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009024 // Now test depth-only
9025 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9027 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 VkDepthStencilObj d_image(m_device);
9029 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9030 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009031 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009032 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009033 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009034
9035 // DEPTH bit must be set
9036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9037 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009038 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009039 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9040 0, nullptr, 0, nullptr, 1, &img_barrier);
9041 m_errorMonitor->VerifyFound();
9042
9043 // No bits other than DEPTH may be set
9044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9045 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9046 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009047 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9048 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009049 m_errorMonitor->VerifyFound();
9050 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009051
9052 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9054 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009055 VkDepthStencilObj s_image(m_device);
9056 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9057 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009059 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009060 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009061 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9063 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009064 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009065 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9066 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009067 m_errorMonitor->VerifyFound();
9068 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009069
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009070 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009071 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009072 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 -06009073 ASSERT_TRUE(c_image.initialized());
9074 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9075 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9076 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009077
9078 // COLOR bit must be set
9079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9080 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009081 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009082 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9083 nullptr, 0, nullptr, 1, &img_barrier);
9084 m_errorMonitor->VerifyFound();
9085
9086 // No bits other than COLOR may be set
9087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9088 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9089 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9091 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009092 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009093
9094 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9095
9096 // Create command pool with incompatible queueflags
9097 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9098 uint32_t queue_family_index = UINT32_MAX;
9099 for (uint32_t i = 0; i < queue_props.size(); i++) {
9100 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9101 queue_family_index = i;
9102 break;
9103 }
9104 }
9105 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009106 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009107 return;
9108 }
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9110
9111 VkCommandPool command_pool;
9112 VkCommandPoolCreateInfo pool_create_info{};
9113 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9114 pool_create_info.queueFamilyIndex = queue_family_index;
9115 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9116 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9117
9118 // Allocate a command buffer
9119 VkCommandBuffer bad_command_buffer;
9120 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9121 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9122 command_buffer_allocate_info.commandPool = command_pool;
9123 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9124 command_buffer_allocate_info.commandBufferCount = 1;
9125 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9126
9127 VkCommandBufferBeginInfo cbbi = {};
9128 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9129 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9130 buf_barrier.offset = 0;
9131 buf_barrier.size = VK_WHOLE_SIZE;
9132 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9133 &buf_barrier, 0, nullptr);
9134 m_errorMonitor->VerifyFound();
9135
9136 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9137 vkEndCommandBuffer(bad_command_buffer);
9138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009139 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009140 return;
9141 }
9142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9143 VkEvent event;
9144 VkEventCreateInfo event_create_info{};
9145 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9146 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9147 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9148 nullptr, 0, nullptr);
9149 m_errorMonitor->VerifyFound();
9150
9151 vkEndCommandBuffer(bad_command_buffer);
9152 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009153}
9154
Tony Barbour18ba25c2016-09-29 13:42:40 -06009155TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9156 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9157
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009159 ASSERT_NO_FATAL_FAILURE(InitState());
9160 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009161 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 -06009162 ASSERT_TRUE(image.initialized());
9163
9164 VkImageMemoryBarrier barrier = {};
9165 VkImageSubresourceRange range;
9166 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9167 barrier.srcAccessMask = 0;
9168 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9169 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9170 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9171 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9172 barrier.image = image.handle();
9173 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9174 range.baseMipLevel = 0;
9175 range.levelCount = 1;
9176 range.baseArrayLayer = 0;
9177 range.layerCount = 1;
9178 barrier.subresourceRange = range;
9179 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9180 cmdbuf.BeginCommandBuffer();
9181 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9182 &barrier);
9183 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9184 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9185 barrier.srcAccessMask = 0;
9186 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9187 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9188 &barrier);
9189
9190 m_errorMonitor->VerifyFound();
9191}
9192
Karl Schultz6addd812016-02-02 17:17:23 -07009193TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009194 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009195 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009198
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009199 ASSERT_NO_FATAL_FAILURE(InitState());
9200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009201 uint32_t qfi = 0;
9202 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009203 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9204 buffCI.size = 1024;
9205 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9206 buffCI.queueFamilyIndexCount = 1;
9207 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009208
9209 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009210 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009211 ASSERT_VK_SUCCESS(err);
9212
Tony Barbour552f6c02016-12-21 14:34:07 -07009213 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009214 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009215 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9216 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009217 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009218 m_errorMonitor->SetUnexpectedError(
9219 "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 -06009220 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009221
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009222 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009223
Chia-I Wuf7458c52015-10-26 21:10:41 +08009224 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009225}
9226
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009227TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9228 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9230 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9231 "of the indices specified when the device was created, via the "
9232 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009233
9234 ASSERT_NO_FATAL_FAILURE(InitState());
9235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9236 VkBufferCreateInfo buffCI = {};
9237 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9238 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009239 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009240 buffCI.queueFamilyIndexCount = 1;
9241 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009242 uint32_t qfi[2];
9243 qfi[0] = 777;
9244
9245 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009246 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009247
9248 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009249 m_errorMonitor->SetUnexpectedError(
9250 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009251 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9252
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009253 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009254
9255 if (m_device->queue_props.size() > 2) {
9256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9257
9258 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9259 buffCI.queueFamilyIndexCount = 2;
9260 qfi[0] = 1;
9261 qfi[1] = 2;
9262 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9263 VkDeviceMemory mem;
9264 VkMemoryRequirements mem_reqs;
9265 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9266
9267 VkMemoryAllocateInfo alloc_info = {};
9268 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9269 alloc_info.allocationSize = 1024;
9270 bool pass = false;
9271 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9272 if (!pass) {
9273 vkDestroyBuffer(m_device->device(), ib, NULL);
9274 return;
9275 }
9276 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9277 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9278
9279 m_commandBuffer->begin();
9280 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9281 m_commandBuffer->end();
9282 QueueCommandBuffer(false);
9283 m_errorMonitor->VerifyFound();
9284 }
9285
Tony Barbourdf4c0042016-06-01 15:55:43 -06009286 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009287}
9288
Karl Schultz6addd812016-02-02 17:17:23 -07009289TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009290 TEST_DESCRIPTION(
9291 "Attempt vkCmdExecuteCommands with a primary command buffer"
9292 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009293
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009294 ASSERT_NO_FATAL_FAILURE(InitState());
9295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009296
Chris Forbesf29a84f2016-10-06 18:39:28 +13009297 // An empty primary command buffer
9298 VkCommandBufferObj cb(m_device, m_commandPool);
9299 cb.BeginCommandBuffer();
9300 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009301
Chris Forbesf29a84f2016-10-06 18:39:28 +13009302 m_commandBuffer->BeginCommandBuffer();
9303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9304 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009305
Chris Forbesf29a84f2016-10-06 18:39:28 +13009306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9307 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009309
9310 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009311}
9312
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009313TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009314 TEST_DESCRIPTION(
9315 "Attempt to update descriptor sets for images and buffers "
9316 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009317 VkResult err;
9318
9319 ASSERT_NO_FATAL_FAILURE(InitState());
9320 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9321 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9322 ds_type_count[i].type = VkDescriptorType(i);
9323 ds_type_count[i].descriptorCount = 1;
9324 }
9325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9327 ds_pool_ci.pNext = NULL;
9328 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9329 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9330 ds_pool_ci.pPoolSizes = ds_type_count;
9331
9332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009334 ASSERT_VK_SUCCESS(err);
9335
9336 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009338 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9339 dsl_binding[i].binding = 0;
9340 dsl_binding[i].descriptorType = VkDescriptorType(i);
9341 dsl_binding[i].descriptorCount = 1;
9342 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9343 dsl_binding[i].pImmutableSamplers = NULL;
9344 }
9345
9346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9348 ds_layout_ci.pNext = NULL;
9349 ds_layout_ci.bindingCount = 1;
9350 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9351 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9352 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009354 ASSERT_VK_SUCCESS(err);
9355 }
9356 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9357 VkDescriptorSetAllocateInfo alloc_info = {};
9358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9359 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9360 alloc_info.descriptorPool = ds_pool;
9361 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009363 ASSERT_VK_SUCCESS(err);
9364
9365 // Create a buffer & bufferView to be used for invalid updates
9366 VkBufferCreateInfo buff_ci = {};
9367 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009368 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009369 buff_ci.size = 256;
9370 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009371 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009372 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9373 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009374
9375 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9376 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9377 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9378 ASSERT_VK_SUCCESS(err);
9379
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009380 VkMemoryRequirements mem_reqs;
9381 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9382 VkMemoryAllocateInfo mem_alloc_info = {};
9383 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9384 mem_alloc_info.pNext = NULL;
9385 mem_alloc_info.memoryTypeIndex = 0;
9386 mem_alloc_info.allocationSize = mem_reqs.size;
9387 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9388 if (!pass) {
9389 vkDestroyBuffer(m_device->device(), buffer, NULL);
9390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9391 return;
9392 }
9393 VkDeviceMemory mem;
9394 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9395 ASSERT_VK_SUCCESS(err);
9396 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9397 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009398
9399 VkBufferViewCreateInfo buff_view_ci = {};
9400 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9401 buff_view_ci.buffer = buffer;
9402 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9403 buff_view_ci.range = VK_WHOLE_SIZE;
9404 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009405 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009406 ASSERT_VK_SUCCESS(err);
9407
Tony Barbour415497c2017-01-24 10:06:09 -07009408 // Now get resources / view for storage_texel_buffer
9409 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9410 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9411 if (!pass) {
9412 vkDestroyBuffer(m_device->device(), buffer, NULL);
9413 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9414 vkFreeMemory(m_device->device(), mem, NULL);
9415 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9417 return;
9418 }
9419 VkDeviceMemory storage_texel_buffer_mem;
9420 VkBufferView storage_texel_buffer_view;
9421 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9422 ASSERT_VK_SUCCESS(err);
9423 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9424 ASSERT_VK_SUCCESS(err);
9425 buff_view_ci.buffer = storage_texel_buffer;
9426 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9427 ASSERT_VK_SUCCESS(err);
9428
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009429 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009430 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009431 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009432 image_ci.format = VK_FORMAT_UNDEFINED;
9433 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9434 VkFormat format = static_cast<VkFormat>(f);
9435 VkFormatProperties fProps = m_device->format_properties(format);
9436 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9437 image_ci.format = format;
9438 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9439 break;
9440 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9441 image_ci.format = format;
9442 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9443 break;
9444 }
9445 }
9446 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9447 return;
9448 }
9449
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009450 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9451 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009452 image_ci.extent.width = 64;
9453 image_ci.extent.height = 64;
9454 image_ci.extent.depth = 1;
9455 image_ci.mipLevels = 1;
9456 image_ci.arrayLayers = 1;
9457 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009458 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009459 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009460 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9461 VkImage image;
9462 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9463 ASSERT_VK_SUCCESS(err);
9464 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009465 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009466
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009467 VkMemoryAllocateInfo mem_alloc = {};
9468 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9469 mem_alloc.pNext = NULL;
9470 mem_alloc.allocationSize = 0;
9471 mem_alloc.memoryTypeIndex = 0;
9472 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9473 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 ASSERT_TRUE(pass);
9476 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9477 ASSERT_VK_SUCCESS(err);
9478 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9479 ASSERT_VK_SUCCESS(err);
9480 // Now create view for image
9481 VkImageViewCreateInfo image_view_ci = {};
9482 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9483 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009484 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9486 image_view_ci.subresourceRange.layerCount = 1;
9487 image_view_ci.subresourceRange.baseArrayLayer = 0;
9488 image_view_ci.subresourceRange.levelCount = 1;
9489 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9490 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009491 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009492 ASSERT_VK_SUCCESS(err);
9493
9494 VkDescriptorBufferInfo buff_info = {};
9495 buff_info.buffer = buffer;
9496 VkDescriptorImageInfo img_info = {};
9497 img_info.imageView = image_view;
9498 VkWriteDescriptorSet descriptor_write = {};
9499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9500 descriptor_write.dstBinding = 0;
9501 descriptor_write.descriptorCount = 1;
9502 descriptor_write.pTexelBufferView = &buff_view;
9503 descriptor_write.pBufferInfo = &buff_info;
9504 descriptor_write.pImageInfo = &img_info;
9505
9506 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009507 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009508 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9509 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9510 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9511 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9512 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9513 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9514 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9515 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9516 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9517 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9518 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009519 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009520 // Start loop at 1 as SAMPLER desc type has no usage bit error
9521 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009522 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9523 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9524 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9525 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009526 descriptor_write.descriptorType = VkDescriptorType(i);
9527 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009529
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009531
9532 m_errorMonitor->VerifyFound();
9533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009534 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9535 descriptor_write.pTexelBufferView = &buff_view;
9536 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009537 }
Tony Barbour415497c2017-01-24 10:06:09 -07009538
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9540 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009541 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009542 vkDestroyImageView(m_device->device(), image_view, NULL);
9543 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009544 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009545 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009546 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009547 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009548 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9550}
9551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009553 TEST_DESCRIPTION(
9554 "Attempt to update buffer descriptor set that has incorrect "
9555 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9556 "1. offset value greater than buffer size\n"
9557 "2. range value of 0\n"
9558 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009559 VkResult err;
9560
9561 ASSERT_NO_FATAL_FAILURE(InitState());
9562 VkDescriptorPoolSize ds_type_count = {};
9563 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9564 ds_type_count.descriptorCount = 1;
9565
9566 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9567 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9568 ds_pool_ci.pNext = NULL;
9569 ds_pool_ci.maxSets = 1;
9570 ds_pool_ci.poolSizeCount = 1;
9571 ds_pool_ci.pPoolSizes = &ds_type_count;
9572
9573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009575 ASSERT_VK_SUCCESS(err);
9576
9577 // Create layout with single uniform buffer descriptor
9578 VkDescriptorSetLayoutBinding dsl_binding = {};
9579 dsl_binding.binding = 0;
9580 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9581 dsl_binding.descriptorCount = 1;
9582 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9583 dsl_binding.pImmutableSamplers = NULL;
9584
9585 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9586 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9587 ds_layout_ci.pNext = NULL;
9588 ds_layout_ci.bindingCount = 1;
9589 ds_layout_ci.pBindings = &dsl_binding;
9590 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009592 ASSERT_VK_SUCCESS(err);
9593
9594 VkDescriptorSet descriptor_set = {};
9595 VkDescriptorSetAllocateInfo alloc_info = {};
9596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9597 alloc_info.descriptorSetCount = 1;
9598 alloc_info.descriptorPool = ds_pool;
9599 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009601 ASSERT_VK_SUCCESS(err);
9602
9603 // Create a buffer to be used for invalid updates
9604 VkBufferCreateInfo buff_ci = {};
9605 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9606 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9607 buff_ci.size = 256;
9608 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9609 VkBuffer buffer;
9610 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9611 ASSERT_VK_SUCCESS(err);
9612 // Have to bind memory to buffer before descriptor update
9613 VkMemoryAllocateInfo mem_alloc = {};
9614 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9615 mem_alloc.pNext = NULL;
9616 mem_alloc.allocationSize = 256;
9617 mem_alloc.memoryTypeIndex = 0;
9618
9619 VkMemoryRequirements mem_reqs;
9620 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009622 if (!pass) {
9623 vkDestroyBuffer(m_device->device(), buffer, NULL);
9624 return;
9625 }
9626
9627 VkDeviceMemory mem;
9628 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9629 ASSERT_VK_SUCCESS(err);
9630 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9631 ASSERT_VK_SUCCESS(err);
9632
9633 VkDescriptorBufferInfo buff_info = {};
9634 buff_info.buffer = buffer;
9635 // First make offset 1 larger than buffer size
9636 buff_info.offset = 257;
9637 buff_info.range = VK_WHOLE_SIZE;
9638 VkWriteDescriptorSet descriptor_write = {};
9639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9640 descriptor_write.dstBinding = 0;
9641 descriptor_write.descriptorCount = 1;
9642 descriptor_write.pTexelBufferView = nullptr;
9643 descriptor_write.pBufferInfo = &buff_info;
9644 descriptor_write.pImageInfo = nullptr;
9645
9646 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9647 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009649
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009650 m_errorMonitor->SetUnexpectedError(
9651 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9652 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009653 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9654
9655 m_errorMonitor->VerifyFound();
9656 // Now cause error due to range of 0
9657 buff_info.offset = 0;
9658 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009660
9661 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9662
9663 m_errorMonitor->VerifyFound();
9664 // Now cause error due to range exceeding buffer size - offset
9665 buff_info.offset = 128;
9666 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009668
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009669 m_errorMonitor->SetUnexpectedError(
9670 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9671 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9673
9674 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009675 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9677 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009678 m_errorMonitor->SetUnexpectedError(
9679 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009680 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9681 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9682}
9683
Tobin Ehlis845887e2017-02-02 19:01:44 -07009684TEST_F(VkLayerTest, DSBufferLimitErrors) {
9685 TEST_DESCRIPTION(
9686 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9687 "Test cases include:\n"
9688 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9689 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9690 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9691 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9692 VkResult err;
9693
9694 ASSERT_NO_FATAL_FAILURE(InitState());
9695 VkDescriptorPoolSize ds_type_count[2] = {};
9696 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9697 ds_type_count[0].descriptorCount = 1;
9698 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9699 ds_type_count[1].descriptorCount = 1;
9700
9701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9703 ds_pool_ci.pNext = NULL;
9704 ds_pool_ci.maxSets = 1;
9705 ds_pool_ci.poolSizeCount = 2;
9706 ds_pool_ci.pPoolSizes = ds_type_count;
9707
9708 VkDescriptorPool ds_pool;
9709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9710 ASSERT_VK_SUCCESS(err);
9711
9712 // Create layout with single uniform buffer & single storage buffer descriptor
9713 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9714 dsl_binding[0].binding = 0;
9715 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9716 dsl_binding[0].descriptorCount = 1;
9717 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9718 dsl_binding[0].pImmutableSamplers = NULL;
9719 dsl_binding[1].binding = 1;
9720 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9721 dsl_binding[1].descriptorCount = 1;
9722 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9723 dsl_binding[1].pImmutableSamplers = NULL;
9724
9725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9727 ds_layout_ci.pNext = NULL;
9728 ds_layout_ci.bindingCount = 2;
9729 ds_layout_ci.pBindings = dsl_binding;
9730 VkDescriptorSetLayout ds_layout;
9731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9732 ASSERT_VK_SUCCESS(err);
9733
9734 VkDescriptorSet descriptor_set = {};
9735 VkDescriptorSetAllocateInfo alloc_info = {};
9736 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9737 alloc_info.descriptorSetCount = 1;
9738 alloc_info.descriptorPool = ds_pool;
9739 alloc_info.pSetLayouts = &ds_layout;
9740 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9741 ASSERT_VK_SUCCESS(err);
9742
9743 // Create a buffer to be used for invalid updates
9744 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9745 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9746 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9747 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9748 VkBufferCreateInfo ub_ci = {};
9749 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9750 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9751 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9752 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9753 VkBuffer uniform_buffer;
9754 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9755 ASSERT_VK_SUCCESS(err);
9756 VkBufferCreateInfo sb_ci = {};
9757 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9758 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9759 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9760 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9761 VkBuffer storage_buffer;
9762 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9763 ASSERT_VK_SUCCESS(err);
9764 // Have to bind memory to buffer before descriptor update
9765 VkMemoryAllocateInfo mem_alloc = {};
9766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9767 mem_alloc.pNext = NULL;
9768 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9769 mem_alloc.memoryTypeIndex = 0;
9770
Cort Stratton77a0d592017-02-17 13:14:13 -08009771 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9772 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9773 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9774 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9775 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009776 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009778 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009779 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9780 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009781 return;
9782 }
9783
9784 VkDeviceMemory mem;
9785 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009786 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009787 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9789 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9790 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9792 return;
9793 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009794 ASSERT_VK_SUCCESS(err);
9795 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9796 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009797 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009798 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9799 ASSERT_VK_SUCCESS(err);
9800
9801 VkDescriptorBufferInfo buff_info = {};
9802 buff_info.buffer = uniform_buffer;
9803 buff_info.range = ub_ci.size; // This will exceed limit
9804 VkWriteDescriptorSet descriptor_write = {};
9805 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9806 descriptor_write.dstBinding = 0;
9807 descriptor_write.descriptorCount = 1;
9808 descriptor_write.pTexelBufferView = nullptr;
9809 descriptor_write.pBufferInfo = &buff_info;
9810 descriptor_write.pImageInfo = nullptr;
9811
9812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9813 descriptor_write.dstSet = descriptor_set;
9814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9816 m_errorMonitor->VerifyFound();
9817
9818 // Reduce size of range to acceptable limit & cause offset error
9819 buff_info.range = max_ub_range;
9820 buff_info.offset = min_ub_align - 1;
9821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9822 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9823 m_errorMonitor->VerifyFound();
9824
9825 // Now break storage updates
9826 buff_info.buffer = storage_buffer;
9827 buff_info.range = sb_ci.size; // This will exceed limit
9828 buff_info.offset = 0; // Reset offset for this update
9829
9830 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9831 descriptor_write.dstBinding = 1;
9832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9833 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9834 m_errorMonitor->VerifyFound();
9835
9836 // Reduce size of range to acceptable limit & cause offset error
9837 buff_info.range = max_sb_range;
9838 buff_info.offset = min_sb_align - 1;
9839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9840 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9841 m_errorMonitor->VerifyFound();
9842
9843 vkFreeMemory(m_device->device(), mem, NULL);
9844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9845 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9846 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9847 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9848}
9849
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009850TEST_F(VkLayerTest, DSAspectBitsErrors) {
9851 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9852 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009853 TEST_DESCRIPTION(
9854 "Attempt to update descriptor sets for images "
9855 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009856 VkResult err;
9857
9858 ASSERT_NO_FATAL_FAILURE(InitState());
9859 VkDescriptorPoolSize ds_type_count = {};
9860 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9861 ds_type_count.descriptorCount = 1;
9862
9863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9865 ds_pool_ci.pNext = NULL;
9866 ds_pool_ci.maxSets = 5;
9867 ds_pool_ci.poolSizeCount = 1;
9868 ds_pool_ci.pPoolSizes = &ds_type_count;
9869
9870 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009871 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009872 ASSERT_VK_SUCCESS(err);
9873
9874 VkDescriptorSetLayoutBinding dsl_binding = {};
9875 dsl_binding.binding = 0;
9876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9877 dsl_binding.descriptorCount = 1;
9878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9879 dsl_binding.pImmutableSamplers = NULL;
9880
9881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9883 ds_layout_ci.pNext = NULL;
9884 ds_layout_ci.bindingCount = 1;
9885 ds_layout_ci.pBindings = &dsl_binding;
9886 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009888 ASSERT_VK_SUCCESS(err);
9889
9890 VkDescriptorSet descriptor_set = {};
9891 VkDescriptorSetAllocateInfo alloc_info = {};
9892 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9893 alloc_info.descriptorSetCount = 1;
9894 alloc_info.descriptorPool = ds_pool;
9895 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009897 ASSERT_VK_SUCCESS(err);
9898
9899 // Create an image to be used for invalid updates
9900 VkImageCreateInfo image_ci = {};
9901 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9902 image_ci.imageType = VK_IMAGE_TYPE_2D;
9903 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9904 image_ci.extent.width = 64;
9905 image_ci.extent.height = 64;
9906 image_ci.extent.depth = 1;
9907 image_ci.mipLevels = 1;
9908 image_ci.arrayLayers = 1;
9909 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009910 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009911 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9912 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9913 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9914 VkImage image;
9915 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9916 ASSERT_VK_SUCCESS(err);
9917 // Bind memory to image
9918 VkMemoryRequirements mem_reqs;
9919 VkDeviceMemory image_mem;
9920 bool pass;
9921 VkMemoryAllocateInfo mem_alloc = {};
9922 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9923 mem_alloc.pNext = NULL;
9924 mem_alloc.allocationSize = 0;
9925 mem_alloc.memoryTypeIndex = 0;
9926 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9927 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009929 ASSERT_TRUE(pass);
9930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9931 ASSERT_VK_SUCCESS(err);
9932 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9933 ASSERT_VK_SUCCESS(err);
9934 // Now create view for image
9935 VkImageViewCreateInfo image_view_ci = {};
9936 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9937 image_view_ci.image = image;
9938 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9939 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9940 image_view_ci.subresourceRange.layerCount = 1;
9941 image_view_ci.subresourceRange.baseArrayLayer = 0;
9942 image_view_ci.subresourceRange.levelCount = 1;
9943 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009945
9946 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009948 ASSERT_VK_SUCCESS(err);
9949
9950 VkDescriptorImageInfo img_info = {};
9951 img_info.imageView = image_view;
9952 VkWriteDescriptorSet descriptor_write = {};
9953 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9954 descriptor_write.dstBinding = 0;
9955 descriptor_write.descriptorCount = 1;
9956 descriptor_write.pTexelBufferView = NULL;
9957 descriptor_write.pBufferInfo = NULL;
9958 descriptor_write.pImageInfo = &img_info;
9959 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9960 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009961 const char *error_msg =
9962 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9963 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009965
9966 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9967
9968 m_errorMonitor->VerifyFound();
9969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9970 vkDestroyImage(m_device->device(), image, NULL);
9971 vkFreeMemory(m_device->device(), image_mem, NULL);
9972 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009973 m_errorMonitor->SetUnexpectedError(
9974 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009975 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9976 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9977}
9978
Karl Schultz6addd812016-02-02 17:17:23 -07009979TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009980 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009981 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9984 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9985 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009986
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009988 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009989 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009990 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9991 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009992
9993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9995 ds_pool_ci.pNext = NULL;
9996 ds_pool_ci.maxSets = 1;
9997 ds_pool_ci.poolSizeCount = 1;
9998 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009999
Tobin Ehlis3b780662015-05-28 12:11:26 -060010000 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010002 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010003 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010004 dsl_binding.binding = 0;
10005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10006 dsl_binding.descriptorCount = 1;
10007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10008 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010009
Tony Barboureb254902015-07-15 12:50:33 -060010010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10012 ds_layout_ci.pNext = NULL;
10013 ds_layout_ci.bindingCount = 1;
10014 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010015
Tobin Ehlis3b780662015-05-28 12:11:26 -060010016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010018 ASSERT_VK_SUCCESS(err);
10019
10020 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010021 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010023 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010024 alloc_info.descriptorPool = ds_pool;
10025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010027 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010028
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010029 VkSamplerCreateInfo sampler_ci = {};
10030 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10031 sampler_ci.pNext = NULL;
10032 sampler_ci.magFilter = VK_FILTER_NEAREST;
10033 sampler_ci.minFilter = VK_FILTER_NEAREST;
10034 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10035 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10036 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10037 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10038 sampler_ci.mipLodBias = 1.0;
10039 sampler_ci.anisotropyEnable = VK_FALSE;
10040 sampler_ci.maxAnisotropy = 1;
10041 sampler_ci.compareEnable = VK_FALSE;
10042 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10043 sampler_ci.minLod = 1.0;
10044 sampler_ci.maxLod = 1.0;
10045 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10046 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10047 VkSampler sampler;
10048 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10049 ASSERT_VK_SUCCESS(err);
10050
10051 VkDescriptorImageInfo info = {};
10052 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010053
10054 VkWriteDescriptorSet descriptor_write;
10055 memset(&descriptor_write, 0, sizeof(descriptor_write));
10056 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010057 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010058 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010060 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010061 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010062
10063 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010065 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010066
Chia-I Wuf7458c52015-10-26 21:10:41 +080010067 vkDestroySampler(m_device->device(), sampler, NULL);
10068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010070}
10071
Karl Schultz6addd812016-02-02 17:17:23 -070010072TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010073 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010074 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010075
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010077
Tobin Ehlis3b780662015-05-28 12:11:26 -060010078 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010079 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010080 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010081 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10082 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010083
10084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10086 ds_pool_ci.pNext = NULL;
10087 ds_pool_ci.maxSets = 1;
10088 ds_pool_ci.poolSizeCount = 1;
10089 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010090
Tobin Ehlis3b780662015-05-28 12:11:26 -060010091 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010093 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010094
Tony Barboureb254902015-07-15 12:50:33 -060010095 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010096 dsl_binding.binding = 0;
10097 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10098 dsl_binding.descriptorCount = 1;
10099 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10100 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010101
10102 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010103 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10104 ds_layout_ci.pNext = NULL;
10105 ds_layout_ci.bindingCount = 1;
10106 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010107
Tobin Ehlis3b780662015-05-28 12:11:26 -060010108 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010110 ASSERT_VK_SUCCESS(err);
10111
10112 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010113 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010115 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010116 alloc_info.descriptorPool = ds_pool;
10117 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010120
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010121 // Correctly update descriptor to avoid "NOT_UPDATED" error
10122 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010123 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010124 buff_info.offset = 0;
10125 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010126
10127 VkWriteDescriptorSet descriptor_write;
10128 memset(&descriptor_write, 0, sizeof(descriptor_write));
10129 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010130 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010132 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010133 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10134 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010135
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010136 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010137 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010139 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010140
Chia-I Wuf7458c52015-10-26 21:10:41 +080010141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010143}
10144
Karl Schultz6addd812016-02-02 17:17:23 -070010145TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010146 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010147 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010150
Tobin Ehlis3b780662015-05-28 12:11:26 -060010151 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010152 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010153 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010154 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10155 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010156
10157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10159 ds_pool_ci.pNext = NULL;
10160 ds_pool_ci.maxSets = 1;
10161 ds_pool_ci.poolSizeCount = 1;
10162 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010163
Tobin Ehlis3b780662015-05-28 12:11:26 -060010164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167
Tony Barboureb254902015-07-15 12:50:33 -060010168 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010169 dsl_binding.binding = 0;
10170 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10171 dsl_binding.descriptorCount = 1;
10172 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10173 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010174
10175 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010176 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10177 ds_layout_ci.pNext = NULL;
10178 ds_layout_ci.bindingCount = 1;
10179 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010182 ASSERT_VK_SUCCESS(err);
10183
10184 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010185 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010187 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010188 alloc_info.descriptorPool = ds_pool;
10189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
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 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010194 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10195 sampler_ci.pNext = NULL;
10196 sampler_ci.magFilter = VK_FILTER_NEAREST;
10197 sampler_ci.minFilter = VK_FILTER_NEAREST;
10198 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10199 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10200 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10201 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10202 sampler_ci.mipLodBias = 1.0;
10203 sampler_ci.anisotropyEnable = VK_FALSE;
10204 sampler_ci.maxAnisotropy = 1;
10205 sampler_ci.compareEnable = VK_FALSE;
10206 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10207 sampler_ci.minLod = 1.0;
10208 sampler_ci.maxLod = 1.0;
10209 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10210 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010211
Tobin Ehlis3b780662015-05-28 12:11:26 -060010212 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010213 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010214 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010215
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010216 VkDescriptorImageInfo info = {};
10217 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010218
10219 VkWriteDescriptorSet descriptor_write;
10220 memset(&descriptor_write, 0, sizeof(descriptor_write));
10221 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010222 descriptor_write.dstSet = descriptorSet;
10223 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010224 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010226 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010227 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010228
10229 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010231 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010232
Chia-I Wuf7458c52015-10-26 21:10:41 +080010233 vkDestroySampler(m_device->device(), sampler, NULL);
10234 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10235 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010236}
10237
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010238TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10239 // Create layout w/ empty binding and attempt to update it
10240 VkResult err;
10241
10242 ASSERT_NO_FATAL_FAILURE(InitState());
10243
10244 VkDescriptorPoolSize ds_type_count = {};
10245 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10246 ds_type_count.descriptorCount = 1;
10247
10248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10250 ds_pool_ci.pNext = NULL;
10251 ds_pool_ci.maxSets = 1;
10252 ds_pool_ci.poolSizeCount = 1;
10253 ds_pool_ci.pPoolSizes = &ds_type_count;
10254
10255 VkDescriptorPool ds_pool;
10256 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10257 ASSERT_VK_SUCCESS(err);
10258
10259 VkDescriptorSetLayoutBinding dsl_binding = {};
10260 dsl_binding.binding = 0;
10261 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10262 dsl_binding.descriptorCount = 0;
10263 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10264 dsl_binding.pImmutableSamplers = NULL;
10265
10266 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10267 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10268 ds_layout_ci.pNext = NULL;
10269 ds_layout_ci.bindingCount = 1;
10270 ds_layout_ci.pBindings = &dsl_binding;
10271 VkDescriptorSetLayout ds_layout;
10272 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10273 ASSERT_VK_SUCCESS(err);
10274
10275 VkDescriptorSet descriptor_set;
10276 VkDescriptorSetAllocateInfo alloc_info = {};
10277 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10278 alloc_info.descriptorSetCount = 1;
10279 alloc_info.descriptorPool = ds_pool;
10280 alloc_info.pSetLayouts = &ds_layout;
10281 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10282 ASSERT_VK_SUCCESS(err);
10283
10284 VkSamplerCreateInfo sampler_ci = {};
10285 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10286 sampler_ci.magFilter = VK_FILTER_NEAREST;
10287 sampler_ci.minFilter = VK_FILTER_NEAREST;
10288 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10289 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10290 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10291 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10292 sampler_ci.mipLodBias = 1.0;
10293 sampler_ci.maxAnisotropy = 1;
10294 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10295 sampler_ci.minLod = 1.0;
10296 sampler_ci.maxLod = 1.0;
10297 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10298
10299 VkSampler sampler;
10300 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10301 ASSERT_VK_SUCCESS(err);
10302
10303 VkDescriptorImageInfo info = {};
10304 info.sampler = sampler;
10305
10306 VkWriteDescriptorSet descriptor_write;
10307 memset(&descriptor_write, 0, sizeof(descriptor_write));
10308 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10309 descriptor_write.dstSet = descriptor_set;
10310 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010311 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010312 // This is the wrong type, but empty binding error will be flagged first
10313 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10314 descriptor_write.pImageInfo = &info;
10315
10316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10318 m_errorMonitor->VerifyFound();
10319
10320 vkDestroySampler(m_device->device(), sampler, NULL);
10321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10322 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10323}
10324
Karl Schultz6addd812016-02-02 17:17:23 -070010325TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10326 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10327 // types
10328 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 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 -060010331
Tobin Ehlis3b780662015-05-28 12:11:26 -060010332 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010333
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010334 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010335 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10336 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010337
10338 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010339 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10340 ds_pool_ci.pNext = NULL;
10341 ds_pool_ci.maxSets = 1;
10342 ds_pool_ci.poolSizeCount = 1;
10343 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010344
Tobin Ehlis3b780662015-05-28 12:11:26 -060010345 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010347 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010348 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010349 dsl_binding.binding = 0;
10350 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10351 dsl_binding.descriptorCount = 1;
10352 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10353 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354
Tony Barboureb254902015-07-15 12:50:33 -060010355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10357 ds_layout_ci.pNext = NULL;
10358 ds_layout_ci.bindingCount = 1;
10359 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010360
Tobin Ehlis3b780662015-05-28 12:11:26 -060010361 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010363 ASSERT_VK_SUCCESS(err);
10364
10365 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010366 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010367 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010368 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010369 alloc_info.descriptorPool = ds_pool;
10370 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010373
Tony Barboureb254902015-07-15 12:50:33 -060010374 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010375 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10376 sampler_ci.pNext = NULL;
10377 sampler_ci.magFilter = VK_FILTER_NEAREST;
10378 sampler_ci.minFilter = VK_FILTER_NEAREST;
10379 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10380 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10381 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10382 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10383 sampler_ci.mipLodBias = 1.0;
10384 sampler_ci.anisotropyEnable = VK_FALSE;
10385 sampler_ci.maxAnisotropy = 1;
10386 sampler_ci.compareEnable = VK_FALSE;
10387 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10388 sampler_ci.minLod = 1.0;
10389 sampler_ci.maxLod = 1.0;
10390 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10391 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010392 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010393 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010394 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010395
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010396 VkDescriptorImageInfo info = {};
10397 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010398
10399 VkWriteDescriptorSet descriptor_write;
10400 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010402 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010403 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010404 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010405 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010406 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010407
10408 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010410 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010411
Chia-I Wuf7458c52015-10-26 21:10:41 +080010412 vkDestroySampler(m_device->device(), sampler, NULL);
10413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010415}
10416
Karl Schultz6addd812016-02-02 17:17:23 -070010417TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010418 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010419 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010420
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010422
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010423 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010424 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10425 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010427 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10428 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010429
10430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10432 ds_pool_ci.pNext = NULL;
10433 ds_pool_ci.maxSets = 1;
10434 ds_pool_ci.poolSizeCount = 1;
10435 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010436
10437 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010439 ASSERT_VK_SUCCESS(err);
10440
10441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010442 dsl_binding.binding = 0;
10443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10444 dsl_binding.descriptorCount = 1;
10445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010447
10448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10450 ds_layout_ci.pNext = NULL;
10451 ds_layout_ci.bindingCount = 1;
10452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010453 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010455 ASSERT_VK_SUCCESS(err);
10456
10457 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010458 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010459 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010460 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010461 alloc_info.descriptorPool = ds_pool;
10462 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010464 ASSERT_VK_SUCCESS(err);
10465
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010466 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010467
10468 VkDescriptorImageInfo descriptor_info;
10469 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10470 descriptor_info.sampler = sampler;
10471
10472 VkWriteDescriptorSet descriptor_write;
10473 memset(&descriptor_write, 0, sizeof(descriptor_write));
10474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010475 descriptor_write.dstSet = descriptorSet;
10476 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010477 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10479 descriptor_write.pImageInfo = &descriptor_info;
10480
10481 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10482
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010483 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010484
Chia-I Wuf7458c52015-10-26 21:10:41 +080010485 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10486 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010487}
10488
Karl Schultz6addd812016-02-02 17:17:23 -070010489TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10490 // Create a single combined Image/Sampler descriptor and send it an invalid
10491 // imageView
10492 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010493
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010495
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010496 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010497 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010498 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10499 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010500
10501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10503 ds_pool_ci.pNext = NULL;
10504 ds_pool_ci.maxSets = 1;
10505 ds_pool_ci.poolSizeCount = 1;
10506 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010507
10508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010510 ASSERT_VK_SUCCESS(err);
10511
10512 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010513 dsl_binding.binding = 0;
10514 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10515 dsl_binding.descriptorCount = 1;
10516 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10517 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010518
10519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10521 ds_layout_ci.pNext = NULL;
10522 ds_layout_ci.bindingCount = 1;
10523 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010524 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010526 ASSERT_VK_SUCCESS(err);
10527
10528 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010529 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010531 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010532 alloc_info.descriptorPool = ds_pool;
10533 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010535 ASSERT_VK_SUCCESS(err);
10536
10537 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010538 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10539 sampler_ci.pNext = NULL;
10540 sampler_ci.magFilter = VK_FILTER_NEAREST;
10541 sampler_ci.minFilter = VK_FILTER_NEAREST;
10542 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10543 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10544 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10545 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10546 sampler_ci.mipLodBias = 1.0;
10547 sampler_ci.anisotropyEnable = VK_FALSE;
10548 sampler_ci.maxAnisotropy = 1;
10549 sampler_ci.compareEnable = VK_FALSE;
10550 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10551 sampler_ci.minLod = 1.0;
10552 sampler_ci.maxLod = 1.0;
10553 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10554 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010555
10556 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010557 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558 ASSERT_VK_SUCCESS(err);
10559
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010560 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010561
10562 VkDescriptorImageInfo descriptor_info;
10563 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10564 descriptor_info.sampler = sampler;
10565 descriptor_info.imageView = view;
10566
10567 VkWriteDescriptorSet descriptor_write;
10568 memset(&descriptor_write, 0, sizeof(descriptor_write));
10569 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010570 descriptor_write.dstSet = descriptorSet;
10571 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010572 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010573 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10574 descriptor_write.pImageInfo = &descriptor_info;
10575
10576 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010578 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579
Chia-I Wuf7458c52015-10-26 21:10:41 +080010580 vkDestroySampler(m_device->device(), sampler, NULL);
10581 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10582 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010583}
10584
Karl Schultz6addd812016-02-02 17:17:23 -070010585TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10586 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10587 // into the other
10588 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10591 " binding #1 with type "
10592 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10593 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010594
Tobin Ehlis04356f92015-10-27 16:35:27 -060010595 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010596 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010597 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010598 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10599 ds_type_count[0].descriptorCount = 1;
10600 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10601 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010602
10603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10605 ds_pool_ci.pNext = NULL;
10606 ds_pool_ci.maxSets = 1;
10607 ds_pool_ci.poolSizeCount = 2;
10608 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010609
10610 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010612 ASSERT_VK_SUCCESS(err);
10613 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010614 dsl_binding[0].binding = 0;
10615 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10616 dsl_binding[0].descriptorCount = 1;
10617 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10618 dsl_binding[0].pImmutableSamplers = NULL;
10619 dsl_binding[1].binding = 1;
10620 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10621 dsl_binding[1].descriptorCount = 1;
10622 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10623 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010624
10625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10627 ds_layout_ci.pNext = NULL;
10628 ds_layout_ci.bindingCount = 2;
10629 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010630
10631 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010633 ASSERT_VK_SUCCESS(err);
10634
10635 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010636 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010638 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010639 alloc_info.descriptorPool = ds_pool;
10640 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010642 ASSERT_VK_SUCCESS(err);
10643
10644 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010645 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10646 sampler_ci.pNext = NULL;
10647 sampler_ci.magFilter = VK_FILTER_NEAREST;
10648 sampler_ci.minFilter = VK_FILTER_NEAREST;
10649 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10650 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10651 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10652 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10653 sampler_ci.mipLodBias = 1.0;
10654 sampler_ci.anisotropyEnable = VK_FALSE;
10655 sampler_ci.maxAnisotropy = 1;
10656 sampler_ci.compareEnable = VK_FALSE;
10657 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10658 sampler_ci.minLod = 1.0;
10659 sampler_ci.maxLod = 1.0;
10660 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10661 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010662
10663 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010664 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010665 ASSERT_VK_SUCCESS(err);
10666
10667 VkDescriptorImageInfo info = {};
10668 info.sampler = sampler;
10669
10670 VkWriteDescriptorSet descriptor_write;
10671 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010673 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010674 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010675 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10677 descriptor_write.pImageInfo = &info;
10678 // This write update should succeed
10679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10680 // Now perform a copy update that fails due to type mismatch
10681 VkCopyDescriptorSet copy_ds_update;
10682 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10683 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10684 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010685 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010686 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010687 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10688 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010691 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010692 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010693 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 -060010694 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10695 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10696 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010697 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010698 copy_ds_update.dstSet = descriptorSet;
10699 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010701 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10702
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010703 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010704
Tobin Ehlis04356f92015-10-27 16:35:27 -060010705 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10707 " binding#1 with offset index of 1 plus "
10708 "update array offset of 0 and update of "
10709 "5 descriptors oversteps total number "
10710 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010711
Tobin Ehlis04356f92015-10-27 16:35:27 -060010712 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10713 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10714 copy_ds_update.srcSet = descriptorSet;
10715 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010716 copy_ds_update.dstSet = descriptorSet;
10717 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010718 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010719 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010721 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010722
Chia-I Wuf7458c52015-10-26 21:10:41 +080010723 vkDestroySampler(m_device->device(), sampler, NULL);
10724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010726}
10727
Karl Schultz6addd812016-02-02 17:17:23 -070010728TEST_F(VkLayerTest, NumSamplesMismatch) {
10729 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10730 // sampleCount
10731 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010734
Tobin Ehlis3b780662015-05-28 12:11:26 -060010735 ASSERT_NO_FATAL_FAILURE(InitState());
10736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010737 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010739 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010740
10741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10743 ds_pool_ci.pNext = NULL;
10744 ds_pool_ci.maxSets = 1;
10745 ds_pool_ci.poolSizeCount = 1;
10746 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010747
Tobin Ehlis3b780662015-05-28 12:11:26 -060010748 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010750 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010751
Tony Barboureb254902015-07-15 12:50:33 -060010752 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010753 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010755 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10757 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010758
Tony Barboureb254902015-07-15 12:50:33 -060010759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10761 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010762 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010763 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010764
Tobin Ehlis3b780662015-05-28 12:11:26 -060010765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010767 ASSERT_VK_SUCCESS(err);
10768
10769 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010770 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010772 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010773 alloc_info.descriptorPool = ds_pool;
10774 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010776 ASSERT_VK_SUCCESS(err);
10777
Tony Barboureb254902015-07-15 12:50:33 -060010778 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010780 pipe_ms_state_ci.pNext = NULL;
10781 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10782 pipe_ms_state_ci.sampleShadingEnable = 0;
10783 pipe_ms_state_ci.minSampleShading = 1.0;
10784 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010785
Tony Barboureb254902015-07-15 12:50:33 -060010786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10788 pipeline_layout_ci.pNext = NULL;
10789 pipeline_layout_ci.setLayoutCount = 1;
10790 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010791
10792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_VK_SUCCESS(err);
10795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010797 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 -060010798 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010799 VkPipelineObj pipe(m_device);
10800 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010801 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010802 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010803 pipe.SetMSAA(&pipe_ms_state_ci);
10804 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010805
Tony Barbour552f6c02016-12-21 14:34:07 -070010806 m_commandBuffer->BeginCommandBuffer();
10807 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010810 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10811 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10812 VkRect2D scissor = {{0, 0}, {16, 16}};
10813 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10814
Mark Young29927482016-05-04 14:38:51 -060010815 // Render triangle (the error should trigger on the attempt to draw).
10816 Draw(3, 1, 0, 0);
10817
10818 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010819 m_commandBuffer->EndRenderPass();
10820 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010822 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010823
Chia-I Wuf7458c52015-10-26 21:10:41 +080010824 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010827}
Mark Young29927482016-05-04 14:38:51 -060010828
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010829TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010830 TEST_DESCRIPTION(
10831 "Hit RenderPass incompatible cases. "
10832 "Initial case is drawing with an active renderpass that's "
10833 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010834 VkResult err;
10835
10836 ASSERT_NO_FATAL_FAILURE(InitState());
10837 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10838
10839 VkDescriptorSetLayoutBinding dsl_binding = {};
10840 dsl_binding.binding = 0;
10841 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10842 dsl_binding.descriptorCount = 1;
10843 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10844 dsl_binding.pImmutableSamplers = NULL;
10845
10846 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10847 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10848 ds_layout_ci.pNext = NULL;
10849 ds_layout_ci.bindingCount = 1;
10850 ds_layout_ci.pBindings = &dsl_binding;
10851
10852 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010854 ASSERT_VK_SUCCESS(err);
10855
10856 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10857 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10858 pipeline_layout_ci.pNext = NULL;
10859 pipeline_layout_ci.setLayoutCount = 1;
10860 pipeline_layout_ci.pSetLayouts = &ds_layout;
10861
10862 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010864 ASSERT_VK_SUCCESS(err);
10865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010867 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 -060010868 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010869 // Create a renderpass that will be incompatible with default renderpass
10870 VkAttachmentReference attach = {};
10871 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10872 VkAttachmentReference color_att = {};
10873 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10874 VkSubpassDescription subpass = {};
10875 subpass.inputAttachmentCount = 1;
10876 subpass.pInputAttachments = &attach;
10877 subpass.colorAttachmentCount = 1;
10878 subpass.pColorAttachments = &color_att;
10879 VkRenderPassCreateInfo rpci = {};
10880 rpci.subpassCount = 1;
10881 rpci.pSubpasses = &subpass;
10882 rpci.attachmentCount = 1;
10883 VkAttachmentDescription attach_desc = {};
10884 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010885 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10886 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010887 rpci.pAttachments = &attach_desc;
10888 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10889 VkRenderPass rp;
10890 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10891 VkPipelineObj pipe(m_device);
10892 pipe.AddShader(&vs);
10893 pipe.AddShader(&fs);
10894 pipe.AddColorAttachment();
10895 VkViewport view_port = {};
10896 m_viewports.push_back(view_port);
10897 pipe.SetViewport(m_viewports);
10898 VkRect2D rect = {};
10899 m_scissors.push_back(rect);
10900 pipe.SetScissor(m_scissors);
10901 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10902
10903 VkCommandBufferInheritanceInfo cbii = {};
10904 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10905 cbii.renderPass = rp;
10906 cbii.subpass = 0;
10907 VkCommandBufferBeginInfo cbbi = {};
10908 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10909 cbbi.pInheritanceInfo = &cbii;
10910 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10911 VkRenderPassBeginInfo rpbi = {};
10912 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10913 rpbi.framebuffer = m_framebuffer;
10914 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10916 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010919 // Render triangle (the error should trigger on the attempt to draw).
10920 Draw(3, 1, 0, 0);
10921
10922 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010923 m_commandBuffer->EndRenderPass();
10924 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010925
10926 m_errorMonitor->VerifyFound();
10927
10928 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10930 vkDestroyRenderPass(m_device->device(), rp, NULL);
10931}
10932
Mark Youngc89c6312016-03-31 16:03:20 -060010933TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10934 // Create Pipeline where the number of blend attachments doesn't match the
10935 // number of color attachments. In this case, we don't add any color
10936 // blend attachments even though we have a color attachment.
10937 VkResult err;
10938
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010940
10941 ASSERT_NO_FATAL_FAILURE(InitState());
10942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10943 VkDescriptorPoolSize ds_type_count = {};
10944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10945 ds_type_count.descriptorCount = 1;
10946
10947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10949 ds_pool_ci.pNext = NULL;
10950 ds_pool_ci.maxSets = 1;
10951 ds_pool_ci.poolSizeCount = 1;
10952 ds_pool_ci.pPoolSizes = &ds_type_count;
10953
10954 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010956 ASSERT_VK_SUCCESS(err);
10957
10958 VkDescriptorSetLayoutBinding dsl_binding = {};
10959 dsl_binding.binding = 0;
10960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10961 dsl_binding.descriptorCount = 1;
10962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10963 dsl_binding.pImmutableSamplers = NULL;
10964
10965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10967 ds_layout_ci.pNext = NULL;
10968 ds_layout_ci.bindingCount = 1;
10969 ds_layout_ci.pBindings = &dsl_binding;
10970
10971 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010973 ASSERT_VK_SUCCESS(err);
10974
10975 VkDescriptorSet descriptorSet;
10976 VkDescriptorSetAllocateInfo alloc_info = {};
10977 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10978 alloc_info.descriptorSetCount = 1;
10979 alloc_info.descriptorPool = ds_pool;
10980 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010981 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010982 ASSERT_VK_SUCCESS(err);
10983
10984 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010986 pipe_ms_state_ci.pNext = NULL;
10987 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10988 pipe_ms_state_ci.sampleShadingEnable = 0;
10989 pipe_ms_state_ci.minSampleShading = 1.0;
10990 pipe_ms_state_ci.pSampleMask = NULL;
10991
10992 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10993 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10994 pipeline_layout_ci.pNext = NULL;
10995 pipeline_layout_ci.setLayoutCount = 1;
10996 pipeline_layout_ci.pSetLayouts = &ds_layout;
10997
10998 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010999 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011000 ASSERT_VK_SUCCESS(err);
11001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011002 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011003 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 -060011004 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011005 VkPipelineObj pipe(m_device);
11006 pipe.AddShader(&vs);
11007 pipe.AddShader(&fs);
11008 pipe.SetMSAA(&pipe_ms_state_ci);
11009 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011010 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011011
11012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11015}
Mark Young29927482016-05-04 14:38:51 -060011016
Mark Muellerd4914412016-06-13 17:52:06 -060011017TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011018 TEST_DESCRIPTION(
11019 "Points to a wrong colorAttachment index in a VkClearAttachment "
11020 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011021 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011023
11024 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11025 m_errorMonitor->VerifyFound();
11026}
11027
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011028TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011029 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11030 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011031
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011032 ASSERT_NO_FATAL_FAILURE(InitState());
11033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011034
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011035 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011036 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11037 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011038
11039 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011040 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11041 ds_pool_ci.pNext = NULL;
11042 ds_pool_ci.maxSets = 1;
11043 ds_pool_ci.poolSizeCount = 1;
11044 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011045
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011046 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011047 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011048 ASSERT_VK_SUCCESS(err);
11049
Tony Barboureb254902015-07-15 12:50:33 -060011050 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 dsl_binding.binding = 0;
11052 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11053 dsl_binding.descriptorCount = 1;
11054 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11055 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011056
Tony Barboureb254902015-07-15 12:50:33 -060011057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11059 ds_layout_ci.pNext = NULL;
11060 ds_layout_ci.bindingCount = 1;
11061 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011062
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011065 ASSERT_VK_SUCCESS(err);
11066
11067 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011068 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011070 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011071 alloc_info.descriptorPool = ds_pool;
11072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011074 ASSERT_VK_SUCCESS(err);
11075
Tony Barboureb254902015-07-15 12:50:33 -060011076 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011078 pipe_ms_state_ci.pNext = NULL;
11079 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11080 pipe_ms_state_ci.sampleShadingEnable = 0;
11081 pipe_ms_state_ci.minSampleShading = 1.0;
11082 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011083
Tony Barboureb254902015-07-15 12:50:33 -060011084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11086 pipeline_layout_ci.pNext = NULL;
11087 pipeline_layout_ci.setLayoutCount = 1;
11088 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089
11090 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011092 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011094 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011095 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011096 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011097 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011098
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011099 VkPipelineObj pipe(m_device);
11100 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011101 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011102 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011103 m_errorMonitor->SetUnexpectedError(
11104 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11105 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011106 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011107
Tony Barbour552f6c02016-12-21 14:34:07 -070011108 m_commandBuffer->BeginCommandBuffer();
11109 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011110
Karl Schultz6addd812016-02-02 17:17:23 -070011111 // Main thing we care about for this test is that the VkImage obj we're
11112 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011113 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011114 VkClearAttachment color_attachment;
11115 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11116 color_attachment.clearValue.color.float32[0] = 1.0;
11117 color_attachment.clearValue.color.float32[1] = 1.0;
11118 color_attachment.clearValue.color.float32[2] = 1.0;
11119 color_attachment.clearValue.color.float32[3] = 1.0;
11120 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011122
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011123 // Call for full-sized FB Color attachment prior to issuing a Draw
11124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011125 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011127 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011128
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011129 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11130 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11132 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11133 m_errorMonitor->VerifyFound();
11134
11135 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11136 clear_rect.layerCount = 2;
11137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11138 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011139 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011140
Chia-I Wuf7458c52015-10-26 21:10:41 +080011141 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011144}
11145
Karl Schultz6addd812016-02-02 17:17:23 -070011146TEST_F(VkLayerTest, VtxBufferBadIndex) {
11147 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11150 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011151
Tobin Ehlis502480b2015-06-24 15:53:07 -060011152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011153 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011155
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011156 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011157 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11158 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011159
11160 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011161 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11162 ds_pool_ci.pNext = NULL;
11163 ds_pool_ci.maxSets = 1;
11164 ds_pool_ci.poolSizeCount = 1;
11165 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011166
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011167 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011168 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011169 ASSERT_VK_SUCCESS(err);
11170
Tony Barboureb254902015-07-15 12:50:33 -060011171 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011172 dsl_binding.binding = 0;
11173 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11174 dsl_binding.descriptorCount = 1;
11175 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11176 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011177
Tony Barboureb254902015-07-15 12:50:33 -060011178 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011179 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11180 ds_layout_ci.pNext = NULL;
11181 ds_layout_ci.bindingCount = 1;
11182 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011183
Tobin Ehlis502480b2015-06-24 15:53:07 -060011184 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011185 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011186 ASSERT_VK_SUCCESS(err);
11187
11188 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011189 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011190 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011191 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011192 alloc_info.descriptorPool = ds_pool;
11193 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011195 ASSERT_VK_SUCCESS(err);
11196
Tony Barboureb254902015-07-15 12:50:33 -060011197 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011199 pipe_ms_state_ci.pNext = NULL;
11200 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11201 pipe_ms_state_ci.sampleShadingEnable = 0;
11202 pipe_ms_state_ci.minSampleShading = 1.0;
11203 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011204
Tony Barboureb254902015-07-15 12:50:33 -060011205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11207 pipeline_layout_ci.pNext = NULL;
11208 pipeline_layout_ci.setLayoutCount = 1;
11209 pipeline_layout_ci.pSetLayouts = &ds_layout;
11210 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011213 ASSERT_VK_SUCCESS(err);
11214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011216 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 -060011217 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011218 VkPipelineObj pipe(m_device);
11219 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011220 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011221 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011222 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011223 pipe.SetViewport(m_viewports);
11224 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011226
Tony Barbour552f6c02016-12-21 14:34:07 -070011227 m_commandBuffer->BeginCommandBuffer();
11228 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011229 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011230 // Don't care about actual data, just need to get to draw to flag error
11231 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011233 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011234 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011237
Chia-I Wuf7458c52015-10-26 21:10:41 +080011238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011241}
Mark Muellerdfe37552016-07-07 14:47:42 -060011242
Mark Mueller2ee294f2016-08-04 12:59:48 -060011243TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011244 TEST_DESCRIPTION(
11245 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11246 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011247 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011248
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011249 const char *invalid_queueFamilyIndex_message =
11250 "Invalid queue create request in vkCreateDevice(). Invalid "
11251 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011254
Mark Mueller880fce52016-08-17 15:23:23 -060011255 // The following test fails with recent NVidia drivers.
11256 // By the time core_validation is reached, the NVidia
11257 // driver has sanitized the invalid condition and core_validation
11258 // is not introduced to the failure condition. This is not the case
11259 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011260 // uint32_t count = static_cast<uint32_t>(~0);
11261 // VkPhysicalDevice physical_device;
11262 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11263 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011266 float queue_priority = 0.0;
11267
11268 VkDeviceQueueCreateInfo queue_create_info = {};
11269 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11270 queue_create_info.queueCount = 1;
11271 queue_create_info.pQueuePriorities = &queue_priority;
11272 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11273
11274 VkPhysicalDeviceFeatures features = m_device->phy().features();
11275 VkDevice testDevice;
11276 VkDeviceCreateInfo device_create_info = {};
11277 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11278 device_create_info.queueCreateInfoCount = 1;
11279 device_create_info.pQueueCreateInfos = &queue_create_info;
11280 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011281 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011282 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11283 m_errorMonitor->VerifyFound();
11284
11285 queue_create_info.queueFamilyIndex = 1;
11286
11287 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11288 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11289 for (unsigned i = 0; i < feature_count; i++) {
11290 if (VK_FALSE == feature_array[i]) {
11291 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011293 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011294 m_errorMonitor->SetUnexpectedError(
11295 "You requested features that are unavailable on this device. You should first query feature availability by "
11296 "calling vkGetPhysicalDeviceFeatures().");
11297 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011298 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11299 m_errorMonitor->VerifyFound();
11300 break;
11301 }
11302 }
11303}
11304
Tobin Ehlis16edf082016-11-21 12:33:49 -070011305TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11306 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11307
11308 ASSERT_NO_FATAL_FAILURE(InitState());
11309
11310 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11311 std::vector<VkDeviceQueueCreateInfo> queue_info;
11312 queue_info.reserve(queue_props.size());
11313 std::vector<std::vector<float>> queue_priorities;
11314 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11315 VkDeviceQueueCreateInfo qi{};
11316 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11317 qi.queueFamilyIndex = i;
11318 qi.queueCount = queue_props[i].queueCount;
11319 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11320 qi.pQueuePriorities = queue_priorities[i].data();
11321 queue_info.push_back(qi);
11322 }
11323
11324 std::vector<const char *> device_extension_names;
11325
11326 VkDevice local_device;
11327 VkDeviceCreateInfo device_create_info = {};
11328 auto features = m_device->phy().features();
11329 // Intentionally disable pipeline stats
11330 features.pipelineStatisticsQuery = VK_FALSE;
11331 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11332 device_create_info.pNext = NULL;
11333 device_create_info.queueCreateInfoCount = queue_info.size();
11334 device_create_info.pQueueCreateInfos = queue_info.data();
11335 device_create_info.enabledLayerCount = 0;
11336 device_create_info.ppEnabledLayerNames = NULL;
11337 device_create_info.pEnabledFeatures = &features;
11338 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11339 ASSERT_VK_SUCCESS(err);
11340
11341 VkQueryPoolCreateInfo qpci{};
11342 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11343 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11344 qpci.queryCount = 1;
11345 VkQueryPool query_pool;
11346
11347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11348 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11349 m_errorMonitor->VerifyFound();
11350
11351 vkDestroyDevice(local_device, nullptr);
11352}
11353
Mark Mueller2ee294f2016-08-04 12:59:48 -060011354TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011355 TEST_DESCRIPTION(
11356 "Use an invalid queue index in a vkCmdWaitEvents call."
11357 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011359 const char *invalid_queue_index =
11360 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11361 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11362 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011367
11368 ASSERT_NO_FATAL_FAILURE(InitState());
11369
11370 VkEvent event;
11371 VkEventCreateInfo event_create_info{};
11372 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11373 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11374
Mark Mueller2ee294f2016-08-04 12:59:48 -060011375 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011377
Tony Barbour552f6c02016-12-21 14:34:07 -070011378 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011379
11380 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 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 -060011382 ASSERT_TRUE(image.initialized());
11383 VkImageMemoryBarrier img_barrier = {};
11384 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11385 img_barrier.pNext = NULL;
11386 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11387 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11388 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11389 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11390 img_barrier.image = image.handle();
11391 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011392
11393 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11394 // that layer validation catches the case when it is not.
11395 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011396 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11397 img_barrier.subresourceRange.baseArrayLayer = 0;
11398 img_barrier.subresourceRange.baseMipLevel = 0;
11399 img_barrier.subresourceRange.layerCount = 1;
11400 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11402 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011403 m_errorMonitor->VerifyFound();
11404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011406
11407 VkQueryPool query_pool;
11408 VkQueryPoolCreateInfo query_pool_create_info = {};
11409 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11410 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11411 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011414 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011415 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11416
11417 vkEndCommandBuffer(m_commandBuffer->handle());
11418 m_errorMonitor->VerifyFound();
11419
11420 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11421 vkDestroyEvent(m_device->device(), event, nullptr);
11422}
11423
Mark Muellerdfe37552016-07-07 14:47:42 -060011424TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011425 TEST_DESCRIPTION(
11426 "Submit a command buffer using deleted vertex buffer, "
11427 "delete a buffer twice, use an invalid offset for each "
11428 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011429
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011430 const char *deleted_buffer_in_command_buffer =
11431 "Cannot submit cmd buffer "
11432 "using deleted buffer ";
11433 const char *invalid_offset_message =
11434 "vkBindBufferMemory(): "
11435 "memoryOffset is 0x";
11436 const char *invalid_storage_buffer_offset_message =
11437 "vkBindBufferMemory(): "
11438 "storage memoryOffset "
11439 "is 0x";
11440 const char *invalid_texel_buffer_offset_message =
11441 "vkBindBufferMemory(): "
11442 "texel memoryOffset "
11443 "is 0x";
11444 const char *invalid_uniform_buffer_offset_message =
11445 "vkBindBufferMemory(): "
11446 "uniform memoryOffset "
11447 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011448
11449 ASSERT_NO_FATAL_FAILURE(InitState());
11450 ASSERT_NO_FATAL_FAILURE(InitViewport());
11451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11452
11453 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011455 pipe_ms_state_ci.pNext = NULL;
11456 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11457 pipe_ms_state_ci.sampleShadingEnable = 0;
11458 pipe_ms_state_ci.minSampleShading = 1.0;
11459 pipe_ms_state_ci.pSampleMask = nullptr;
11460
11461 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11462 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11463 VkPipelineLayout pipeline_layout;
11464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011466 ASSERT_VK_SUCCESS(err);
11467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011468 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11469 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011470 VkPipelineObj pipe(m_device);
11471 pipe.AddShader(&vs);
11472 pipe.AddShader(&fs);
11473 pipe.AddColorAttachment();
11474 pipe.SetMSAA(&pipe_ms_state_ci);
11475 pipe.SetViewport(m_viewports);
11476 pipe.SetScissor(m_scissors);
11477 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11478
Tony Barbour552f6c02016-12-21 14:34:07 -070011479 m_commandBuffer->BeginCommandBuffer();
11480 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011481 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011482
11483 {
11484 // Create and bind a vertex buffer in a reduced scope, which will cause
11485 // it to be deleted upon leaving this scope
11486 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011487 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011488 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11489 draw_verticies.AddVertexInputToPipe(pipe);
11490 }
11491
11492 Draw(1, 0, 0, 0);
11493
Tony Barbour552f6c02016-12-21 14:34:07 -070011494 m_commandBuffer->EndRenderPass();
11495 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011498 QueueCommandBuffer(false);
11499 m_errorMonitor->VerifyFound();
11500
11501 {
11502 // Create and bind a vertex buffer in a reduced scope, and delete it
11503 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011506 buffer_test.TestDoubleDestroy();
11507 }
11508 m_errorMonitor->VerifyFound();
11509
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011510 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011512 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011514 m_errorMonitor->SetUnexpectedError(
11515 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11516 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11518 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011519 m_errorMonitor->VerifyFound();
11520 }
11521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11523 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011524 // Create and bind a memory buffer with an invalid offset again,
11525 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011527 m_errorMonitor->SetUnexpectedError(
11528 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11529 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11531 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011532 m_errorMonitor->VerifyFound();
11533 }
11534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011536 // Create and bind a memory buffer with an invalid offset again, but
11537 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011539 m_errorMonitor->SetUnexpectedError(
11540 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11541 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011542 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
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, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011548 // Create and bind a memory buffer with an invalid offset again, but
11549 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011551 m_errorMonitor->SetUnexpectedError(
11552 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11553 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11555 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011556 m_errorMonitor->VerifyFound();
11557 }
11558
11559 {
11560 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011562 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11563 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11565 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011566 m_errorMonitor->VerifyFound();
11567 }
11568
11569 {
11570 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11573 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011574 }
11575 m_errorMonitor->VerifyFound();
11576
11577 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11578}
11579
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011580// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11581TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011582 TEST_DESCRIPTION(
11583 "Hit all possible validation checks associated with the "
11584 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11585 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011586 // 3 in ValidateCmdBufImageLayouts
11587 // * -1 Attempt to submit cmd buf w/ deleted image
11588 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11589 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011590
11591 ASSERT_NO_FATAL_FAILURE(InitState());
11592 // Create src & dst images to use for copy operations
11593 VkImage src_image;
11594 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011595 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011596
11597 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11598 const int32_t tex_width = 32;
11599 const int32_t tex_height = 32;
11600
11601 VkImageCreateInfo image_create_info = {};
11602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11603 image_create_info.pNext = NULL;
11604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11605 image_create_info.format = tex_format;
11606 image_create_info.extent.width = tex_width;
11607 image_create_info.extent.height = tex_height;
11608 image_create_info.extent.depth = 1;
11609 image_create_info.mipLevels = 1;
11610 image_create_info.arrayLayers = 4;
11611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11612 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11613 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011614 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011615 image_create_info.flags = 0;
11616
11617 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11618 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011619 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11621 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011622 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11623 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11625 ASSERT_VK_SUCCESS(err);
11626
11627 // Allocate memory
11628 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011629 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011630 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011631 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11632 mem_alloc.pNext = NULL;
11633 mem_alloc.allocationSize = 0;
11634 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011635
11636 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011637 mem_alloc.allocationSize = img_mem_reqs.size;
11638 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011639 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011640 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011641 ASSERT_VK_SUCCESS(err);
11642
11643 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011644 mem_alloc.allocationSize = img_mem_reqs.size;
11645 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011646 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011647 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011648 ASSERT_VK_SUCCESS(err);
11649
11650 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011651 mem_alloc.allocationSize = img_mem_reqs.size;
11652 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011653 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011654 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011655 ASSERT_VK_SUCCESS(err);
11656
11657 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11658 ASSERT_VK_SUCCESS(err);
11659 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11660 ASSERT_VK_SUCCESS(err);
11661 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11662 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011663
Tony Barbour552f6c02016-12-21 14:34:07 -070011664 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011665 VkImageCopy copy_region;
11666 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11667 copy_region.srcSubresource.mipLevel = 0;
11668 copy_region.srcSubresource.baseArrayLayer = 0;
11669 copy_region.srcSubresource.layerCount = 1;
11670 copy_region.srcOffset.x = 0;
11671 copy_region.srcOffset.y = 0;
11672 copy_region.srcOffset.z = 0;
11673 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11674 copy_region.dstSubresource.mipLevel = 0;
11675 copy_region.dstSubresource.baseArrayLayer = 0;
11676 copy_region.dstSubresource.layerCount = 1;
11677 copy_region.dstOffset.x = 0;
11678 copy_region.dstOffset.y = 0;
11679 copy_region.dstOffset.z = 0;
11680 copy_region.extent.width = 1;
11681 copy_region.extent.height = 1;
11682 copy_region.extent.depth = 1;
11683
11684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11685 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011686 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011687 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 -060011688 m_errorMonitor->VerifyFound();
11689 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11691 "Cannot copy from an image whose source layout is "
11692 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11693 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011694 m_errorMonitor->SetUnexpectedError(
11695 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011696 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 -060011697 m_errorMonitor->VerifyFound();
11698 // Final src error is due to bad layout type
11699 m_errorMonitor->SetDesiredFailureMsg(
11700 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11701 "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 -070011702 m_errorMonitor->SetUnexpectedError(
11703 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11704 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011705 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 -060011706 m_errorMonitor->VerifyFound();
11707 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11709 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011710 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011711 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 -060011712 m_errorMonitor->VerifyFound();
11713 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11715 "Cannot copy from an image whose dest layout is "
11716 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11717 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011718 m_errorMonitor->SetUnexpectedError(
11719 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011720 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 -060011721 m_errorMonitor->VerifyFound();
11722 m_errorMonitor->SetDesiredFailureMsg(
11723 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11724 "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 -070011725 m_errorMonitor->SetUnexpectedError(
11726 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11727 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011728 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 -060011729 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011730
Cort3b021012016-12-07 12:00:57 -080011731 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11732 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11733 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11734 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11735 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11736 transfer_dst_image_barrier[0].srcAccessMask = 0;
11737 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11738 transfer_dst_image_barrier[0].image = dst_image;
11739 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11740 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11741 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11742 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11743 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11744 transfer_dst_image_barrier[0].image = depth_image;
11745 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11746 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11747 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11748
11749 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011750 VkClearColorValue color_clear_value = {};
11751 VkImageSubresourceRange clear_range;
11752 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11753 clear_range.baseMipLevel = 0;
11754 clear_range.baseArrayLayer = 0;
11755 clear_range.layerCount = 1;
11756 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011757
Cort3b021012016-12-07 12:00:57 -080011758 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11759 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011762 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011763 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011764 // Fail due to provided layout not matching actual current layout for color clear.
11765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011766 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011767 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011768
Cort530cf382016-12-08 09:59:47 -080011769 VkClearDepthStencilValue depth_clear_value = {};
11770 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011771
11772 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11773 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011776 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011777 m_errorMonitor->VerifyFound();
11778 // Fail due to provided layout not matching actual current layout for depth clear.
11779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011780 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011781 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011782
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011783 // Now cause error due to bad image layout transition in PipelineBarrier
11784 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011785 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011786 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011787 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011788 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011789 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11790 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011791 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11793 "You cannot transition the layout of aspect 1 from "
11794 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11795 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011796 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11797 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011798 m_errorMonitor->VerifyFound();
11799
11800 // Finally some layout errors at RenderPass create time
11801 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11802 VkAttachmentReference attach = {};
11803 // perf warning for GENERAL layout w/ non-DS input attachment
11804 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11805 VkSubpassDescription subpass = {};
11806 subpass.inputAttachmentCount = 1;
11807 subpass.pInputAttachments = &attach;
11808 VkRenderPassCreateInfo rpci = {};
11809 rpci.subpassCount = 1;
11810 rpci.pSubpasses = &subpass;
11811 rpci.attachmentCount = 1;
11812 VkAttachmentDescription attach_desc = {};
11813 attach_desc.format = VK_FORMAT_UNDEFINED;
11814 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011815 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011816 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11818 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011819 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11820 m_errorMonitor->VerifyFound();
11821 // error w/ non-general layout
11822 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11823
11824 m_errorMonitor->SetDesiredFailureMsg(
11825 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11826 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11827 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11828 m_errorMonitor->VerifyFound();
11829 subpass.inputAttachmentCount = 0;
11830 subpass.colorAttachmentCount = 1;
11831 subpass.pColorAttachments = &attach;
11832 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11833 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11835 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011836 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11837 m_errorMonitor->VerifyFound();
11838 // error w/ non-color opt or GENERAL layout for color attachment
11839 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11840 m_errorMonitor->SetDesiredFailureMsg(
11841 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11842 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11844 m_errorMonitor->VerifyFound();
11845 subpass.colorAttachmentCount = 0;
11846 subpass.pDepthStencilAttachment = &attach;
11847 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11848 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11850 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011851 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11852 m_errorMonitor->VerifyFound();
11853 // error w/ non-ds opt or GENERAL layout for color attachment
11854 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11856 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11857 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011858 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11859 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011860 // For this error we need a valid renderpass so create default one
11861 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11862 attach.attachment = 0;
11863 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11864 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11865 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11866 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11867 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11868 // Can't do a CLEAR load on READ_ONLY initialLayout
11869 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11870 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11871 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11873 " with invalid first layout "
11874 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11875 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011876 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11877 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011878
Cort3b021012016-12-07 12:00:57 -080011879 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11880 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11881 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011882 vkDestroyImage(m_device->device(), src_image, NULL);
11883 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011884 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011885}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011886
Tobin Ehlise0936662016-10-11 08:10:51 -060011887TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11888 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11889 VkResult err;
11890
11891 ASSERT_NO_FATAL_FAILURE(InitState());
11892
11893 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11894 VkImageTiling tiling;
11895 VkFormatProperties format_properties;
11896 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11897 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11898 tiling = VK_IMAGE_TILING_LINEAR;
11899 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11900 tiling = VK_IMAGE_TILING_OPTIMAL;
11901 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011902 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011903 return;
11904 }
11905
11906 VkDescriptorPoolSize ds_type = {};
11907 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11908 ds_type.descriptorCount = 1;
11909
11910 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11911 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11912 ds_pool_ci.maxSets = 1;
11913 ds_pool_ci.poolSizeCount = 1;
11914 ds_pool_ci.pPoolSizes = &ds_type;
11915 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11916
11917 VkDescriptorPool ds_pool;
11918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11919 ASSERT_VK_SUCCESS(err);
11920
11921 VkDescriptorSetLayoutBinding dsl_binding = {};
11922 dsl_binding.binding = 0;
11923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11924 dsl_binding.descriptorCount = 1;
11925 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11926 dsl_binding.pImmutableSamplers = NULL;
11927
11928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11930 ds_layout_ci.pNext = NULL;
11931 ds_layout_ci.bindingCount = 1;
11932 ds_layout_ci.pBindings = &dsl_binding;
11933
11934 VkDescriptorSetLayout ds_layout;
11935 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11936 ASSERT_VK_SUCCESS(err);
11937
11938 VkDescriptorSetAllocateInfo alloc_info = {};
11939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11940 alloc_info.descriptorSetCount = 1;
11941 alloc_info.descriptorPool = ds_pool;
11942 alloc_info.pSetLayouts = &ds_layout;
11943 VkDescriptorSet descriptor_set;
11944 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11945 ASSERT_VK_SUCCESS(err);
11946
11947 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11948 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11949 pipeline_layout_ci.pNext = NULL;
11950 pipeline_layout_ci.setLayoutCount = 1;
11951 pipeline_layout_ci.pSetLayouts = &ds_layout;
11952 VkPipelineLayout pipeline_layout;
11953 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11954 ASSERT_VK_SUCCESS(err);
11955
11956 VkImageObj image(m_device);
11957 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11958 ASSERT_TRUE(image.initialized());
11959 VkImageView view = image.targetView(tex_format);
11960
11961 VkDescriptorImageInfo image_info = {};
11962 image_info.imageView = view;
11963 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11964
11965 VkWriteDescriptorSet descriptor_write = {};
11966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11967 descriptor_write.dstSet = descriptor_set;
11968 descriptor_write.dstBinding = 0;
11969 descriptor_write.descriptorCount = 1;
11970 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11971 descriptor_write.pImageInfo = &image_info;
11972
11973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11974 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11975 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11977 m_errorMonitor->VerifyFound();
11978
11979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11981 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11983}
11984
Mark Mueller93b938f2016-08-18 10:27:40 -060011985TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011986 TEST_DESCRIPTION(
11987 "Use vkCmdExecuteCommands with invalid state "
11988 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011989
11990 ASSERT_NO_FATAL_FAILURE(InitState());
11991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11992
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011993 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011994 const char *simultaneous_use_message2 =
11995 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11996 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011997
11998 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011999 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012000 command_buffer_allocate_info.commandPool = m_commandPool;
12001 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12002 command_buffer_allocate_info.commandBufferCount = 1;
12003
12004 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012005 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012006 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12007 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012008 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012009 command_buffer_inheritance_info.renderPass = m_renderPass;
12010 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012011
Mark Mueller93b938f2016-08-18 10:27:40 -060012012 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 command_buffer_begin_info.flags =
12014 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012015 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12016
12017 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12018 vkEndCommandBuffer(secondary_command_buffer);
12019
Mark Mueller93b938f2016-08-18 10:27:40 -060012020 VkSubmitInfo submit_info = {};
12021 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12022 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012024
Mark Mueller4042b652016-09-05 22:52:21 -060012025 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12028 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012029 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012030 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012031 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12032 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012033
Dave Houltonfbf52152017-01-06 12:55:29 -070012034 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012036 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012037
Mark Mueller4042b652016-09-05 22:52:21 -060012038 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012039 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12040 m_errorMonitor->SetUnexpectedError(
12041 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12042 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012043 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012044 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12047 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012049 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12050 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012051
12052 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012053
12054 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012055}
12056
Tony Barbour626994c2017-02-08 15:29:37 -070012057TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12058 TEST_DESCRIPTION(
12059 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12060 "errors");
12061 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12062 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12063 ASSERT_NO_FATAL_FAILURE(InitState());
12064
12065 VkCommandBuffer cmd_bufs[2];
12066 VkCommandBufferAllocateInfo alloc_info;
12067 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12068 alloc_info.pNext = NULL;
12069 alloc_info.commandBufferCount = 2;
12070 alloc_info.commandPool = m_commandPool;
12071 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12072 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12073
12074 VkCommandBufferBeginInfo cb_binfo;
12075 cb_binfo.pNext = NULL;
12076 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12077 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12078 cb_binfo.flags = 0;
12079 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12080 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12081 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12082 vkEndCommandBuffer(cmd_bufs[0]);
12083 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12084
12085 VkSubmitInfo submit_info = {};
12086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12087 submit_info.commandBufferCount = 2;
12088 submit_info.pCommandBuffers = duplicates;
12089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12090 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12091 m_errorMonitor->VerifyFound();
12092 vkQueueWaitIdle(m_device->m_queue);
12093
12094 // Set one time use and now look for one time submit
12095 duplicates[0] = duplicates[1] = cmd_bufs[1];
12096 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12097 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12098 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12099 vkEndCommandBuffer(cmd_bufs[1]);
12100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12101 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12102 m_errorMonitor->VerifyFound();
12103 vkQueueWaitIdle(m_device->m_queue);
12104}
12105
Tobin Ehlisb093da82017-01-19 12:05:27 -070012106TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012107 TEST_DESCRIPTION(
12108 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12109 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012110
12111 ASSERT_NO_FATAL_FAILURE(InitState());
12112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12113
12114 std::vector<const char *> device_extension_names;
12115 auto features = m_device->phy().features();
12116 // Make sure gs & ts are disabled
12117 features.geometryShader = false;
12118 features.tessellationShader = false;
12119 // The sacrificial device object
12120 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12121
12122 VkCommandPoolCreateInfo pool_create_info{};
12123 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12124 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12125
12126 VkCommandPool command_pool;
12127 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12128
12129 VkCommandBufferAllocateInfo cmd = {};
12130 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12131 cmd.pNext = NULL;
12132 cmd.commandPool = command_pool;
12133 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12134 cmd.commandBufferCount = 1;
12135
12136 VkCommandBuffer cmd_buffer;
12137 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12138 ASSERT_VK_SUCCESS(err);
12139
12140 VkEvent event;
12141 VkEventCreateInfo evci = {};
12142 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12143 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12144 ASSERT_VK_SUCCESS(result);
12145
12146 VkCommandBufferBeginInfo cbbi = {};
12147 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12148 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12150 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12151 m_errorMonitor->VerifyFound();
12152
12153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12154 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12155 m_errorMonitor->VerifyFound();
12156
12157 vkDestroyEvent(test_device.handle(), event, NULL);
12158 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12159}
12160
Mark Mueller917f6bc2016-08-30 10:57:19 -060012161TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012162 TEST_DESCRIPTION(
12163 "Use vkCmdExecuteCommands with invalid state "
12164 "in primary and secondary command buffers. "
12165 "Delete objects that are inuse. Call VkQueueSubmit "
12166 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012167
12168 ASSERT_NO_FATAL_FAILURE(InitState());
12169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12170
Tony Barbour552f6c02016-12-21 14:34:07 -070012171 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012172
12173 VkEvent event;
12174 VkEventCreateInfo event_create_info = {};
12175 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12176 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012178
Tony Barbour552f6c02016-12-21 14:34:07 -070012179 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012180 vkDestroyEvent(m_device->device(), event, nullptr);
12181
12182 VkSubmitInfo submit_info = {};
12183 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12184 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12188 m_errorMonitor->VerifyFound();
12189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012190 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012191 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12192
12193 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12194
Mark Mueller917f6bc2016-08-30 10:57:19 -060012195 VkSemaphoreCreateInfo semaphore_create_info = {};
12196 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12197 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012199 VkFenceCreateInfo fence_create_info = {};
12200 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12201 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012202 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012203
12204 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012205 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012206 descriptor_pool_type_count.descriptorCount = 1;
12207
12208 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12209 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12210 descriptor_pool_create_info.maxSets = 1;
12211 descriptor_pool_create_info.poolSizeCount = 1;
12212 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012214
12215 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012216 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012217
12218 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012219 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220 descriptorset_layout_binding.descriptorCount = 1;
12221 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12222
12223 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012224 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012225 descriptorset_layout_create_info.bindingCount = 1;
12226 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12227
12228 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012229 ASSERT_VK_SUCCESS(
12230 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012231
12232 VkDescriptorSet descriptorset;
12233 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012235 descriptorset_allocate_info.descriptorSetCount = 1;
12236 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12237 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012239
Mark Mueller4042b652016-09-05 22:52:21 -060012240 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12241
12242 VkDescriptorBufferInfo buffer_info = {};
12243 buffer_info.buffer = buffer_test.GetBuffer();
12244 buffer_info.offset = 0;
12245 buffer_info.range = 1024;
12246
12247 VkWriteDescriptorSet write_descriptor_set = {};
12248 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12249 write_descriptor_set.dstSet = descriptorset;
12250 write_descriptor_set.descriptorCount = 1;
12251 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12252 write_descriptor_set.pBufferInfo = &buffer_info;
12253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12257 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012258
12259 VkPipelineObj pipe(m_device);
12260 pipe.AddColorAttachment();
12261 pipe.AddShader(&vs);
12262 pipe.AddShader(&fs);
12263
12264 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012266 pipeline_layout_create_info.setLayoutCount = 1;
12267 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12268
12269 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012271
12272 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12273
Tony Barbour552f6c02016-12-21 14:34:07 -070012274 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012275 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12279 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012280
Tony Barbour552f6c02016-12-21 14:34:07 -070012281 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012282
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283 submit_info.signalSemaphoreCount = 1;
12284 submit_info.pSignalSemaphores = &semaphore;
12285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012286 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012287
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012289 vkDestroyEvent(m_device->device(), event, nullptr);
12290 m_errorMonitor->VerifyFound();
12291
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012293 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12294 m_errorMonitor->VerifyFound();
12295
Jeremy Hayes08369882017-02-02 10:31:06 -070012296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012297 vkDestroyFence(m_device->device(), fence, nullptr);
12298 m_errorMonitor->VerifyFound();
12299
Tobin Ehlis122207b2016-09-01 08:50:06 -070012300 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012301 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12302 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012303 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012304 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12305 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012307 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12308 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012309 vkDestroyEvent(m_device->device(), event, nullptr);
12310 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12313}
12314
Tobin Ehlis2adda372016-09-01 08:51:06 -070012315TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12316 TEST_DESCRIPTION("Delete in-use query pool.");
12317
12318 ASSERT_NO_FATAL_FAILURE(InitState());
12319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12320
12321 VkQueryPool query_pool;
12322 VkQueryPoolCreateInfo query_pool_ci{};
12323 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12324 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12325 query_pool_ci.queryCount = 1;
12326 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012327 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012328 // Reset query pool to create binding with cmd buffer
12329 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12330
Tony Barbour552f6c02016-12-21 14:34:07 -070012331 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012332
12333 VkSubmitInfo submit_info = {};
12334 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12335 submit_info.commandBufferCount = 1;
12336 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12337 // Submit cmd buffer and then destroy query pool while in-flight
12338 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12339
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012341 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12342 m_errorMonitor->VerifyFound();
12343
12344 vkQueueWaitIdle(m_device->m_queue);
12345 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012346 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12347 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012348 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12349}
12350
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012351TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12352 TEST_DESCRIPTION("Delete in-use pipeline.");
12353
12354 ASSERT_NO_FATAL_FAILURE(InitState());
12355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12356
12357 // Empty pipeline layout used for binding PSO
12358 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12359 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12360 pipeline_layout_ci.setLayoutCount = 0;
12361 pipeline_layout_ci.pSetLayouts = NULL;
12362
12363 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012365 ASSERT_VK_SUCCESS(err);
12366
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012368 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12370 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012371 // Store pipeline handle so we can actually delete it before test finishes
12372 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012373 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012374 VkPipelineObj pipe(m_device);
12375 pipe.AddShader(&vs);
12376 pipe.AddShader(&fs);
12377 pipe.AddColorAttachment();
12378 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12379 delete_this_pipeline = pipe.handle();
12380
Tony Barbour552f6c02016-12-21 14:34:07 -070012381 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012382 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012383 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012384
Tony Barbour552f6c02016-12-21 14:34:07 -070012385 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012386
12387 VkSubmitInfo submit_info = {};
12388 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12389 submit_info.commandBufferCount = 1;
12390 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12391 // Submit cmd buffer and then pipeline destroyed while in-flight
12392 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012393 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012394 m_errorMonitor->VerifyFound();
12395 // Make sure queue finished and then actually delete pipeline
12396 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012397 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12398 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12400 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12401}
12402
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012403TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12404 TEST_DESCRIPTION("Delete in-use imageView.");
12405
12406 ASSERT_NO_FATAL_FAILURE(InitState());
12407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12408
12409 VkDescriptorPoolSize ds_type_count;
12410 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12411 ds_type_count.descriptorCount = 1;
12412
12413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12415 ds_pool_ci.maxSets = 1;
12416 ds_pool_ci.poolSizeCount = 1;
12417 ds_pool_ci.pPoolSizes = &ds_type_count;
12418
12419 VkDescriptorPool ds_pool;
12420 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12421 ASSERT_VK_SUCCESS(err);
12422
12423 VkSamplerCreateInfo sampler_ci = {};
12424 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12425 sampler_ci.pNext = NULL;
12426 sampler_ci.magFilter = VK_FILTER_NEAREST;
12427 sampler_ci.minFilter = VK_FILTER_NEAREST;
12428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12432 sampler_ci.mipLodBias = 1.0;
12433 sampler_ci.anisotropyEnable = VK_FALSE;
12434 sampler_ci.maxAnisotropy = 1;
12435 sampler_ci.compareEnable = VK_FALSE;
12436 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12437 sampler_ci.minLod = 1.0;
12438 sampler_ci.maxLod = 1.0;
12439 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12440 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12441 VkSampler sampler;
12442
12443 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12444 ASSERT_VK_SUCCESS(err);
12445
12446 VkDescriptorSetLayoutBinding layout_binding;
12447 layout_binding.binding = 0;
12448 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12449 layout_binding.descriptorCount = 1;
12450 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12451 layout_binding.pImmutableSamplers = NULL;
12452
12453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12455 ds_layout_ci.bindingCount = 1;
12456 ds_layout_ci.pBindings = &layout_binding;
12457 VkDescriptorSetLayout ds_layout;
12458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12459 ASSERT_VK_SUCCESS(err);
12460
12461 VkDescriptorSetAllocateInfo alloc_info = {};
12462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12463 alloc_info.descriptorSetCount = 1;
12464 alloc_info.descriptorPool = ds_pool;
12465 alloc_info.pSetLayouts = &ds_layout;
12466 VkDescriptorSet descriptor_set;
12467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12468 ASSERT_VK_SUCCESS(err);
12469
12470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12472 pipeline_layout_ci.pNext = NULL;
12473 pipeline_layout_ci.setLayoutCount = 1;
12474 pipeline_layout_ci.pSetLayouts = &ds_layout;
12475
12476 VkPipelineLayout pipeline_layout;
12477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12478 ASSERT_VK_SUCCESS(err);
12479
12480 VkImageObj image(m_device);
12481 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12482 ASSERT_TRUE(image.initialized());
12483
12484 VkImageView view;
12485 VkImageViewCreateInfo ivci = {};
12486 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12487 ivci.image = image.handle();
12488 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12489 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12490 ivci.subresourceRange.layerCount = 1;
12491 ivci.subresourceRange.baseMipLevel = 0;
12492 ivci.subresourceRange.levelCount = 1;
12493 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12494
12495 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12496 ASSERT_VK_SUCCESS(err);
12497
12498 VkDescriptorImageInfo image_info{};
12499 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12500 image_info.imageView = view;
12501 image_info.sampler = sampler;
12502
12503 VkWriteDescriptorSet descriptor_write = {};
12504 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12505 descriptor_write.dstSet = descriptor_set;
12506 descriptor_write.dstBinding = 0;
12507 descriptor_write.descriptorCount = 1;
12508 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12509 descriptor_write.pImageInfo = &image_info;
12510
12511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12512
12513 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012514 char const *vsSource =
12515 "#version 450\n"
12516 "\n"
12517 "out gl_PerVertex { \n"
12518 " vec4 gl_Position;\n"
12519 "};\n"
12520 "void main(){\n"
12521 " gl_Position = vec4(1);\n"
12522 "}\n";
12523 char const *fsSource =
12524 "#version 450\n"
12525 "\n"
12526 "layout(set=0, binding=0) uniform sampler2D s;\n"
12527 "layout(location=0) out vec4 x;\n"
12528 "void main(){\n"
12529 " x = texture(s, vec2(1));\n"
12530 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12533 VkPipelineObj pipe(m_device);
12534 pipe.AddShader(&vs);
12535 pipe.AddShader(&fs);
12536 pipe.AddColorAttachment();
12537 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12538
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012540
Tony Barbour552f6c02016-12-21 14:34:07 -070012541 m_commandBuffer->BeginCommandBuffer();
12542 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012543 // Bind pipeline to cmd buffer
12544 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12545 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12546 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012547
12548 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12549 VkRect2D scissor = {{0, 0}, {16, 16}};
12550 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12551 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12552
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012553 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012554 m_commandBuffer->EndRenderPass();
12555 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012556 // Submit cmd buffer then destroy sampler
12557 VkSubmitInfo submit_info = {};
12558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12559 submit_info.commandBufferCount = 1;
12560 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12561 // Submit cmd buffer and then destroy imageView while in-flight
12562 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12563
12564 vkDestroyImageView(m_device->device(), view, nullptr);
12565 m_errorMonitor->VerifyFound();
12566 vkQueueWaitIdle(m_device->m_queue);
12567 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012568 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12569 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012570 vkDestroyImageView(m_device->device(), view, NULL);
12571 vkDestroySampler(m_device->device(), sampler, nullptr);
12572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12575}
12576
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012577TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12578 TEST_DESCRIPTION("Delete in-use bufferView.");
12579
12580 ASSERT_NO_FATAL_FAILURE(InitState());
12581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12582
12583 VkDescriptorPoolSize ds_type_count;
12584 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12585 ds_type_count.descriptorCount = 1;
12586
12587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12589 ds_pool_ci.maxSets = 1;
12590 ds_pool_ci.poolSizeCount = 1;
12591 ds_pool_ci.pPoolSizes = &ds_type_count;
12592
12593 VkDescriptorPool ds_pool;
12594 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12595 ASSERT_VK_SUCCESS(err);
12596
12597 VkDescriptorSetLayoutBinding layout_binding;
12598 layout_binding.binding = 0;
12599 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12600 layout_binding.descriptorCount = 1;
12601 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12602 layout_binding.pImmutableSamplers = NULL;
12603
12604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12606 ds_layout_ci.bindingCount = 1;
12607 ds_layout_ci.pBindings = &layout_binding;
12608 VkDescriptorSetLayout ds_layout;
12609 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12610 ASSERT_VK_SUCCESS(err);
12611
12612 VkDescriptorSetAllocateInfo alloc_info = {};
12613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12614 alloc_info.descriptorSetCount = 1;
12615 alloc_info.descriptorPool = ds_pool;
12616 alloc_info.pSetLayouts = &ds_layout;
12617 VkDescriptorSet descriptor_set;
12618 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12619 ASSERT_VK_SUCCESS(err);
12620
12621 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12622 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12623 pipeline_layout_ci.pNext = NULL;
12624 pipeline_layout_ci.setLayoutCount = 1;
12625 pipeline_layout_ci.pSetLayouts = &ds_layout;
12626
12627 VkPipelineLayout pipeline_layout;
12628 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12629 ASSERT_VK_SUCCESS(err);
12630
12631 VkBuffer buffer;
12632 uint32_t queue_family_index = 0;
12633 VkBufferCreateInfo buffer_create_info = {};
12634 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12635 buffer_create_info.size = 1024;
12636 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12637 buffer_create_info.queueFamilyIndexCount = 1;
12638 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12639
12640 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12641 ASSERT_VK_SUCCESS(err);
12642
12643 VkMemoryRequirements memory_reqs;
12644 VkDeviceMemory buffer_memory;
12645
12646 VkMemoryAllocateInfo memory_info = {};
12647 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12648 memory_info.allocationSize = 0;
12649 memory_info.memoryTypeIndex = 0;
12650
12651 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12652 memory_info.allocationSize = memory_reqs.size;
12653 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12654 ASSERT_TRUE(pass);
12655
12656 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12657 ASSERT_VK_SUCCESS(err);
12658 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12659 ASSERT_VK_SUCCESS(err);
12660
12661 VkBufferView view;
12662 VkBufferViewCreateInfo bvci = {};
12663 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12664 bvci.buffer = buffer;
12665 bvci.format = VK_FORMAT_R8_UNORM;
12666 bvci.range = VK_WHOLE_SIZE;
12667
12668 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12669 ASSERT_VK_SUCCESS(err);
12670
12671 VkWriteDescriptorSet descriptor_write = {};
12672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12673 descriptor_write.dstSet = descriptor_set;
12674 descriptor_write.dstBinding = 0;
12675 descriptor_write.descriptorCount = 1;
12676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12677 descriptor_write.pTexelBufferView = &view;
12678
12679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012681 char const *vsSource =
12682 "#version 450\n"
12683 "\n"
12684 "out gl_PerVertex { \n"
12685 " vec4 gl_Position;\n"
12686 "};\n"
12687 "void main(){\n"
12688 " gl_Position = vec4(1);\n"
12689 "}\n";
12690 char const *fsSource =
12691 "#version 450\n"
12692 "\n"
12693 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12694 "layout(location=0) out vec4 x;\n"
12695 "void main(){\n"
12696 " x = imageLoad(s, 0);\n"
12697 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12700 VkPipelineObj pipe(m_device);
12701 pipe.AddShader(&vs);
12702 pipe.AddShader(&fs);
12703 pipe.AddColorAttachment();
12704 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12705
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012707
Tony Barbour552f6c02016-12-21 14:34:07 -070012708 m_commandBuffer->BeginCommandBuffer();
12709 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012710 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12711 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12712 VkRect2D scissor = {{0, 0}, {16, 16}};
12713 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12714 // Bind pipeline to cmd buffer
12715 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12716 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12717 &descriptor_set, 0, nullptr);
12718 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012719 m_commandBuffer->EndRenderPass();
12720 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012721
12722 VkSubmitInfo submit_info = {};
12723 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12724 submit_info.commandBufferCount = 1;
12725 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12726 // Submit cmd buffer and then destroy bufferView while in-flight
12727 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12728
12729 vkDestroyBufferView(m_device->device(), view, nullptr);
12730 m_errorMonitor->VerifyFound();
12731 vkQueueWaitIdle(m_device->m_queue);
12732 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012733 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12734 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012735 vkDestroyBufferView(m_device->device(), view, NULL);
12736 vkDestroyBuffer(m_device->device(), buffer, NULL);
12737 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12741}
12742
Tobin Ehlis209532e2016-09-07 13:52:18 -060012743TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12744 TEST_DESCRIPTION("Delete in-use sampler.");
12745
12746 ASSERT_NO_FATAL_FAILURE(InitState());
12747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12748
12749 VkDescriptorPoolSize ds_type_count;
12750 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12751 ds_type_count.descriptorCount = 1;
12752
12753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12755 ds_pool_ci.maxSets = 1;
12756 ds_pool_ci.poolSizeCount = 1;
12757 ds_pool_ci.pPoolSizes = &ds_type_count;
12758
12759 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012760 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012761 ASSERT_VK_SUCCESS(err);
12762
12763 VkSamplerCreateInfo sampler_ci = {};
12764 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12765 sampler_ci.pNext = NULL;
12766 sampler_ci.magFilter = VK_FILTER_NEAREST;
12767 sampler_ci.minFilter = VK_FILTER_NEAREST;
12768 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12769 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12770 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12771 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12772 sampler_ci.mipLodBias = 1.0;
12773 sampler_ci.anisotropyEnable = VK_FALSE;
12774 sampler_ci.maxAnisotropy = 1;
12775 sampler_ci.compareEnable = VK_FALSE;
12776 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12777 sampler_ci.minLod = 1.0;
12778 sampler_ci.maxLod = 1.0;
12779 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12780 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12781 VkSampler sampler;
12782
12783 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12784 ASSERT_VK_SUCCESS(err);
12785
12786 VkDescriptorSetLayoutBinding layout_binding;
12787 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012788 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012789 layout_binding.descriptorCount = 1;
12790 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12791 layout_binding.pImmutableSamplers = NULL;
12792
12793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12795 ds_layout_ci.bindingCount = 1;
12796 ds_layout_ci.pBindings = &layout_binding;
12797 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012798 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012799 ASSERT_VK_SUCCESS(err);
12800
12801 VkDescriptorSetAllocateInfo alloc_info = {};
12802 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12803 alloc_info.descriptorSetCount = 1;
12804 alloc_info.descriptorPool = ds_pool;
12805 alloc_info.pSetLayouts = &ds_layout;
12806 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012807 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012808 ASSERT_VK_SUCCESS(err);
12809
12810 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12811 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12812 pipeline_layout_ci.pNext = NULL;
12813 pipeline_layout_ci.setLayoutCount = 1;
12814 pipeline_layout_ci.pSetLayouts = &ds_layout;
12815
12816 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012817 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012818 ASSERT_VK_SUCCESS(err);
12819
12820 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012821 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 -060012822 ASSERT_TRUE(image.initialized());
12823
12824 VkImageView view;
12825 VkImageViewCreateInfo ivci = {};
12826 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12827 ivci.image = image.handle();
12828 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12829 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12830 ivci.subresourceRange.layerCount = 1;
12831 ivci.subresourceRange.baseMipLevel = 0;
12832 ivci.subresourceRange.levelCount = 1;
12833 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12834
12835 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12836 ASSERT_VK_SUCCESS(err);
12837
12838 VkDescriptorImageInfo image_info{};
12839 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12840 image_info.imageView = view;
12841 image_info.sampler = sampler;
12842
12843 VkWriteDescriptorSet descriptor_write = {};
12844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12845 descriptor_write.dstSet = descriptor_set;
12846 descriptor_write.dstBinding = 0;
12847 descriptor_write.descriptorCount = 1;
12848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12849 descriptor_write.pImageInfo = &image_info;
12850
12851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12852
12853 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012854 char const *vsSource =
12855 "#version 450\n"
12856 "\n"
12857 "out gl_PerVertex { \n"
12858 " vec4 gl_Position;\n"
12859 "};\n"
12860 "void main(){\n"
12861 " gl_Position = vec4(1);\n"
12862 "}\n";
12863 char const *fsSource =
12864 "#version 450\n"
12865 "\n"
12866 "layout(set=0, binding=0) uniform sampler2D s;\n"
12867 "layout(location=0) out vec4 x;\n"
12868 "void main(){\n"
12869 " x = texture(s, vec2(1));\n"
12870 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012871 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12872 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12873 VkPipelineObj pipe(m_device);
12874 pipe.AddShader(&vs);
12875 pipe.AddShader(&fs);
12876 pipe.AddColorAttachment();
12877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12878
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012880
Tony Barbour552f6c02016-12-21 14:34:07 -070012881 m_commandBuffer->BeginCommandBuffer();
12882 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012883 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012884 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12886 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012887
12888 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12889 VkRect2D scissor = {{0, 0}, {16, 16}};
12890 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12891 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12892
Tobin Ehlis209532e2016-09-07 13:52:18 -060012893 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012894 m_commandBuffer->EndRenderPass();
12895 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012896 // Submit cmd buffer then destroy sampler
12897 VkSubmitInfo submit_info = {};
12898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12899 submit_info.commandBufferCount = 1;
12900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12901 // Submit cmd buffer and then destroy sampler while in-flight
12902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012904 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012905 m_errorMonitor->VerifyFound();
12906 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012907
Tobin Ehlis209532e2016-09-07 13:52:18 -060012908 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012909 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12910 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012911 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012912 vkDestroyImageView(m_device->device(), view, NULL);
12913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12916}
12917
Mark Mueller1cd9f412016-08-25 13:23:52 -060012918TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012919 TEST_DESCRIPTION(
12920 "Call VkQueueSubmit with a semaphore that is already "
12921 "signaled but not waited on by the queue. Wait on a "
12922 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012923
12924 ASSERT_NO_FATAL_FAILURE(InitState());
12925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012927 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 -070012928 const char *invalid_fence_wait_message =
12929 " which has not been submitted on a Queue or during "
12930 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012931
Tony Barbour552f6c02016-12-21 14:34:07 -070012932 m_commandBuffer->BeginCommandBuffer();
12933 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012934
12935 VkSemaphoreCreateInfo semaphore_create_info = {};
12936 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12937 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012939 VkSubmitInfo submit_info = {};
12940 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12941 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012943 submit_info.signalSemaphoreCount = 1;
12944 submit_info.pSignalSemaphores = &semaphore;
12945 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012946 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012947 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012948 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012949 m_commandBuffer->BeginCommandBuffer();
12950 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12953 m_errorMonitor->VerifyFound();
12954
Mark Mueller1cd9f412016-08-25 13:23:52 -060012955 VkFenceCreateInfo fence_create_info = {};
12956 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12957 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12962 m_errorMonitor->VerifyFound();
12963
Mark Mueller4042b652016-09-05 22:52:21 -060012964 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012965 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012966 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12967}
12968
Tobin Ehlis4af23302016-07-19 10:50:30 -060012969TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012970 TEST_DESCRIPTION(
12971 "Bind a secondary command buffer with with a framebuffer "
12972 "that does not match the framebuffer for the active "
12973 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012974 ASSERT_NO_FATAL_FAILURE(InitState());
12975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12976
12977 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 VkAttachmentDescription attachment = {0,
12979 VK_FORMAT_B8G8R8A8_UNORM,
12980 VK_SAMPLE_COUNT_1_BIT,
12981 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12982 VK_ATTACHMENT_STORE_OP_STORE,
12983 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12984 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12985 VK_IMAGE_LAYOUT_UNDEFINED,
12986 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012992 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012993
12994 VkRenderPass rp;
12995 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12996 ASSERT_VK_SUCCESS(err);
12997
12998 // A compatible framebuffer.
12999 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013000 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 -060013001 ASSERT_TRUE(image.initialized());
13002
13003 VkImageViewCreateInfo ivci = {
13004 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13005 nullptr,
13006 0,
13007 image.handle(),
13008 VK_IMAGE_VIEW_TYPE_2D,
13009 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013010 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13011 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013012 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13013 };
13014 VkImageView view;
13015 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13016 ASSERT_VK_SUCCESS(err);
13017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013018 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019 VkFramebuffer fb;
13020 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13021 ASSERT_VK_SUCCESS(err);
13022
13023 VkCommandBufferAllocateInfo cbai = {};
13024 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13025 cbai.commandPool = m_commandPool;
13026 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13027 cbai.commandBufferCount = 1;
13028
13029 VkCommandBuffer sec_cb;
13030 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13031 ASSERT_VK_SUCCESS(err);
13032 VkCommandBufferBeginInfo cbbi = {};
13033 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013034 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035 cbii.renderPass = renderPass();
13036 cbii.framebuffer = fb;
13037 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13038 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 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 -060013040 cbbi.pInheritanceInfo = &cbii;
13041 vkBeginCommandBuffer(sec_cb, &cbbi);
13042 vkEndCommandBuffer(sec_cb);
13043
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013044 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013045 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13046 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013049 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013050 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13051 m_errorMonitor->VerifyFound();
13052 // Cleanup
13053 vkDestroyImageView(m_device->device(), view, NULL);
13054 vkDestroyRenderPass(m_device->device(), rp, NULL);
13055 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13056}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013057
13058TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 TEST_DESCRIPTION(
13060 "If logicOp is available on the device, set it to an "
13061 "invalid value. If logicOp is not available, attempt to "
13062 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063 ASSERT_NO_FATAL_FAILURE(InitState());
13064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13065
13066 auto features = m_device->phy().features();
13067 // Set the expected error depending on whether or not logicOp available
13068 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13070 "If logic operations feature not "
13071 "enabled, logicOpEnable must be "
13072 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013073 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013075 }
13076 // Create a pipeline using logicOp
13077 VkResult err;
13078
13079 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13080 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13081
13082 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013084 ASSERT_VK_SUCCESS(err);
13085
13086 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13087 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13088 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013089 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013090 vp_state_ci.pViewports = &vp;
13091 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013092 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013093 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013094
13095 VkPipelineShaderStageCreateInfo shaderStages[2];
13096 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013098 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13099 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013100 shaderStages[0] = vs.GetStageCreateInfo();
13101 shaderStages[1] = fs.GetStageCreateInfo();
13102
13103 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13104 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13105
13106 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13107 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13108 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13109
13110 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13111 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013112 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013113
13114 VkPipelineColorBlendAttachmentState att = {};
13115 att.blendEnable = VK_FALSE;
13116 att.colorWriteMask = 0xf;
13117
13118 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13119 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13120 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13121 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013122 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013123 cb_ci.attachmentCount = 1;
13124 cb_ci.pAttachments = &att;
13125
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013126 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13127 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13128 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13129
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013130 VkGraphicsPipelineCreateInfo gp_ci = {};
13131 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13132 gp_ci.stageCount = 2;
13133 gp_ci.pStages = shaderStages;
13134 gp_ci.pVertexInputState = &vi_ci;
13135 gp_ci.pInputAssemblyState = &ia_ci;
13136 gp_ci.pViewportState = &vp_state_ci;
13137 gp_ci.pRasterizationState = &rs_ci;
13138 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013139 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013140 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13141 gp_ci.layout = pipeline_layout;
13142 gp_ci.renderPass = renderPass();
13143
13144 VkPipelineCacheCreateInfo pc_ci = {};
13145 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13146
13147 VkPipeline pipeline;
13148 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013149 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013150 ASSERT_VK_SUCCESS(err);
13151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013153 m_errorMonitor->VerifyFound();
13154 if (VK_SUCCESS == err) {
13155 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13156 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13159}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013160
Mike Stroyanaccf7692015-05-12 16:00:45 -060013161#if GTEST_IS_THREADSAFE
13162struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013163 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013164 VkEvent event;
13165 bool bailout;
13166};
13167
Karl Schultz6addd812016-02-02 17:17:23 -070013168extern "C" void *AddToCommandBuffer(void *arg) {
13169 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013170
Mike Stroyana6d14942016-07-13 15:10:05 -060013171 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013173 if (data->bailout) {
13174 break;
13175 }
13176 }
13177 return NULL;
13178}
13179
Karl Schultz6addd812016-02-02 17:17:23 -070013180TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013181 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013184
Mike Stroyanaccf7692015-05-12 16:00:45 -060013185 ASSERT_NO_FATAL_FAILURE(InitState());
13186 ASSERT_NO_FATAL_FAILURE(InitViewport());
13187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13188
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013189 // Calls AllocateCommandBuffers
13190 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013191
13192 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013193 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194
13195 VkEventCreateInfo event_info;
13196 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013197 VkResult err;
13198
13199 memset(&event_info, 0, sizeof(event_info));
13200 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13201
Chia-I Wuf7458c52015-10-26 21:10:41 +080013202 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013203 ASSERT_VK_SUCCESS(err);
13204
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205 err = vkResetEvent(device(), event);
13206 ASSERT_VK_SUCCESS(err);
13207
13208 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013209 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210 data.event = event;
13211 data.bailout = false;
13212 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013213
13214 // First do some correct operations using multiple threads.
13215 // Add many entries to command buffer from another thread.
13216 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13217 // Make non-conflicting calls from this thread at the same time.
13218 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013219 uint32_t count;
13220 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013221 }
13222 test_platform_thread_join(thread, NULL);
13223
13224 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013225 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013226 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227 // Add many entries to command buffer from this thread at the same time.
13228 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013229
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013230 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013231 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013232
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013233 m_errorMonitor->SetBailout(NULL);
13234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013235 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013236
Chia-I Wuf7458c52015-10-26 21:10:41 +080013237 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013238}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013239#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013240
Karl Schultz6addd812016-02-02 17:17:23 -070013241TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013242 TEST_DESCRIPTION(
13243 "Test that an error is produced for a spirv module "
13244 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013248 ASSERT_NO_FATAL_FAILURE(InitState());
13249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13250
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013251 VkShaderModule module;
13252 VkShaderModuleCreateInfo moduleCreateInfo;
13253 struct icd_spv_header spv;
13254
13255 spv.magic = ICD_SPV_MAGIC;
13256 spv.version = ICD_SPV_VERSION;
13257 spv.gen_magic = 0;
13258
13259 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13260 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013261 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262 moduleCreateInfo.codeSize = 4;
13263 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013264 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013265
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013266 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013267}
13268
Karl Schultz6addd812016-02-02 17:17:23 -070013269TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013270 TEST_DESCRIPTION(
13271 "Test that an error is produced for a spirv module "
13272 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013275
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 ASSERT_NO_FATAL_FAILURE(InitState());
13277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13278
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013279 VkShaderModule module;
13280 VkShaderModuleCreateInfo moduleCreateInfo;
13281 struct icd_spv_header spv;
13282
13283 spv.magic = ~ICD_SPV_MAGIC;
13284 spv.version = ICD_SPV_VERSION;
13285 spv.gen_magic = 0;
13286
13287 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13288 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013289 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13291 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013292 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013294 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295}
13296
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013297#if 0
13298// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013299TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013301 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013302
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013303 ASSERT_NO_FATAL_FAILURE(InitState());
13304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13305
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013306 VkShaderModule module;
13307 VkShaderModuleCreateInfo moduleCreateInfo;
13308 struct icd_spv_header spv;
13309
13310 spv.magic = ICD_SPV_MAGIC;
13311 spv.version = ~ICD_SPV_VERSION;
13312 spv.gen_magic = 0;
13313
13314 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13315 moduleCreateInfo.pNext = NULL;
13316
Karl Schultz6addd812016-02-02 17:17:23 -070013317 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13319 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013320 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013322 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013323}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013324#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013325
Karl Schultz6addd812016-02-02 17:17:23 -070013326TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013327 TEST_DESCRIPTION(
13328 "Test that a warning is produced for a vertex output that "
13329 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013331
Chris Forbes9f7ff632015-05-25 11:13:08 +120013332 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013335 char const *vsSource =
13336 "#version 450\n"
13337 "\n"
13338 "layout(location=0) out float x;\n"
13339 "out gl_PerVertex {\n"
13340 " vec4 gl_Position;\n"
13341 "};\n"
13342 "void main(){\n"
13343 " gl_Position = vec4(1);\n"
13344 " x = 0;\n"
13345 "}\n";
13346 char const *fsSource =
13347 "#version 450\n"
13348 "\n"
13349 "layout(location=0) out vec4 color;\n"
13350 "void main(){\n"
13351 " color = vec4(1);\n"
13352 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013353
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013356
13357 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013358 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359 pipe.AddShader(&vs);
13360 pipe.AddShader(&fs);
13361
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362 VkDescriptorSetObj descriptorSet(m_device);
13363 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013365
Tony Barbour5781e8f2015-08-04 16:23:11 -060013366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013368 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013369}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013370
Mark Mueller098c9cb2016-09-08 09:01:57 -060013371TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13372 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13373
13374 ASSERT_NO_FATAL_FAILURE(InitState());
13375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13376
13377 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013378 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013379
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013380 char const *vsSource =
13381 "#version 450\n"
13382 "\n"
13383 "out gl_PerVertex {\n"
13384 " vec4 gl_Position;\n"
13385 "};\n"
13386 "void main(){\n"
13387 " gl_Position = vec4(1);\n"
13388 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013389
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013390 char const *fsSource =
13391 "#version 450\n"
13392 "\n"
13393 "layout (constant_id = 0) const float r = 0.0f;\n"
13394 "layout(location = 0) out vec4 uFragColor;\n"
13395 "void main(){\n"
13396 " uFragColor = vec4(r,1,0,1);\n"
13397 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013398
13399 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13400 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13401
13402 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13403 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13404
13405 VkPipelineLayout pipeline_layout;
13406 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13407
13408 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13409 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13410 vp_state_create_info.viewportCount = 1;
13411 VkViewport viewport = {};
13412 vp_state_create_info.pViewports = &viewport;
13413 vp_state_create_info.scissorCount = 1;
13414 VkRect2D scissors = {};
13415 vp_state_create_info.pScissors = &scissors;
13416
13417 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13418
13419 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13420 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13421 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13422 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13423
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013424 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013425
13426 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13427 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13428
13429 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13430 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13431 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13432
13433 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13434 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13435 rasterization_state_create_info.pNext = nullptr;
13436 rasterization_state_create_info.lineWidth = 1.0f;
13437 rasterization_state_create_info.rasterizerDiscardEnable = true;
13438
13439 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13440 color_blend_attachment_state.blendEnable = VK_FALSE;
13441 color_blend_attachment_state.colorWriteMask = 0xf;
13442
13443 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13444 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13445 color_blend_state_create_info.attachmentCount = 1;
13446 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13447
13448 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13449 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13450 graphicspipe_create_info.stageCount = 2;
13451 graphicspipe_create_info.pStages = shader_stage_create_info;
13452 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13453 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13454 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13455 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13456 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13457 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13458 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13459 graphicspipe_create_info.layout = pipeline_layout;
13460 graphicspipe_create_info.renderPass = renderPass();
13461
13462 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13463 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13464
13465 VkPipelineCache pipelineCache;
13466 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13467
13468 // This structure maps constant ids to data locations.
13469 const VkSpecializationMapEntry entry =
13470 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013471 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013472
13473 uint32_t data = 1;
13474
13475 // Set up the info describing spec map and data
13476 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013477 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013478 };
13479 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13480
13481 VkPipeline pipeline;
13482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13483 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13484 m_errorMonitor->VerifyFound();
13485
13486 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13487 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13488}
13489
13490TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13491 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13492
13493 ASSERT_NO_FATAL_FAILURE(InitState());
13494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13495
13496 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13497
13498 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13499 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13500 descriptor_pool_type_count[0].descriptorCount = 1;
13501 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13502 descriptor_pool_type_count[1].descriptorCount = 1;
13503
13504 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13505 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13506 descriptor_pool_create_info.maxSets = 1;
13507 descriptor_pool_create_info.poolSizeCount = 2;
13508 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13509 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13510
13511 VkDescriptorPool descriptorset_pool;
13512 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13513
13514 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13515 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13516 descriptorset_layout_binding.descriptorCount = 1;
13517 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13518
13519 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13520 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13521 descriptorset_layout_create_info.bindingCount = 1;
13522 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13523
13524 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013525 ASSERT_VK_SUCCESS(
13526 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013527
13528 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13529 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13530 descriptorset_allocate_info.descriptorSetCount = 1;
13531 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13532 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13533 VkDescriptorSet descriptorset;
13534 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13535
13536 // Challenge core_validation with a non uniform buffer type.
13537 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13538
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013539 char const *vsSource =
13540 "#version 450\n"
13541 "\n"
13542 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13543 " mat4 mvp;\n"
13544 "} ubuf;\n"
13545 "out gl_PerVertex {\n"
13546 " vec4 gl_Position;\n"
13547 "};\n"
13548 "void main(){\n"
13549 " gl_Position = ubuf.mvp * vec4(1);\n"
13550 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013551
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013552 char const *fsSource =
13553 "#version 450\n"
13554 "\n"
13555 "layout(location = 0) out vec4 uFragColor;\n"
13556 "void main(){\n"
13557 " uFragColor = vec4(0,1,0,1);\n"
13558 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013559
13560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13562
13563 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13564 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13565 pipeline_layout_create_info.setLayoutCount = 1;
13566 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13567
13568 VkPipelineLayout pipeline_layout;
13569 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13570
13571 VkPipelineObj pipe(m_device);
13572 pipe.AddColorAttachment();
13573 pipe.AddShader(&vs);
13574 pipe.AddShader(&fs);
13575
13576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13578 m_errorMonitor->VerifyFound();
13579
13580 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13581 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13582 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13583}
13584
13585TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13586 TEST_DESCRIPTION(
13587 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13588
13589 ASSERT_NO_FATAL_FAILURE(InitState());
13590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13591
13592 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13593
13594 VkDescriptorPoolSize descriptor_pool_type_count = {};
13595 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13596 descriptor_pool_type_count.descriptorCount = 1;
13597
13598 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13599 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13600 descriptor_pool_create_info.maxSets = 1;
13601 descriptor_pool_create_info.poolSizeCount = 1;
13602 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13603 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13604
13605 VkDescriptorPool descriptorset_pool;
13606 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13607
13608 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13609 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13610 descriptorset_layout_binding.descriptorCount = 1;
13611 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13612 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13613
13614 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13615 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13616 descriptorset_layout_create_info.bindingCount = 1;
13617 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13618
13619 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013620 ASSERT_VK_SUCCESS(
13621 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013622
13623 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13624 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13625 descriptorset_allocate_info.descriptorSetCount = 1;
13626 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13627 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13628 VkDescriptorSet descriptorset;
13629 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13630
13631 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13632
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013633 char const *vsSource =
13634 "#version 450\n"
13635 "\n"
13636 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13637 " mat4 mvp;\n"
13638 "} ubuf;\n"
13639 "out gl_PerVertex {\n"
13640 " vec4 gl_Position;\n"
13641 "};\n"
13642 "void main(){\n"
13643 " gl_Position = ubuf.mvp * vec4(1);\n"
13644 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013646 char const *fsSource =
13647 "#version 450\n"
13648 "\n"
13649 "layout(location = 0) out vec4 uFragColor;\n"
13650 "void main(){\n"
13651 " uFragColor = vec4(0,1,0,1);\n"
13652 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013653
13654 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13655 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13656
13657 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13658 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13659 pipeline_layout_create_info.setLayoutCount = 1;
13660 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13661
13662 VkPipelineLayout pipeline_layout;
13663 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13664
13665 VkPipelineObj pipe(m_device);
13666 pipe.AddColorAttachment();
13667 pipe.AddShader(&vs);
13668 pipe.AddShader(&fs);
13669
13670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13671 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13672 m_errorMonitor->VerifyFound();
13673
13674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13675 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13676 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13677}
13678
13679TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013680 TEST_DESCRIPTION(
13681 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13682 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013683
13684 ASSERT_NO_FATAL_FAILURE(InitState());
13685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13686
13687 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013688 "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 -060013689
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013690 char const *vsSource =
13691 "#version 450\n"
13692 "\n"
13693 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13694 "out gl_PerVertex {\n"
13695 " vec4 gl_Position;\n"
13696 "};\n"
13697 "void main(){\n"
13698 " gl_Position = vec4(consts.x);\n"
13699 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013700
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013701 char const *fsSource =
13702 "#version 450\n"
13703 "\n"
13704 "layout(location = 0) out vec4 uFragColor;\n"
13705 "void main(){\n"
13706 " uFragColor = vec4(0,1,0,1);\n"
13707 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013708
13709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13711
13712 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13713 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13714
13715 // Set up a push constant range
13716 VkPushConstantRange push_constant_ranges = {};
13717 // Set to the wrong stage to challenge core_validation
13718 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13719 push_constant_ranges.size = 4;
13720
13721 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13722 pipeline_layout_create_info.pushConstantRangeCount = 1;
13723
13724 VkPipelineLayout pipeline_layout;
13725 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13726
13727 VkPipelineObj pipe(m_device);
13728 pipe.AddColorAttachment();
13729 pipe.AddShader(&vs);
13730 pipe.AddShader(&fs);
13731
13732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13733 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13734 m_errorMonitor->VerifyFound();
13735
13736 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13737}
13738
13739TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13740 TEST_DESCRIPTION(
13741 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13742
13743 ASSERT_NO_FATAL_FAILURE(InitState());
13744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13745
13746 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013747 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013748
13749 // Some awkward steps are required to test with custom device features.
13750 std::vector<const char *> device_extension_names;
13751 auto features = m_device->phy().features();
13752 // Disable support for 64 bit floats
13753 features.shaderFloat64 = false;
13754 // The sacrificial device object
13755 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13756
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013757 char const *vsSource =
13758 "#version 450\n"
13759 "\n"
13760 "out gl_PerVertex {\n"
13761 " vec4 gl_Position;\n"
13762 "};\n"
13763 "void main(){\n"
13764 " gl_Position = vec4(1);\n"
13765 "}\n";
13766 char const *fsSource =
13767 "#version 450\n"
13768 "\n"
13769 "layout(location=0) out vec4 color;\n"
13770 "void main(){\n"
13771 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13772 " color = vec4(green);\n"
13773 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013774
13775 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13776 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13777
13778 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013779
13780 VkPipelineObj pipe(&test_device);
13781 pipe.AddColorAttachment();
13782 pipe.AddShader(&vs);
13783 pipe.AddShader(&fs);
13784
13785 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13786 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13787 VkPipelineLayout pipeline_layout;
13788 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13789
13790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13791 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13792 m_errorMonitor->VerifyFound();
13793
13794 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13795}
13796
13797TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13798 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13799
13800 ASSERT_NO_FATAL_FAILURE(InitState());
13801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13802
13803 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13804
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013805 char const *vsSource =
13806 "#version 450\n"
13807 "\n"
13808 "out gl_PerVertex {\n"
13809 " vec4 gl_Position;\n"
13810 "};\n"
13811 "layout(xfb_buffer = 1) out;"
13812 "void main(){\n"
13813 " gl_Position = vec4(1);\n"
13814 "}\n";
13815 char const *fsSource =
13816 "#version 450\n"
13817 "\n"
13818 "layout(location=0) out vec4 color;\n"
13819 "void main(){\n"
13820 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13821 " color = vec4(green);\n"
13822 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013823
13824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13826
13827 VkPipelineObj pipe(m_device);
13828 pipe.AddColorAttachment();
13829 pipe.AddShader(&vs);
13830 pipe.AddShader(&fs);
13831
13832 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13833 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13834 VkPipelineLayout pipeline_layout;
13835 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13836
13837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13838 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13839 m_errorMonitor->VerifyFound();
13840
13841 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13842}
13843
Karl Schultz6addd812016-02-02 17:17:23 -070013844TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013845 TEST_DESCRIPTION(
13846 "Test that an error is produced for a fragment shader input "
13847 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013850
Chris Forbes59cb88d2015-05-25 11:13:13 +120013851 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013854 char const *vsSource =
13855 "#version 450\n"
13856 "\n"
13857 "out gl_PerVertex {\n"
13858 " vec4 gl_Position;\n"
13859 "};\n"
13860 "void main(){\n"
13861 " gl_Position = vec4(1);\n"
13862 "}\n";
13863 char const *fsSource =
13864 "#version 450\n"
13865 "\n"
13866 "layout(location=0) in float x;\n"
13867 "layout(location=0) out vec4 color;\n"
13868 "void main(){\n"
13869 " color = vec4(x);\n"
13870 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013871
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013874
13875 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013876 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013877 pipe.AddShader(&vs);
13878 pipe.AddShader(&fs);
13879
Chris Forbes59cb88d2015-05-25 11:13:13 +120013880 VkDescriptorSetObj descriptorSet(m_device);
13881 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013883
Tony Barbour5781e8f2015-08-04 16:23:11 -060013884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013885
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013886 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013887}
13888
Karl Schultz6addd812016-02-02 17:17:23 -070013889TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013890 TEST_DESCRIPTION(
13891 "Test that an error is produced for a fragment shader input "
13892 "within an interace block, which is not present in the outputs "
13893 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013895
13896 ASSERT_NO_FATAL_FAILURE(InitState());
13897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13898
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013899 char const *vsSource =
13900 "#version 450\n"
13901 "\n"
13902 "out gl_PerVertex {\n"
13903 " vec4 gl_Position;\n"
13904 "};\n"
13905 "void main(){\n"
13906 " gl_Position = vec4(1);\n"
13907 "}\n";
13908 char const *fsSource =
13909 "#version 450\n"
13910 "\n"
13911 "in block { layout(location=0) float x; } ins;\n"
13912 "layout(location=0) out vec4 color;\n"
13913 "void main(){\n"
13914 " color = vec4(ins.x);\n"
13915 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013916
13917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13919
13920 VkPipelineObj pipe(m_device);
13921 pipe.AddColorAttachment();
13922 pipe.AddShader(&vs);
13923 pipe.AddShader(&fs);
13924
13925 VkDescriptorSetObj descriptorSet(m_device);
13926 descriptorSet.AppendDummy();
13927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13928
13929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013931 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013932}
13933
Karl Schultz6addd812016-02-02 17:17:23 -070013934TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013935 TEST_DESCRIPTION(
13936 "Test that an error is produced for mismatched array sizes "
13937 "across the vertex->fragment shader interface");
13938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13939 "Type mismatch on location 0.0: 'ptr to "
13940 "output arr[2] of float32' vs 'ptr to "
13941 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013942
13943 ASSERT_NO_FATAL_FAILURE(InitState());
13944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13945
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013946 char const *vsSource =
13947 "#version 450\n"
13948 "\n"
13949 "layout(location=0) out float x[2];\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "void main(){\n"
13954 " x[0] = 0; x[1] = 0;\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource =
13958 "#version 450\n"
13959 "\n"
13960 "layout(location=0) in float x[1];\n"
13961 "layout(location=0) out vec4 color;\n"
13962 "void main(){\n"
13963 " color = vec4(x[0]);\n"
13964 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013965
13966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13968
13969 VkPipelineObj pipe(m_device);
13970 pipe.AddColorAttachment();
13971 pipe.AddShader(&vs);
13972 pipe.AddShader(&fs);
13973
13974 VkDescriptorSetObj descriptorSet(m_device);
13975 descriptorSet.AppendDummy();
13976 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13977
13978 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13979
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013980 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013981}
13982
Karl Schultz6addd812016-02-02 17:17:23 -070013983TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013984 TEST_DESCRIPTION(
13985 "Test that an error is produced for mismatched types across "
13986 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013988
Chris Forbesb56af562015-05-25 11:13:17 +120013989 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013991
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013992 char const *vsSource =
13993 "#version 450\n"
13994 "\n"
13995 "layout(location=0) out int x;\n"
13996 "out gl_PerVertex {\n"
13997 " vec4 gl_Position;\n"
13998 "};\n"
13999 "void main(){\n"
14000 " x = 0;\n"
14001 " gl_Position = vec4(1);\n"
14002 "}\n";
14003 char const *fsSource =
14004 "#version 450\n"
14005 "\n"
14006 "layout(location=0) in float x;\n" /* VS writes int */
14007 "layout(location=0) out vec4 color;\n"
14008 "void main(){\n"
14009 " color = vec4(x);\n"
14010 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014011
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014014
14015 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014016 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014017 pipe.AddShader(&vs);
14018 pipe.AddShader(&fs);
14019
Chris Forbesb56af562015-05-25 11:13:17 +120014020 VkDescriptorSetObj descriptorSet(m_device);
14021 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014022 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014023
Tony Barbour5781e8f2015-08-04 16:23:11 -060014024 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014026 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014027}
14028
Karl Schultz6addd812016-02-02 17:17:23 -070014029TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014030 TEST_DESCRIPTION(
14031 "Test that an error is produced for mismatched types across "
14032 "the vertex->fragment shader interface, when the variable is contained within "
14033 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014035
14036 ASSERT_NO_FATAL_FAILURE(InitState());
14037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014039 char const *vsSource =
14040 "#version 450\n"
14041 "\n"
14042 "out block { layout(location=0) int x; } outs;\n"
14043 "out gl_PerVertex {\n"
14044 " vec4 gl_Position;\n"
14045 "};\n"
14046 "void main(){\n"
14047 " outs.x = 0;\n"
14048 " gl_Position = vec4(1);\n"
14049 "}\n";
14050 char const *fsSource =
14051 "#version 450\n"
14052 "\n"
14053 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14054 "layout(location=0) out vec4 color;\n"
14055 "void main(){\n"
14056 " color = vec4(ins.x);\n"
14057 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014058
14059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14061
14062 VkPipelineObj pipe(m_device);
14063 pipe.AddColorAttachment();
14064 pipe.AddShader(&vs);
14065 pipe.AddShader(&fs);
14066
14067 VkDescriptorSetObj descriptorSet(m_device);
14068 descriptorSet.AppendDummy();
14069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14070
14071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014073 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014074}
14075
14076TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014077 TEST_DESCRIPTION(
14078 "Test that an error is produced for location mismatches across "
14079 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14080 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 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 +130014082
14083 ASSERT_NO_FATAL_FAILURE(InitState());
14084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14085
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014086 char const *vsSource =
14087 "#version 450\n"
14088 "\n"
14089 "out block { layout(location=1) float x; } outs;\n"
14090 "out gl_PerVertex {\n"
14091 " vec4 gl_Position;\n"
14092 "};\n"
14093 "void main(){\n"
14094 " outs.x = 0;\n"
14095 " gl_Position = vec4(1);\n"
14096 "}\n";
14097 char const *fsSource =
14098 "#version 450\n"
14099 "\n"
14100 "in block { layout(location=0) float x; } ins;\n"
14101 "layout(location=0) out vec4 color;\n"
14102 "void main(){\n"
14103 " color = vec4(ins.x);\n"
14104 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014105
14106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14108
14109 VkPipelineObj pipe(m_device);
14110 pipe.AddColorAttachment();
14111 pipe.AddShader(&vs);
14112 pipe.AddShader(&fs);
14113
14114 VkDescriptorSetObj descriptorSet(m_device);
14115 descriptorSet.AppendDummy();
14116 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14117
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014118 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014121 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014122}
14123
14124TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014125 TEST_DESCRIPTION(
14126 "Test that an error is produced for component mismatches across the "
14127 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14128 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 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 +130014130
14131 ASSERT_NO_FATAL_FAILURE(InitState());
14132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "out block { layout(location=0, component=0) float x; } outs;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " outs.x = 0;\n"
14143 " gl_Position = vec4(1);\n"
14144 "}\n";
14145 char const *fsSource =
14146 "#version 450\n"
14147 "\n"
14148 "in block { layout(location=0, component=1) float x; } ins;\n"
14149 "layout(location=0) out vec4 color;\n"
14150 "void main(){\n"
14151 " color = vec4(ins.x);\n"
14152 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014153
14154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14156
14157 VkPipelineObj pipe(m_device);
14158 pipe.AddColorAttachment();
14159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
14166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014169}
14170
Chris Forbes1f3b0152016-11-30 12:48:40 +130014171TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14172 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14173
14174 ASSERT_NO_FATAL_FAILURE(InitState());
14175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14176
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014177 char const *vsSource =
14178 "#version 450\n"
14179 "layout(location=0) out mediump float x;\n"
14180 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14181 char const *fsSource =
14182 "#version 450\n"
14183 "layout(location=0) in highp float x;\n"
14184 "layout(location=0) out vec4 color;\n"
14185 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014186
14187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14189
14190 VkPipelineObj pipe(m_device);
14191 pipe.AddColorAttachment();
14192 pipe.AddShader(&vs);
14193 pipe.AddShader(&fs);
14194
14195 VkDescriptorSetObj descriptorSet(m_device);
14196 descriptorSet.AppendDummy();
14197 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14198
14199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14200
14201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14202
14203 m_errorMonitor->VerifyFound();
14204}
14205
Chris Forbes870a39e2016-11-30 12:55:56 +130014206TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14207 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14208
14209 ASSERT_NO_FATAL_FAILURE(InitState());
14210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14211
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014212 char const *vsSource =
14213 "#version 450\n"
14214 "out block { layout(location=0) mediump float x; };\n"
14215 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14216 char const *fsSource =
14217 "#version 450\n"
14218 "in block { layout(location=0) highp float x; };\n"
14219 "layout(location=0) out vec4 color;\n"
14220 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014221
14222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14224
14225 VkPipelineObj pipe(m_device);
14226 pipe.AddColorAttachment();
14227 pipe.AddShader(&vs);
14228 pipe.AddShader(&fs);
14229
14230 VkDescriptorSetObj descriptorSet(m_device);
14231 descriptorSet.AppendDummy();
14232 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14233
14234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14235
14236 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14237
14238 m_errorMonitor->VerifyFound();
14239}
14240
Karl Schultz6addd812016-02-02 17:17:23 -070014241TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 TEST_DESCRIPTION(
14243 "Test that a warning is produced for a vertex attribute which is "
14244 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014246
Chris Forbesde136e02015-05-25 11:13:28 +120014247 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014249
14250 VkVertexInputBindingDescription input_binding;
14251 memset(&input_binding, 0, sizeof(input_binding));
14252
14253 VkVertexInputAttributeDescription input_attrib;
14254 memset(&input_attrib, 0, sizeof(input_attrib));
14255 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14256
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014257 char const *vsSource =
14258 "#version 450\n"
14259 "\n"
14260 "out gl_PerVertex {\n"
14261 " vec4 gl_Position;\n"
14262 "};\n"
14263 "void main(){\n"
14264 " gl_Position = vec4(1);\n"
14265 "}\n";
14266 char const *fsSource =
14267 "#version 450\n"
14268 "\n"
14269 "layout(location=0) out vec4 color;\n"
14270 "void main(){\n"
14271 " color = vec4(1);\n"
14272 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014273
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014276
14277 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014278 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014279 pipe.AddShader(&vs);
14280 pipe.AddShader(&fs);
14281
14282 pipe.AddVertexInputBindings(&input_binding, 1);
14283 pipe.AddVertexInputAttribs(&input_attrib, 1);
14284
Chris Forbesde136e02015-05-25 11:13:28 +120014285 VkDescriptorSetObj descriptorSet(m_device);
14286 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014287 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014288
Tony Barbour5781e8f2015-08-04 16:23:11 -060014289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014290
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014291 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014292}
14293
Karl Schultz6addd812016-02-02 17:17:23 -070014294TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014295 TEST_DESCRIPTION(
14296 "Test that a warning is produced for a location mismatch on "
14297 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014299
14300 ASSERT_NO_FATAL_FAILURE(InitState());
14301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14302
14303 VkVertexInputBindingDescription input_binding;
14304 memset(&input_binding, 0, sizeof(input_binding));
14305
14306 VkVertexInputAttributeDescription input_attrib;
14307 memset(&input_attrib, 0, sizeof(input_attrib));
14308 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014310 char const *vsSource =
14311 "#version 450\n"
14312 "\n"
14313 "layout(location=1) in float x;\n"
14314 "out gl_PerVertex {\n"
14315 " vec4 gl_Position;\n"
14316 "};\n"
14317 "void main(){\n"
14318 " gl_Position = vec4(x);\n"
14319 "}\n";
14320 char const *fsSource =
14321 "#version 450\n"
14322 "\n"
14323 "layout(location=0) out vec4 color;\n"
14324 "void main(){\n"
14325 " color = vec4(1);\n"
14326 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014327
14328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14330
14331 VkPipelineObj pipe(m_device);
14332 pipe.AddColorAttachment();
14333 pipe.AddShader(&vs);
14334 pipe.AddShader(&fs);
14335
14336 pipe.AddVertexInputBindings(&input_binding, 1);
14337 pipe.AddVertexInputAttribs(&input_attrib, 1);
14338
14339 VkDescriptorSetObj descriptorSet(m_device);
14340 descriptorSet.AppendDummy();
14341 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14342
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014343 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14345
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014346 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014347}
14348
Karl Schultz6addd812016-02-02 17:17:23 -070014349TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014350 TEST_DESCRIPTION(
14351 "Test that an error is produced for a vertex shader input which is not "
14352 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14354 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014355
Chris Forbes62e8e502015-05-25 11:13:29 +120014356 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014359 char const *vsSource =
14360 "#version 450\n"
14361 "\n"
14362 "layout(location=0) in vec4 x;\n" /* not provided */
14363 "out gl_PerVertex {\n"
14364 " vec4 gl_Position;\n"
14365 "};\n"
14366 "void main(){\n"
14367 " gl_Position = x;\n"
14368 "}\n";
14369 char const *fsSource =
14370 "#version 450\n"
14371 "\n"
14372 "layout(location=0) out vec4 color;\n"
14373 "void main(){\n"
14374 " color = vec4(1);\n"
14375 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014376
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014377 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14378 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014379
14380 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014381 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014382 pipe.AddShader(&vs);
14383 pipe.AddShader(&fs);
14384
Chris Forbes62e8e502015-05-25 11:13:29 +120014385 VkDescriptorSetObj descriptorSet(m_device);
14386 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014388
Tony Barbour5781e8f2015-08-04 16:23:11 -060014389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014391 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014392}
14393
Karl Schultz6addd812016-02-02 17:17:23 -070014394TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014395 TEST_DESCRIPTION(
14396 "Test that an error is produced for a mismatch between the "
14397 "fundamental type (float/int/uint) of an attribute and the "
14398 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014399 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 -060014400
Chris Forbesc97d98e2015-05-25 11:13:31 +120014401 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014403
14404 VkVertexInputBindingDescription input_binding;
14405 memset(&input_binding, 0, sizeof(input_binding));
14406
14407 VkVertexInputAttributeDescription input_attrib;
14408 memset(&input_attrib, 0, sizeof(input_attrib));
14409 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14410
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014411 char const *vsSource =
14412 "#version 450\n"
14413 "\n"
14414 "layout(location=0) in int x;\n" /* attrib provided float */
14415 "out gl_PerVertex {\n"
14416 " vec4 gl_Position;\n"
14417 "};\n"
14418 "void main(){\n"
14419 " gl_Position = vec4(x);\n"
14420 "}\n";
14421 char const *fsSource =
14422 "#version 450\n"
14423 "\n"
14424 "layout(location=0) out vec4 color;\n"
14425 "void main(){\n"
14426 " color = vec4(1);\n"
14427 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014428
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014429 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14430 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014431
14432 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014433 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014434 pipe.AddShader(&vs);
14435 pipe.AddShader(&fs);
14436
14437 pipe.AddVertexInputBindings(&input_binding, 1);
14438 pipe.AddVertexInputAttribs(&input_attrib, 1);
14439
Chris Forbesc97d98e2015-05-25 11:13:31 +120014440 VkDescriptorSetObj descriptorSet(m_device);
14441 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014442 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014443
Tony Barbour5781e8f2015-08-04 16:23:11 -060014444 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014446 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014447}
14448
Chris Forbesc68b43c2016-04-06 11:18:47 +120014449TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014450 TEST_DESCRIPTION(
14451 "Test that an error is produced for a pipeline containing multiple "
14452 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14454 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014455
14456 ASSERT_NO_FATAL_FAILURE(InitState());
14457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14458
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014459 char const *vsSource =
14460 "#version 450\n"
14461 "\n"
14462 "out gl_PerVertex {\n"
14463 " vec4 gl_Position;\n"
14464 "};\n"
14465 "void main(){\n"
14466 " gl_Position = vec4(1);\n"
14467 "}\n";
14468 char const *fsSource =
14469 "#version 450\n"
14470 "\n"
14471 "layout(location=0) out vec4 color;\n"
14472 "void main(){\n"
14473 " color = vec4(1);\n"
14474 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014475
14476 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14478
14479 VkPipelineObj pipe(m_device);
14480 pipe.AddColorAttachment();
14481 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014482 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014483 pipe.AddShader(&fs);
14484
14485 VkDescriptorSetObj descriptorSet(m_device);
14486 descriptorSet.AppendDummy();
14487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14488
14489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014491 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014492}
14493
Chris Forbes82ff92a2016-09-09 10:50:24 +120014494TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014496
14497 ASSERT_NO_FATAL_FAILURE(InitState());
14498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 char const *vsSource =
14501 "#version 450\n"
14502 "out gl_PerVertex {\n"
14503 " vec4 gl_Position;\n"
14504 "};\n"
14505 "void main(){\n"
14506 " gl_Position = vec4(0);\n"
14507 "}\n";
14508 char const *fsSource =
14509 "#version 450\n"
14510 "\n"
14511 "layout(location=0) out vec4 color;\n"
14512 "void main(){\n"
14513 " color = vec4(1);\n"
14514 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014515
14516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14518
14519 VkPipelineObj pipe(m_device);
14520 pipe.AddColorAttachment();
14521 pipe.AddShader(&vs);
14522 pipe.AddShader(&fs);
14523
14524 VkDescriptorSetObj descriptorSet(m_device);
14525 descriptorSet.AppendDummy();
14526 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14527
14528 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14529
14530 m_errorMonitor->VerifyFound();
14531}
14532
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014533TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14535 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14536 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014537
14538 ASSERT_NO_FATAL_FAILURE(InitState());
14539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14540
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014541 char const *vsSource =
14542 "#version 450\n"
14543 "void main(){ gl_Position = vec4(0); }\n";
14544 char const *fsSource =
14545 "#version 450\n"
14546 "\n"
14547 "layout(location=0) out vec4 color;\n"
14548 "void main(){\n"
14549 " color = vec4(1);\n"
14550 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014551
14552 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14553 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14554
14555 VkPipelineObj pipe(m_device);
14556 pipe.AddColorAttachment();
14557 pipe.AddShader(&vs);
14558 pipe.AddShader(&fs);
14559
14560 VkDescriptorSetObj descriptorSet(m_device);
14561 descriptorSet.AppendDummy();
14562 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14563
14564 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014565 {
14566 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14567 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14568 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014569 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014570 {
14571 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14572 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14573 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014574 },
14575 };
14576 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014577 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014578 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014579 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14580 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014581 VkRenderPass rp;
14582 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14583 ASSERT_VK_SUCCESS(err);
14584
14585 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14586
14587 m_errorMonitor->VerifyFound();
14588
14589 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14590}
14591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014592TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014593 TEST_DESCRIPTION(
14594 "Test that an error is produced for a variable output from "
14595 "the TCS without the patch decoration, but consumed in the TES "
14596 "with the decoration.");
14597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14598 "is per-vertex in tessellation control shader stage "
14599 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014600
14601 ASSERT_NO_FATAL_FAILURE(InitState());
14602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14603
Chris Forbesc1e852d2016-04-04 19:26:42 +120014604 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014605 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014606 return;
14607 }
14608
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014609 char const *vsSource =
14610 "#version 450\n"
14611 "void main(){}\n";
14612 char const *tcsSource =
14613 "#version 450\n"
14614 "layout(location=0) out int x[];\n"
14615 "layout(vertices=3) out;\n"
14616 "void main(){\n"
14617 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14618 " gl_TessLevelInner[0] = 1;\n"
14619 " x[gl_InvocationID] = gl_InvocationID;\n"
14620 "}\n";
14621 char const *tesSource =
14622 "#version 450\n"
14623 "layout(triangles, equal_spacing, cw) in;\n"
14624 "layout(location=0) patch in int x;\n"
14625 "out gl_PerVertex { vec4 gl_Position; };\n"
14626 "void main(){\n"
14627 " gl_Position.xyz = gl_TessCoord;\n"
14628 " gl_Position.w = x;\n"
14629 "}\n";
14630 char const *fsSource =
14631 "#version 450\n"
14632 "layout(location=0) out vec4 color;\n"
14633 "void main(){\n"
14634 " color = vec4(1);\n"
14635 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014636
14637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14638 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14639 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14640 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14643 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014645 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014646
14647 VkPipelineObj pipe(m_device);
14648 pipe.SetInputAssembly(&iasci);
14649 pipe.SetTessellation(&tsci);
14650 pipe.AddColorAttachment();
14651 pipe.AddShader(&vs);
14652 pipe.AddShader(&tcs);
14653 pipe.AddShader(&tes);
14654 pipe.AddShader(&fs);
14655
14656 VkDescriptorSetObj descriptorSet(m_device);
14657 descriptorSet.AppendDummy();
14658 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14659
14660 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14661
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014662 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014663}
14664
Karl Schultz6addd812016-02-02 17:17:23 -070014665TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014666 TEST_DESCRIPTION(
14667 "Test that an error is produced for a vertex attribute setup where multiple "
14668 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14670 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014671
Chris Forbes280ba2c2015-06-12 11:16:41 +120014672 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014674
14675 /* Two binding descriptions for binding 0 */
14676 VkVertexInputBindingDescription input_bindings[2];
14677 memset(input_bindings, 0, sizeof(input_bindings));
14678
14679 VkVertexInputAttributeDescription input_attrib;
14680 memset(&input_attrib, 0, sizeof(input_attrib));
14681 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14682
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014683 char const *vsSource =
14684 "#version 450\n"
14685 "\n"
14686 "layout(location=0) in float x;\n" /* attrib provided float */
14687 "out gl_PerVertex {\n"
14688 " vec4 gl_Position;\n"
14689 "};\n"
14690 "void main(){\n"
14691 " gl_Position = vec4(x);\n"
14692 "}\n";
14693 char const *fsSource =
14694 "#version 450\n"
14695 "\n"
14696 "layout(location=0) out vec4 color;\n"
14697 "void main(){\n"
14698 " color = vec4(1);\n"
14699 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014700
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014703
14704 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014705 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014706 pipe.AddShader(&vs);
14707 pipe.AddShader(&fs);
14708
14709 pipe.AddVertexInputBindings(input_bindings, 2);
14710 pipe.AddVertexInputAttribs(&input_attrib, 1);
14711
Chris Forbes280ba2c2015-06-12 11:16:41 +120014712 VkDescriptorSetObj descriptorSet(m_device);
14713 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014714 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014715
Tony Barbour5781e8f2015-08-04 16:23:11 -060014716 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014718 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014719}
Chris Forbes8f68b562015-05-25 11:13:32 +120014720
Karl Schultz6addd812016-02-02 17:17:23 -070014721TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014722 TEST_DESCRIPTION(
14723 "Test that an error is produced for a fragment shader which does not "
14724 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014726
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014727 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014729 char const *vsSource =
14730 "#version 450\n"
14731 "\n"
14732 "out gl_PerVertex {\n"
14733 " vec4 gl_Position;\n"
14734 "};\n"
14735 "void main(){\n"
14736 " gl_Position = vec4(1);\n"
14737 "}\n";
14738 char const *fsSource =
14739 "#version 450\n"
14740 "\n"
14741 "void main(){\n"
14742 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014743
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014746
14747 VkPipelineObj pipe(m_device);
14748 pipe.AddShader(&vs);
14749 pipe.AddShader(&fs);
14750
Chia-I Wu08accc62015-07-07 11:50:03 +080014751 /* set up CB 0, not written */
14752 pipe.AddColorAttachment();
14753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014754
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014755 VkDescriptorSetObj descriptorSet(m_device);
14756 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014758
Tony Barbour5781e8f2015-08-04 16:23:11 -060014759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014761 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014762}
14763
Karl Schultz6addd812016-02-02 17:17:23 -070014764TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014765 TEST_DESCRIPTION(
14766 "Test that a warning is produced for a fragment shader which provides a spurious "
14767 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014769 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014770
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014771 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014773 char const *vsSource =
14774 "#version 450\n"
14775 "\n"
14776 "out gl_PerVertex {\n"
14777 " vec4 gl_Position;\n"
14778 "};\n"
14779 "void main(){\n"
14780 " gl_Position = vec4(1);\n"
14781 "}\n";
14782 char const *fsSource =
14783 "#version 450\n"
14784 "\n"
14785 "layout(location=0) out vec4 x;\n"
14786 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14787 "void main(){\n"
14788 " x = vec4(1);\n"
14789 " y = vec4(1);\n"
14790 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014791
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014794
14795 VkPipelineObj pipe(m_device);
14796 pipe.AddShader(&vs);
14797 pipe.AddShader(&fs);
14798
Chia-I Wu08accc62015-07-07 11:50:03 +080014799 /* set up CB 0, not written */
14800 pipe.AddColorAttachment();
14801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014802 /* FS writes CB 1, but we don't configure it */
14803
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014804 VkDescriptorSetObj descriptorSet(m_device);
14805 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014806 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014807
Tony Barbour5781e8f2015-08-04 16:23:11 -060014808 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014809
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014810 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014811}
14812
Karl Schultz6addd812016-02-02 17:17:23 -070014813TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014814 TEST_DESCRIPTION(
14815 "Test that an error is produced for a mismatch between the fundamental "
14816 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014818
Chris Forbesa36d69e2015-05-25 11:13:44 +120014819 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014821 char const *vsSource =
14822 "#version 450\n"
14823 "\n"
14824 "out gl_PerVertex {\n"
14825 " vec4 gl_Position;\n"
14826 "};\n"
14827 "void main(){\n"
14828 " gl_Position = vec4(1);\n"
14829 "}\n";
14830 char const *fsSource =
14831 "#version 450\n"
14832 "\n"
14833 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14834 "void main(){\n"
14835 " x = ivec4(1);\n"
14836 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014837
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014840
14841 VkPipelineObj pipe(m_device);
14842 pipe.AddShader(&vs);
14843 pipe.AddShader(&fs);
14844
Chia-I Wu08accc62015-07-07 11:50:03 +080014845 /* set up CB 0; type is UNORM by default */
14846 pipe.AddColorAttachment();
14847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014848
Chris Forbesa36d69e2015-05-25 11:13:44 +120014849 VkDescriptorSetObj descriptorSet(m_device);
14850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014852
Tony Barbour5781e8f2015-08-04 16:23:11 -060014853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014855 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014856}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014857
Karl Schultz6addd812016-02-02 17:17:23 -070014858TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014859 TEST_DESCRIPTION(
14860 "Test that an error is produced for a shader consuming a uniform "
14861 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014863
Chris Forbes556c76c2015-08-14 12:04:59 +120014864 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014865
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014866 char const *vsSource =
14867 "#version 450\n"
14868 "\n"
14869 "out gl_PerVertex {\n"
14870 " vec4 gl_Position;\n"
14871 "};\n"
14872 "void main(){\n"
14873 " gl_Position = vec4(1);\n"
14874 "}\n";
14875 char const *fsSource =
14876 "#version 450\n"
14877 "\n"
14878 "layout(location=0) out vec4 x;\n"
14879 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14880 "void main(){\n"
14881 " x = vec4(bar.y);\n"
14882 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014883
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014886
Chris Forbes556c76c2015-08-14 12:04:59 +120014887 VkPipelineObj pipe(m_device);
14888 pipe.AddShader(&vs);
14889 pipe.AddShader(&fs);
14890
14891 /* set up CB 0; type is UNORM by default */
14892 pipe.AddColorAttachment();
14893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14894
14895 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014897
14898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014900 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014901}
14902
Chris Forbes5c59e902016-02-26 16:56:09 +130014903TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014904 TEST_DESCRIPTION(
14905 "Test that an error is produced for a shader consuming push constants "
14906 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014908
14909 ASSERT_NO_FATAL_FAILURE(InitState());
14910
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014911 char const *vsSource =
14912 "#version 450\n"
14913 "\n"
14914 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14915 "out gl_PerVertex {\n"
14916 " vec4 gl_Position;\n"
14917 "};\n"
14918 "void main(){\n"
14919 " gl_Position = vec4(consts.x);\n"
14920 "}\n";
14921 char const *fsSource =
14922 "#version 450\n"
14923 "\n"
14924 "layout(location=0) out vec4 x;\n"
14925 "void main(){\n"
14926 " x = vec4(1);\n"
14927 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014928
14929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14931
14932 VkPipelineObj pipe(m_device);
14933 pipe.AddShader(&vs);
14934 pipe.AddShader(&fs);
14935
14936 /* set up CB 0; type is UNORM by default */
14937 pipe.AddColorAttachment();
14938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14939
14940 VkDescriptorSetObj descriptorSet(m_device);
14941 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14942
14943 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14944
14945 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014946 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014947}
14948
Chris Forbes3fb17902016-08-22 14:57:55 +120014949TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014950 TEST_DESCRIPTION(
14951 "Test that an error is produced for a shader consuming an input attachment "
14952 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14954 "consumes input attachment index 0 but not provided in subpass");
14955
14956 ASSERT_NO_FATAL_FAILURE(InitState());
14957
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014958 char const *vsSource =
14959 "#version 450\n"
14960 "\n"
14961 "out gl_PerVertex {\n"
14962 " vec4 gl_Position;\n"
14963 "};\n"
14964 "void main(){\n"
14965 " gl_Position = vec4(1);\n"
14966 "}\n";
14967 char const *fsSource =
14968 "#version 450\n"
14969 "\n"
14970 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14971 "layout(location=0) out vec4 color;\n"
14972 "void main() {\n"
14973 " color = subpassLoad(x);\n"
14974 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014975
14976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14978
14979 VkPipelineObj pipe(m_device);
14980 pipe.AddShader(&vs);
14981 pipe.AddShader(&fs);
14982 pipe.AddColorAttachment();
14983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14986 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014987 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014988 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014989 ASSERT_VK_SUCCESS(err);
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014992 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014993 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014994 ASSERT_VK_SUCCESS(err);
14995
14996 // error here.
14997 pipe.CreateVKPipeline(pl, renderPass());
14998
14999 m_errorMonitor->VerifyFound();
15000
15001 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15002 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15003}
15004
Chris Forbes5a9a0472016-08-22 16:02:09 +120015005TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015006 TEST_DESCRIPTION(
15007 "Test that an error is produced for a shader consuming an input attachment "
15008 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15010 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15011
15012 ASSERT_NO_FATAL_FAILURE(InitState());
15013
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015014 char const *vsSource =
15015 "#version 450\n"
15016 "\n"
15017 "out gl_PerVertex {\n"
15018 " vec4 gl_Position;\n"
15019 "};\n"
15020 "void main(){\n"
15021 " gl_Position = vec4(1);\n"
15022 "}\n";
15023 char const *fsSource =
15024 "#version 450\n"
15025 "\n"
15026 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15027 "layout(location=0) out vec4 color;\n"
15028 "void main() {\n"
15029 " color = subpassLoad(x);\n"
15030 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015031
15032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15034
15035 VkPipelineObj pipe(m_device);
15036 pipe.AddShader(&vs);
15037 pipe.AddShader(&fs);
15038 pipe.AddColorAttachment();
15039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15042 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015043 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015045 ASSERT_VK_SUCCESS(err);
15046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015048 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015050 ASSERT_VK_SUCCESS(err);
15051
15052 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15054 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15055 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15056 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15057 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 +120015058 };
15059 VkAttachmentReference color = {
15060 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15061 };
15062 VkAttachmentReference input = {
15063 1, VK_IMAGE_LAYOUT_GENERAL,
15064 };
15065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015069 VkRenderPass rp;
15070 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15071 ASSERT_VK_SUCCESS(err);
15072
15073 // error here.
15074 pipe.CreateVKPipeline(pl, rp);
15075
15076 m_errorMonitor->VerifyFound();
15077
15078 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15079 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15080 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15081}
15082
Chris Forbes541f7b02016-08-22 15:30:27 +120015083TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015084 TEST_DESCRIPTION(
15085 "Test that an error is produced for a shader consuming an input attachment "
15086 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015088 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015089
15090 ASSERT_NO_FATAL_FAILURE(InitState());
15091
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015092 char const *vsSource =
15093 "#version 450\n"
15094 "\n"
15095 "out gl_PerVertex {\n"
15096 " vec4 gl_Position;\n"
15097 "};\n"
15098 "void main(){\n"
15099 " gl_Position = vec4(1);\n"
15100 "}\n";
15101 char const *fsSource =
15102 "#version 450\n"
15103 "\n"
15104 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15105 "layout(location=0) out vec4 color;\n"
15106 "void main() {\n"
15107 " color = subpassLoad(xs[0]);\n"
15108 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015109
15110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15112
15113 VkPipelineObj pipe(m_device);
15114 pipe.AddShader(&vs);
15115 pipe.AddShader(&fs);
15116 pipe.AddColorAttachment();
15117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15120 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015121 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015123 ASSERT_VK_SUCCESS(err);
15124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015126 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015127 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015128 ASSERT_VK_SUCCESS(err);
15129
15130 // error here.
15131 pipe.CreateVKPipeline(pl, renderPass());
15132
15133 m_errorMonitor->VerifyFound();
15134
15135 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15136 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15137}
15138
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015139TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015140 TEST_DESCRIPTION(
15141 "Test that an error is produced for a compute pipeline consuming a "
15142 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015144
15145 ASSERT_NO_FATAL_FAILURE(InitState());
15146
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015147 char const *csSource =
15148 "#version 450\n"
15149 "\n"
15150 "layout(local_size_x=1) in;\n"
15151 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15152 "void main(){\n"
15153 " x = vec4(1);\n"
15154 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015155
15156 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15157
15158 VkDescriptorSetObj descriptorSet(m_device);
15159 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15162 nullptr,
15163 0,
15164 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15165 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15166 descriptorSet.GetPipelineLayout(),
15167 VK_NULL_HANDLE,
15168 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015169
15170 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015172
15173 m_errorMonitor->VerifyFound();
15174
15175 if (err == VK_SUCCESS) {
15176 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15177 }
15178}
15179
Chris Forbes22a9b092016-07-19 14:34:05 +120015180TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015181 TEST_DESCRIPTION(
15182 "Test that an error is produced for a pipeline consuming a "
15183 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15185 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015186
15187 ASSERT_NO_FATAL_FAILURE(InitState());
15188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15190 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015191 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015193 ASSERT_VK_SUCCESS(err);
15194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015196 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015197 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015198 ASSERT_VK_SUCCESS(err);
15199
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015200 char const *csSource =
15201 "#version 450\n"
15202 "\n"
15203 "layout(local_size_x=1) in;\n"
15204 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15205 "void main() {\n"
15206 " x.x = 1.0f;\n"
15207 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015208 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15211 nullptr,
15212 0,
15213 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15214 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15215 pl,
15216 VK_NULL_HANDLE,
15217 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015218
15219 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015220 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015221
15222 m_errorMonitor->VerifyFound();
15223
15224 if (err == VK_SUCCESS) {
15225 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15226 }
15227
15228 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15229 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15230}
15231
Chris Forbes50020592016-07-27 13:52:41 +120015232TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015233 TEST_DESCRIPTION(
15234 "Test that an error is produced when an image view type "
15235 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 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 +120015238
15239 ASSERT_NO_FATAL_FAILURE(InitState());
15240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015242 char const *vsSource =
15243 "#version 450\n"
15244 "\n"
15245 "out gl_PerVertex { vec4 gl_Position; };\n"
15246 "void main() { gl_Position = vec4(0); }\n";
15247 char const *fsSource =
15248 "#version 450\n"
15249 "\n"
15250 "layout(set=0, binding=0) uniform sampler3D s;\n"
15251 "layout(location=0) out vec4 color;\n"
15252 "void main() {\n"
15253 " color = texture(s, vec3(0));\n"
15254 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015255 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15256 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15257
15258 VkPipelineObj pipe(m_device);
15259 pipe.AddShader(&vs);
15260 pipe.AddShader(&fs);
15261 pipe.AddColorAttachment();
15262
15263 VkTextureObj texture(m_device, nullptr);
15264 VkSamplerObj sampler(m_device);
15265
15266 VkDescriptorSetObj descriptorSet(m_device);
15267 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15268 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15269
15270 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15271 ASSERT_VK_SUCCESS(err);
15272
Tony Barbour552f6c02016-12-21 14:34:07 -070015273 m_commandBuffer->BeginCommandBuffer();
15274 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015275
15276 m_commandBuffer->BindPipeline(pipe);
15277 m_commandBuffer->BindDescriptorSet(descriptorSet);
15278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015279 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015280 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015282 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15283
15284 // error produced here.
15285 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15286
15287 m_errorMonitor->VerifyFound();
15288
Tony Barbour552f6c02016-12-21 14:34:07 -070015289 m_commandBuffer->EndRenderPass();
15290 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015291}
15292
Chris Forbes5533bfc2016-07-27 14:12:34 +120015293TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015294 TEST_DESCRIPTION(
15295 "Test that an error is produced when a multisampled images "
15296 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015299
15300 ASSERT_NO_FATAL_FAILURE(InitState());
15301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15302
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015303 char const *vsSource =
15304 "#version 450\n"
15305 "\n"
15306 "out gl_PerVertex { vec4 gl_Position; };\n"
15307 "void main() { gl_Position = vec4(0); }\n";
15308 char const *fsSource =
15309 "#version 450\n"
15310 "\n"
15311 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15312 "layout(location=0) out vec4 color;\n"
15313 "void main() {\n"
15314 " color = texelFetch(s, ivec2(0), 0);\n"
15315 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15318
15319 VkPipelineObj pipe(m_device);
15320 pipe.AddShader(&vs);
15321 pipe.AddShader(&fs);
15322 pipe.AddColorAttachment();
15323
15324 VkTextureObj texture(m_device, nullptr);
15325 VkSamplerObj sampler(m_device);
15326
15327 VkDescriptorSetObj descriptorSet(m_device);
15328 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15329 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15330
15331 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15332 ASSERT_VK_SUCCESS(err);
15333
Tony Barbour552f6c02016-12-21 14:34:07 -070015334 m_commandBuffer->BeginCommandBuffer();
15335 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015336
15337 m_commandBuffer->BindPipeline(pipe);
15338 m_commandBuffer->BindDescriptorSet(descriptorSet);
15339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015340 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015341 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015342 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015343 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15344
15345 // error produced here.
15346 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15347
15348 m_errorMonitor->VerifyFound();
15349
Tony Barbour552f6c02016-12-21 14:34:07 -070015350 m_commandBuffer->EndRenderPass();
15351 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015352}
15353
Mark Youngc48c4c12016-04-11 14:26:49 -060015354TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015356
15357 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015358
15359 // Create an image
15360 VkImage image;
15361
Karl Schultz6addd812016-02-02 17:17:23 -070015362 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15363 const int32_t tex_width = 32;
15364 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015365
15366 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15368 image_create_info.pNext = NULL;
15369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15370 image_create_info.format = tex_format;
15371 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015372 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015373 image_create_info.extent.depth = 1;
15374 image_create_info.mipLevels = 1;
15375 image_create_info.arrayLayers = 1;
15376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15377 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15378 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15379 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015380
15381 // Introduce error by sending down a bogus width extent
15382 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015383 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015385 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015386}
15387
Mark Youngc48c4c12016-04-11 14:26:49 -060015388TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015390
15391 ASSERT_NO_FATAL_FAILURE(InitState());
15392
15393 // Create an image
15394 VkImage image;
15395
15396 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15397 const int32_t tex_width = 32;
15398 const int32_t tex_height = 32;
15399
15400 VkImageCreateInfo image_create_info = {};
15401 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15402 image_create_info.pNext = NULL;
15403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15404 image_create_info.format = tex_format;
15405 image_create_info.extent.width = tex_width;
15406 image_create_info.extent.height = tex_height;
15407 image_create_info.extent.depth = 1;
15408 image_create_info.mipLevels = 1;
15409 image_create_info.arrayLayers = 1;
15410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15411 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15412 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15413 image_create_info.flags = 0;
15414
15415 // Introduce error by sending down a bogus width extent
15416 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015417 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015418 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15419
15420 m_errorMonitor->VerifyFound();
15421}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015422
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015423TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015424 TEST_DESCRIPTION(
15425 "Create a render pass with an attachment description "
15426 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015427
15428 ASSERT_NO_FATAL_FAILURE(InitState());
15429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15430
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015432
15433 VkAttachmentReference color_attach = {};
15434 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15435 color_attach.attachment = 0;
15436 VkSubpassDescription subpass = {};
15437 subpass.colorAttachmentCount = 1;
15438 subpass.pColorAttachments = &color_attach;
15439
15440 VkRenderPassCreateInfo rpci = {};
15441 rpci.subpassCount = 1;
15442 rpci.pSubpasses = &subpass;
15443 rpci.attachmentCount = 1;
15444 VkAttachmentDescription attach_desc = {};
15445 attach_desc.format = VK_FORMAT_UNDEFINED;
15446 rpci.pAttachments = &attach_desc;
15447 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15448 VkRenderPass rp;
15449 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15450
15451 m_errorMonitor->VerifyFound();
15452
15453 if (result == VK_SUCCESS) {
15454 vkDestroyRenderPass(m_device->device(), rp, NULL);
15455 }
15456}
15457
Karl Schultz6addd812016-02-02 17:17:23 -070015458TEST_F(VkLayerTest, InvalidImageView) {
15459 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015460
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015462
Tobin Ehliscde08892015-09-22 10:11:37 -060015463 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015464
Mike Stroyana3082432015-09-25 13:39:21 -060015465 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015466 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015467
Karl Schultz6addd812016-02-02 17:17:23 -070015468 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15469 const int32_t tex_width = 32;
15470 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015471
15472 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15474 image_create_info.pNext = NULL;
15475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15476 image_create_info.format = tex_format;
15477 image_create_info.extent.width = tex_width;
15478 image_create_info.extent.height = tex_height;
15479 image_create_info.extent.depth = 1;
15480 image_create_info.mipLevels = 1;
15481 image_create_info.arrayLayers = 1;
15482 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15483 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15484 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15485 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015486
Chia-I Wuf7458c52015-10-26 21:10:41 +080015487 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015488 ASSERT_VK_SUCCESS(err);
15489
15490 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015491 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015492 image_view_create_info.image = image;
15493 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15494 image_view_create_info.format = tex_format;
15495 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015496 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015497 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015498 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015499
15500 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015501 m_errorMonitor->SetUnexpectedError(
15502 "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 -060015503 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015504
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015505 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015506 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015507}
Mike Stroyana3082432015-09-25 13:39:21 -060015508
Mark Youngd339ba32016-05-30 13:28:35 -060015509TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15510 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015512 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015513
15514 ASSERT_NO_FATAL_FAILURE(InitState());
15515
15516 // Create an image and try to create a view with no memory backing the image
15517 VkImage image;
15518
15519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15520 const int32_t tex_width = 32;
15521 const int32_t tex_height = 32;
15522
15523 VkImageCreateInfo image_create_info = {};
15524 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15525 image_create_info.pNext = NULL;
15526 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15527 image_create_info.format = tex_format;
15528 image_create_info.extent.width = tex_width;
15529 image_create_info.extent.height = tex_height;
15530 image_create_info.extent.depth = 1;
15531 image_create_info.mipLevels = 1;
15532 image_create_info.arrayLayers = 1;
15533 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15534 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15536 image_create_info.flags = 0;
15537
15538 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15539 ASSERT_VK_SUCCESS(err);
15540
15541 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015542 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015543 image_view_create_info.image = image;
15544 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15545 image_view_create_info.format = tex_format;
15546 image_view_create_info.subresourceRange.layerCount = 1;
15547 image_view_create_info.subresourceRange.baseMipLevel = 0;
15548 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015549 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015550
15551 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015552 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015553
15554 m_errorMonitor->VerifyFound();
15555 vkDestroyImage(m_device->device(), image, NULL);
15556 // If last error is success, it still created the view, so delete it.
15557 if (err == VK_SUCCESS) {
15558 vkDestroyImageView(m_device->device(), view, NULL);
15559 }
Mark Youngd339ba32016-05-30 13:28:35 -060015560}
15561
Karl Schultz6addd812016-02-02 17:17:23 -070015562TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015563 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015565
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015566 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015567
Karl Schultz6addd812016-02-02 17:17:23 -070015568 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015569 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015570 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015571 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015572
15573 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015574 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015575 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015576 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15577 image_view_create_info.format = tex_format;
15578 image_view_create_info.subresourceRange.baseMipLevel = 0;
15579 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015580 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015581 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015583
15584 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015585 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015586
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015587 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015588}
15589
Mike Weiblena1e13f42017-02-09 21:25:59 -070015590TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15591 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15592
15593 ASSERT_NO_FATAL_FAILURE(InitState());
15594 VkSubresourceLayout subres_layout = {};
15595
15596 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15597 {
15598 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15599 VkImageObj img(m_device);
15600 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15601 ASSERT_TRUE(img.initialized());
15602
15603 VkImageSubresource subres = {};
15604 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15605 subres.mipLevel = 0;
15606 subres.arrayLayer = 0;
15607
15608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15609 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15610 m_errorMonitor->VerifyFound();
15611 }
15612
15613 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15614 {
15615 VkImageObj img(m_device);
15616 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15617 ASSERT_TRUE(img.initialized());
15618
15619 VkImageSubresource subres = {};
15620 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15621 subres.mipLevel = 0;
15622 subres.arrayLayer = 0;
15623
15624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15626 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15627 m_errorMonitor->VerifyFound();
15628 }
15629
15630 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15631 {
15632 VkImageObj img(m_device);
15633 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15634 ASSERT_TRUE(img.initialized());
15635
15636 VkImageSubresource subres = {};
15637 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15638 subres.mipLevel = 1; // ERROR: triggers VU 00739
15639 subres.arrayLayer = 0;
15640
15641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15642 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15643 m_errorMonitor->VerifyFound();
15644 }
15645
15646 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15647 {
15648 VkImageObj img(m_device);
15649 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15650 ASSERT_TRUE(img.initialized());
15651
15652 VkImageSubresource subres = {};
15653 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15654 subres.mipLevel = 0;
15655 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15656
15657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15658 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15659 m_errorMonitor->VerifyFound();
15660 }
15661}
15662
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015663TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015664 VkResult err;
15665 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015668
Mike Stroyana3082432015-09-25 13:39:21 -060015669 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015670
15671 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015672 VkImage srcImage;
15673 VkImage dstImage;
15674 VkDeviceMemory srcMem;
15675 VkDeviceMemory destMem;
15676 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015677
15678 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015679 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15680 image_create_info.pNext = NULL;
15681 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15682 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15683 image_create_info.extent.width = 32;
15684 image_create_info.extent.height = 32;
15685 image_create_info.extent.depth = 1;
15686 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015687 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015688 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15689 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15691 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015694 ASSERT_VK_SUCCESS(err);
15695
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015697 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015698 ASSERT_VK_SUCCESS(err);
15699
15700 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015701 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015702 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15703 memAlloc.pNext = NULL;
15704 memAlloc.allocationSize = 0;
15705 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015706
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015707 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015708 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015709 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015710 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015711 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015712 ASSERT_VK_SUCCESS(err);
15713
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015714 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015715 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015717 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015718 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_VK_SUCCESS(err);
15720
15721 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15722 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015723 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015724 ASSERT_VK_SUCCESS(err);
15725
Tony Barbour552f6c02016-12-21 14:34:07 -070015726 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015727 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015728 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015729 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015730 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015731 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015732 copyRegion.srcOffset.x = 0;
15733 copyRegion.srcOffset.y = 0;
15734 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015735 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015736 copyRegion.dstSubresource.mipLevel = 0;
15737 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015738 // Introduce failure by forcing the dst layerCount to differ from src
15739 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015740 copyRegion.dstOffset.x = 0;
15741 copyRegion.dstOffset.y = 0;
15742 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015743 copyRegion.extent.width = 1;
15744 copyRegion.extent.height = 1;
15745 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015746 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015747 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015749 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015750
Chia-I Wuf7458c52015-10-26 21:10:41 +080015751 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015752 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015753 vkFreeMemory(m_device->device(), srcMem, NULL);
15754 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015755}
15756
Tony Barbourd6673642016-05-05 14:46:39 -060015757TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015758 TEST_DESCRIPTION("Creating images with unsuported formats ");
15759
15760 ASSERT_NO_FATAL_FAILURE(InitState());
15761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15762 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015763 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 -060015764 VK_IMAGE_TILING_OPTIMAL, 0);
15765 ASSERT_TRUE(image.initialized());
15766
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015767 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015768 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015770 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15771 image_create_info.format = VK_FORMAT_UNDEFINED;
15772 image_create_info.extent.width = 32;
15773 image_create_info.extent.height = 32;
15774 image_create_info.extent.depth = 1;
15775 image_create_info.mipLevels = 1;
15776 image_create_info.arrayLayers = 1;
15777 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15778 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15779 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15782 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015783
15784 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015785 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15786 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15787 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15788 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015789 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15790 m_errorMonitor->VerifyFound();
15791
Tony Barbourd6673642016-05-05 14:46:39 -060015792 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015793 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015794 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15795 VkFormat format = static_cast<VkFormat>(f);
15796 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015797 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015798 unsupported = format;
15799 break;
15800 }
15801 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015802
Tony Barbourd6673642016-05-05 14:46:39 -060015803 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015804 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015806
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015807 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15808 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15809 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15810 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15811 m_errorMonitor->SetUnexpectedError(
15812 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15813 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15814 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015815 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015816 m_errorMonitor->VerifyFound();
15817 }
15818}
15819
15820TEST_F(VkLayerTest, ImageLayerViewTests) {
15821 VkResult ret;
15822 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15823
15824 ASSERT_NO_FATAL_FAILURE(InitState());
15825
15826 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015827 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 -060015828 VK_IMAGE_TILING_OPTIMAL, 0);
15829 ASSERT_TRUE(image.initialized());
15830
15831 VkImageView imgView;
15832 VkImageViewCreateInfo imgViewInfo = {};
15833 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15834 imgViewInfo.image = image.handle();
15835 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15836 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15837 imgViewInfo.subresourceRange.layerCount = 1;
15838 imgViewInfo.subresourceRange.baseMipLevel = 0;
15839 imgViewInfo.subresourceRange.levelCount = 1;
15840 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15841
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015843 // View can't have baseMipLevel >= image's mipLevels - Expect
15844 // VIEW_CREATE_ERROR
15845 imgViewInfo.subresourceRange.baseMipLevel = 1;
15846 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15847 m_errorMonitor->VerifyFound();
15848 imgViewInfo.subresourceRange.baseMipLevel = 0;
15849
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015851 // View can't have baseArrayLayer >= image's arraySize - Expect
15852 // VIEW_CREATE_ERROR
15853 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15854 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15855 m_errorMonitor->VerifyFound();
15856 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15857
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015859 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15860 imgViewInfo.subresourceRange.levelCount = 0;
15861 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15862 m_errorMonitor->VerifyFound();
15863 imgViewInfo.subresourceRange.levelCount = 1;
15864
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015865 m_errorMonitor->SetDesiredFailureMsg(
15866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15867 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015868 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15869 imgViewInfo.subresourceRange.layerCount = 0;
15870 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15871 m_errorMonitor->VerifyFound();
15872 imgViewInfo.subresourceRange.layerCount = 1;
15873
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15875 "Formats MUST be IDENTICAL unless "
15876 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15877 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015878 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15879 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15880 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15881 m_errorMonitor->VerifyFound();
15882 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15883
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015885 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15886 // VIEW_CREATE_ERROR
15887 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15888 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15889 m_errorMonitor->VerifyFound();
15890 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15891
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015893 // TODO: Update framework to easily passing mutable flag into ImageObj init
15894 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015895 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15896 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15897 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015898 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15899 // VIEW_CREATE_ERROR
15900 VkImageCreateInfo mutImgInfo = image.create_info();
15901 VkImage mutImage;
15902 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015903 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015904 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15905 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15906 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15907 ASSERT_VK_SUCCESS(ret);
15908 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015909 m_errorMonitor->SetUnexpectedError(
15910 "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 -060015911 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15912 m_errorMonitor->VerifyFound();
15913 imgViewInfo.image = image.handle();
15914 vkDestroyImage(m_device->handle(), mutImage, NULL);
15915}
15916
Dave Houlton59a20702017-02-02 17:26:23 -070015917TEST_F(VkLayerTest, ImageBufferCopyTests) {
15918 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15919
15920 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015921
15922 // Bail if any dimension of transfer granularity is 0.
15923 auto index = m_device->graphics_queue_node_index_;
15924 auto queue_family_properties = m_device->phy().queue_properties();
15925 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15926 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15927 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15928 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15929 return;
15930 }
15931
Dave Houlton59a20702017-02-02 17:26:23 -070015932 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15933 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15934 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015935 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15936 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15937 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15938 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15939
Dave Houlton59a20702017-02-02 17:26:23 -070015940 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15941 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15942 VK_IMAGE_TILING_OPTIMAL, 0);
15943 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15944 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15945 VK_IMAGE_TILING_OPTIMAL, 0);
15946 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15947 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015948 ASSERT_TRUE(image_64k.initialized());
15949 ASSERT_TRUE(image_16k.initialized());
15950 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015951
Dave Houltonf3229d52017-02-21 15:59:08 -070015952 // Verify all needed Depth/Stencil formats are supported
15953 bool missing_ds_support = false;
15954 VkFormatProperties props = {0, 0, 0};
15955 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15956 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15957 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15958 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15959 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15960 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15961 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15962 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15963
15964 if (!missing_ds_support) {
15965 ds_image_4D_1S.init(
15966 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
15967 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15968 VK_IMAGE_TILING_OPTIMAL, 0);
15969 ASSERT_TRUE(ds_image_4D_1S.initialized());
15970
15971 ds_image_3D_1S.init(
15972 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
15973 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15974 VK_IMAGE_TILING_OPTIMAL, 0);
15975 ASSERT_TRUE(ds_image_3D_1S.initialized());
15976
15977 ds_image_2D.init(
15978 256, 256, VK_FORMAT_D16_UNORM,
15979 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15980 VK_IMAGE_TILING_OPTIMAL, 0);
15981 ASSERT_TRUE(ds_image_2D.initialized());
15982
15983 ds_image_1S.init(
15984 256, 256, VK_FORMAT_S8_UINT,
15985 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15986 VK_IMAGE_TILING_OPTIMAL, 0);
15987 ASSERT_TRUE(ds_image_1S.initialized());
15988 }
15989
15990 // Allocate buffers
15991 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070015992 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070015993 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
15994 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
15995 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
15996 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070015997
15998 VkBufferImageCopy region = {};
15999 region.bufferRowLength = 0;
16000 region.bufferImageHeight = 0;
16001 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16002 region.imageSubresource.layerCount = 1;
16003 region.imageOffset = {0, 0, 0};
16004 region.imageExtent = {64, 64, 1};
16005 region.bufferOffset = 0;
16006
16007 // attempt copies before putting command buffer in recording state
16008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16009 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16010 &region);
16011 m_errorMonitor->VerifyFound();
16012
16013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16014 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16015 &region);
16016 m_errorMonitor->VerifyFound();
16017
16018 // start recording
16019 m_commandBuffer->BeginCommandBuffer();
16020
16021 // successful copies
16022 m_errorMonitor->ExpectSuccess();
16023 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16024 &region);
16025 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16026 &region);
16027 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16028 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16029 &region);
16030 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16031 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16032 &region);
16033 region.imageOffset.x = 0;
16034 region.imageExtent.height = 64;
16035 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16036 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16037 &region);
16038 m_errorMonitor->VerifyNotFound();
16039
16040 // image/buffer too small (extent) on copy to image
16041 region.imageExtent = {65, 64, 1};
16042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16044 &region);
16045 m_errorMonitor->VerifyFound();
16046
16047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16048 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16049 &region);
16050 m_errorMonitor->VerifyFound();
16051
16052 // image/buffer too small (offset) on copy to image
16053 region.imageExtent = {64, 64, 1};
16054 region.imageOffset = {0, 4, 0};
16055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16056 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16057 &region);
16058 m_errorMonitor->VerifyFound();
16059
16060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16061 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16062 &region);
16063 m_errorMonitor->VerifyFound();
16064
16065 // image/buffer too small on copy to buffer
16066 region.imageExtent = {64, 64, 1};
16067 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016068 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16070 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16071 &region);
16072 m_errorMonitor->VerifyFound();
16073
16074 region.imageExtent = {64, 65, 1};
16075 region.bufferOffset = 0;
16076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16077 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16078 &region);
16079 m_errorMonitor->VerifyFound();
16080
16081 // buffer size ok but rowlength causes loose packing
16082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16083 region.imageExtent = {64, 64, 1};
16084 region.bufferRowLength = 68;
16085 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16086 &region);
16087 m_errorMonitor->VerifyFound();
16088
Dave Houlton59a20702017-02-02 17:26:23 -070016089 // aspect bits
16090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16091 region.imageExtent = {64, 64, 1};
16092 region.bufferRowLength = 0;
16093 region.bufferImageHeight = 0;
16094 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16095 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16096 buffer_16k.handle(), 1, &region);
16097 m_errorMonitor->VerifyFound();
16098
16099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16100 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16101 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16102 &region);
16103 m_errorMonitor->VerifyFound();
16104
16105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16106 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16107 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16108 buffer_16k.handle(), 1, &region);
16109 m_errorMonitor->VerifyFound();
16110
Dave Houltonf3229d52017-02-21 15:59:08 -070016111 // Test Depth/Stencil copies
16112 if (missing_ds_support) {
16113 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16114 } else {
16115 VkBufferImageCopy ds_region = {};
16116 ds_region.bufferOffset = 0;
16117 ds_region.bufferRowLength = 0;
16118 ds_region.bufferImageHeight = 0;
16119 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16120 ds_region.imageSubresource.mipLevel = 0;
16121 ds_region.imageSubresource.baseArrayLayer = 0;
16122 ds_region.imageSubresource.layerCount = 1;
16123 ds_region.imageOffset = {0, 0, 0};
16124 ds_region.imageExtent = {256, 256, 1};
16125
16126 // Depth copies that should succeed
16127 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16128 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16129 buffer_256k.handle(), 1, &ds_region);
16130 m_errorMonitor->VerifyNotFound();
16131
16132 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16133 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16134 buffer_256k.handle(), 1, &ds_region);
16135 m_errorMonitor->VerifyNotFound();
16136
16137 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16138 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16139 buffer_128k.handle(), 1, &ds_region);
16140 m_errorMonitor->VerifyNotFound();
16141
16142 // Depth copies that should fail
16143 ds_region.bufferOffset = 4;
16144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16145 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16146 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16147 buffer_256k.handle(), 1, &ds_region);
16148 m_errorMonitor->VerifyFound();
16149
16150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16151 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16152 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16153 buffer_256k.handle(), 1, &ds_region);
16154 m_errorMonitor->VerifyFound();
16155
16156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16157 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16158 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16159 buffer_128k.handle(), 1, &ds_region);
16160 m_errorMonitor->VerifyFound();
16161
16162 // Stencil copies that should succeed
16163 ds_region.bufferOffset = 0;
16164 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16165 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16166 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16167 buffer_64k.handle(), 1, &ds_region);
16168 m_errorMonitor->VerifyNotFound();
16169
16170 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16171 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16172 buffer_64k.handle(), 1, &ds_region);
16173 m_errorMonitor->VerifyNotFound();
16174
16175 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16177 buffer_64k.handle(), 1, &ds_region);
16178 m_errorMonitor->VerifyNotFound();
16179
16180 // Stencil copies that should fail
16181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16182 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16183 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16184 buffer_16k.handle(), 1, &ds_region);
16185 m_errorMonitor->VerifyFound();
16186
16187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16188 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16189 ds_region.bufferRowLength = 260;
16190 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16191 buffer_64k.handle(), 1, &ds_region);
16192 m_errorMonitor->VerifyFound();
16193
16194 ds_region.bufferRowLength = 0;
16195 ds_region.bufferOffset = 4;
16196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16197 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16198 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16199 buffer_64k.handle(), 1, &ds_region);
16200 m_errorMonitor->VerifyFound();
16201 }
16202
Dave Houlton584d51e2017-02-16 12:52:54 -070016203 // Test compressed formats, if supported
16204 VkPhysicalDeviceFeatures device_features;
16205 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016206 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16207 device_features.textureCompressionASTC_LDR)) {
16208 printf(" No compressed formats supported - block compression tests skipped.\n");
16209 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016210 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16211 if (device_features.textureCompressionBC) {
16212 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16213 } else if (device_features.textureCompressionETC2) {
16214 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16215 VK_IMAGE_TILING_OPTIMAL, 0);
16216 } else {
16217 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16218 0);
16219 }
16220 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016221
Dave Houlton584d51e2017-02-16 12:52:54 -070016222 // Just fits
16223 m_errorMonitor->ExpectSuccess();
16224 region.imageExtent = {128, 128, 1};
16225 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16226 buffer_16k.handle(), 1, &region);
16227 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016228
Dave Houlton584d51e2017-02-16 12:52:54 -070016229 // with offset, too big for buffer
16230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16231 region.bufferOffset = 16;
16232 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16233 buffer_16k.handle(), 1, &region);
16234 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016235
Dave Houlton584d51e2017-02-16 12:52:54 -070016236 // buffer offset must be a multiple of texel block size (16)
16237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16239 region.imageExtent = {64, 64, 1};
16240 region.bufferOffset = 24;
16241 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16242 buffer_16k.handle(), 1, &region);
16243 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016244
Dave Houlton584d51e2017-02-16 12:52:54 -070016245 // rowlength not a multiple of block width (4)
16246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16247 region.bufferOffset = 0;
16248 region.bufferRowLength = 130;
16249 region.bufferImageHeight = 0;
16250 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16251 buffer_64k.handle(), 1, &region);
16252 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016253
Dave Houlton584d51e2017-02-16 12:52:54 -070016254 // imageheight not a multiple of block height (4)
16255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16256 region.bufferRowLength = 0;
16257 region.bufferImageHeight = 130;
16258 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16259 buffer_64k.handle(), 1, &region);
16260 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016261
Dave Houlton584d51e2017-02-16 12:52:54 -070016262 // image extents must be multiple of block dimensions (4x4)
16263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16264 region.bufferImageHeight = 0;
16265 region.imageOffset = {4, 6, 0};
16266 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16267 buffer_64k.handle(), 1, &region);
16268 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016269
Dave Houlton584d51e2017-02-16 12:52:54 -070016270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16271 region.imageOffset = {22, 0, 0};
16272 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16273 buffer_64k.handle(), 1, &region);
16274 m_errorMonitor->VerifyFound();
16275 }
Dave Houlton59a20702017-02-02 17:26:23 -070016276}
16277
Tony Barbourd6673642016-05-05 14:46:39 -060016278TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016279 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016280
16281 ASSERT_NO_FATAL_FAILURE(InitState());
16282
Rene Lindsay135204f2016-12-22 17:11:09 -070016283 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016284 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016285 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 -070016286 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016287 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016288 vk_testing::Buffer buffer;
16289 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016290 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016291 VkBufferImageCopy region = {};
16292 region.bufferRowLength = 128;
16293 region.bufferImageHeight = 128;
16294 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16295 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016296 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016297 region.imageExtent.height = 4;
16298 region.imageExtent.width = 4;
16299 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016300
16301 VkImageObj image2(m_device);
16302 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 -070016303 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016304 ASSERT_TRUE(image2.initialized());
16305 vk_testing::Buffer buffer2;
16306 VkMemoryPropertyFlags reqs2 = 0;
16307 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16308 VkBufferImageCopy region2 = {};
16309 region2.bufferRowLength = 128;
16310 region2.bufferImageHeight = 128;
16311 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16312 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16313 region2.imageSubresource.layerCount = 1;
16314 region2.imageExtent.height = 4;
16315 region2.imageExtent.width = 4;
16316 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016317 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016318
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016319 // Image must have offset.z of 0 and extent.depth of 1
16320 // Introduce failure by setting imageExtent.depth to 0
16321 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016323 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016324 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016325 m_errorMonitor->VerifyFound();
16326
16327 region.imageExtent.depth = 1;
16328
16329 // Image must have offset.z of 0 and extent.depth of 1
16330 // Introduce failure by setting imageOffset.z to 4
16331 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016333 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016334 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016335 m_errorMonitor->VerifyFound();
16336
16337 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016338 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16339 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016340 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016342 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16343 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016344 m_errorMonitor->VerifyFound();
16345
16346 // BufferOffset must be a multiple of 4
16347 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016348 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016350 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16351 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016352 m_errorMonitor->VerifyFound();
16353
16354 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16355 region.bufferOffset = 0;
16356 region.imageExtent.height = 128;
16357 region.imageExtent.width = 128;
16358 // Introduce failure by setting bufferRowLength > 0 but less than width
16359 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016361 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16362 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016363 m_errorMonitor->VerifyFound();
16364
16365 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16366 region.bufferRowLength = 128;
16367 // Introduce failure by setting bufferRowHeight > 0 but less than height
16368 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016370 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16371 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016372 m_errorMonitor->VerifyFound();
16373
16374 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016375 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016376 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16377 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016378 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016379 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16380 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016381 VkImageBlit blitRegion = {};
16382 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16383 blitRegion.srcSubresource.baseArrayLayer = 0;
16384 blitRegion.srcSubresource.layerCount = 1;
16385 blitRegion.srcSubresource.mipLevel = 0;
16386 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16387 blitRegion.dstSubresource.baseArrayLayer = 0;
16388 blitRegion.dstSubresource.layerCount = 1;
16389 blitRegion.dstSubresource.mipLevel = 0;
16390
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016391 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016393 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016394 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16395 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016396 m_errorMonitor->VerifyFound();
16397
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016399 VkImageMemoryBarrier img_barrier;
16400 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16401 img_barrier.pNext = NULL;
16402 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16403 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16404 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16405 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16406 img_barrier.image = image.handle();
16407 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16408 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16409 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16410 img_barrier.subresourceRange.baseArrayLayer = 0;
16411 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016412 img_barrier.subresourceRange.layerCount = 0;
16413 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016414 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16415 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016416 m_errorMonitor->VerifyFound();
16417 img_barrier.subresourceRange.layerCount = 1;
16418}
16419
16420TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016421 TEST_DESCRIPTION("Exceed the limits of image format ");
16422
Cody Northropc31a84f2016-08-22 10:41:47 -060016423 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016425 VkImageCreateInfo image_create_info = {};
16426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16427 image_create_info.pNext = NULL;
16428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16429 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16430 image_create_info.extent.width = 32;
16431 image_create_info.extent.height = 32;
16432 image_create_info.extent.depth = 1;
16433 image_create_info.mipLevels = 1;
16434 image_create_info.arrayLayers = 1;
16435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16436 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16437 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16438 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16439 image_create_info.flags = 0;
16440
16441 VkImage nullImg;
16442 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016443 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16444 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016445 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016446 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16447 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16448 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016449 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016452 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16453 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16454 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16455 m_errorMonitor->VerifyFound();
16456 image_create_info.mipLevels = 1;
16457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016459 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16460 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16461 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16462 m_errorMonitor->VerifyFound();
16463 image_create_info.arrayLayers = 1;
16464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016466 int samples = imgFmtProps.sampleCounts >> 1;
16467 image_create_info.samples = (VkSampleCountFlagBits)samples;
16468 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16469 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16470 m_errorMonitor->VerifyFound();
16471 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16474 "pCreateInfo->initialLayout, must be "
16475 "VK_IMAGE_LAYOUT_UNDEFINED or "
16476 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016477 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16478 // Expect INVALID_LAYOUT
16479 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16480 m_errorMonitor->VerifyFound();
16481 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16482}
16483
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016484TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016485 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016487
16488 ASSERT_NO_FATAL_FAILURE(InitState());
16489
16490 VkImageObj src_image(m_device);
16491 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16492 VkImageObj dst_image(m_device);
16493 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16494
Tony Barbour552f6c02016-12-21 14:34:07 -070016495 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016496 VkImageCopy copy_region;
16497 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16498 copy_region.srcSubresource.mipLevel = 0;
16499 copy_region.srcSubresource.baseArrayLayer = 0;
16500 copy_region.srcSubresource.layerCount = 0;
16501 copy_region.srcOffset.x = 0;
16502 copy_region.srcOffset.y = 0;
16503 copy_region.srcOffset.z = 0;
16504 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16505 copy_region.dstSubresource.mipLevel = 0;
16506 copy_region.dstSubresource.baseArrayLayer = 0;
16507 copy_region.dstSubresource.layerCount = 0;
16508 copy_region.dstOffset.x = 0;
16509 copy_region.dstOffset.y = 0;
16510 copy_region.dstOffset.z = 0;
16511 copy_region.extent.width = 64;
16512 copy_region.extent.height = 64;
16513 copy_region.extent.depth = 1;
16514 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16515 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016516 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016517
16518 m_errorMonitor->VerifyFound();
16519}
16520
16521TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016522 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016524
16525 ASSERT_NO_FATAL_FAILURE(InitState());
16526
16527 VkImageObj src_image(m_device);
16528 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16529 VkImageObj dst_image(m_device);
16530 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16531
Tony Barbour552f6c02016-12-21 14:34:07 -070016532 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016533 VkImageCopy copy_region;
16534 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16535 copy_region.srcSubresource.mipLevel = 0;
16536 copy_region.srcSubresource.baseArrayLayer = 0;
16537 copy_region.srcSubresource.layerCount = 0;
16538 copy_region.srcOffset.x = 0;
16539 copy_region.srcOffset.y = 0;
16540 copy_region.srcOffset.z = 0;
16541 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16542 copy_region.dstSubresource.mipLevel = 0;
16543 copy_region.dstSubresource.baseArrayLayer = 0;
16544 copy_region.dstSubresource.layerCount = 0;
16545 copy_region.dstOffset.x = 0;
16546 copy_region.dstOffset.y = 0;
16547 copy_region.dstOffset.z = 0;
16548 copy_region.extent.width = 64;
16549 copy_region.extent.height = 64;
16550 copy_region.extent.depth = 1;
16551 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16552 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016553 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016554
16555 m_errorMonitor->VerifyFound();
16556}
16557
Karl Schultz6addd812016-02-02 17:17:23 -070016558TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016559 VkResult err;
16560 bool pass;
16561
16562 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016564
16565 ASSERT_NO_FATAL_FAILURE(InitState());
16566
16567 // Create two images of different types and try to copy between them
16568 VkImage srcImage;
16569 VkImage dstImage;
16570 VkDeviceMemory srcMem;
16571 VkDeviceMemory destMem;
16572 VkMemoryRequirements memReqs;
16573
16574 VkImageCreateInfo image_create_info = {};
16575 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16576 image_create_info.pNext = NULL;
16577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16578 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16579 image_create_info.extent.width = 32;
16580 image_create_info.extent.height = 32;
16581 image_create_info.extent.depth = 1;
16582 image_create_info.mipLevels = 1;
16583 image_create_info.arrayLayers = 1;
16584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16585 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16587 image_create_info.flags = 0;
16588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016589 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016590 ASSERT_VK_SUCCESS(err);
16591
16592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16593 // Introduce failure by creating second image with a different-sized format.
16594 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016596 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016597 ASSERT_VK_SUCCESS(err);
16598
16599 // Allocate memory
16600 VkMemoryAllocateInfo memAlloc = {};
16601 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16602 memAlloc.pNext = NULL;
16603 memAlloc.allocationSize = 0;
16604 memAlloc.memoryTypeIndex = 0;
16605
16606 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16607 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016608 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016609 ASSERT_TRUE(pass);
16610 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16611 ASSERT_VK_SUCCESS(err);
16612
16613 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16614 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016615 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016616 ASSERT_TRUE(pass);
16617 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16618 ASSERT_VK_SUCCESS(err);
16619
16620 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16621 ASSERT_VK_SUCCESS(err);
16622 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16623 ASSERT_VK_SUCCESS(err);
16624
Tony Barbour552f6c02016-12-21 14:34:07 -070016625 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016626 VkImageCopy copyRegion;
16627 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16628 copyRegion.srcSubresource.mipLevel = 0;
16629 copyRegion.srcSubresource.baseArrayLayer = 0;
16630 copyRegion.srcSubresource.layerCount = 0;
16631 copyRegion.srcOffset.x = 0;
16632 copyRegion.srcOffset.y = 0;
16633 copyRegion.srcOffset.z = 0;
16634 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16635 copyRegion.dstSubresource.mipLevel = 0;
16636 copyRegion.dstSubresource.baseArrayLayer = 0;
16637 copyRegion.dstSubresource.layerCount = 0;
16638 copyRegion.dstOffset.x = 0;
16639 copyRegion.dstOffset.y = 0;
16640 copyRegion.dstOffset.z = 0;
16641 copyRegion.extent.width = 1;
16642 copyRegion.extent.height = 1;
16643 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016644 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016645 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016646
16647 m_errorMonitor->VerifyFound();
16648
16649 vkDestroyImage(m_device->device(), srcImage, NULL);
16650 vkDestroyImage(m_device->device(), dstImage, NULL);
16651 vkFreeMemory(m_device->device(), srcMem, NULL);
16652 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016653}
16654
Karl Schultz6addd812016-02-02 17:17:23 -070016655TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16656 VkResult err;
16657 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016658
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016659 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16661 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016662
Mike Stroyana3082432015-09-25 13:39:21 -060016663 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016664
16665 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016666 VkImage srcImage;
16667 VkImage dstImage;
16668 VkDeviceMemory srcMem;
16669 VkDeviceMemory destMem;
16670 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016671
16672 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016673 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16674 image_create_info.pNext = NULL;
16675 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16676 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16677 image_create_info.extent.width = 32;
16678 image_create_info.extent.height = 32;
16679 image_create_info.extent.depth = 1;
16680 image_create_info.mipLevels = 1;
16681 image_create_info.arrayLayers = 1;
16682 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16683 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16684 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16685 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016687 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016688 ASSERT_VK_SUCCESS(err);
16689
Karl Schultzbdb75952016-04-19 11:36:49 -060016690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16691
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016692 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016693 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016694 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016695 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016697 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016698 ASSERT_VK_SUCCESS(err);
16699
16700 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016701 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016702 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16703 memAlloc.pNext = NULL;
16704 memAlloc.allocationSize = 0;
16705 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016706
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016707 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016708 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016710 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016711 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016712 ASSERT_VK_SUCCESS(err);
16713
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016714 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016715 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016716 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016717 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016718 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016719 ASSERT_VK_SUCCESS(err);
16720
16721 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16722 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016723 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016724 ASSERT_VK_SUCCESS(err);
16725
Tony Barbour552f6c02016-12-21 14:34:07 -070016726 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016727 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016728 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016729 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016730 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016731 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016732 copyRegion.srcOffset.x = 0;
16733 copyRegion.srcOffset.y = 0;
16734 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016735 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016736 copyRegion.dstSubresource.mipLevel = 0;
16737 copyRegion.dstSubresource.baseArrayLayer = 0;
16738 copyRegion.dstSubresource.layerCount = 0;
16739 copyRegion.dstOffset.x = 0;
16740 copyRegion.dstOffset.y = 0;
16741 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016742 copyRegion.extent.width = 1;
16743 copyRegion.extent.height = 1;
16744 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016745 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016746 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016748 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016749
Chia-I Wuf7458c52015-10-26 21:10:41 +080016750 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016751 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016752 vkFreeMemory(m_device->device(), srcMem, NULL);
16753 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016754}
16755
Karl Schultz6addd812016-02-02 17:17:23 -070016756TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16757 VkResult err;
16758 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16761 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016762
Mike Stroyana3082432015-09-25 13:39:21 -060016763 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016764
16765 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016766 VkImage srcImage;
16767 VkImage dstImage;
16768 VkDeviceMemory srcMem;
16769 VkDeviceMemory destMem;
16770 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016771
16772 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016773 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16774 image_create_info.pNext = NULL;
16775 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16776 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16777 image_create_info.extent.width = 32;
16778 image_create_info.extent.height = 1;
16779 image_create_info.extent.depth = 1;
16780 image_create_info.mipLevels = 1;
16781 image_create_info.arrayLayers = 1;
16782 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16783 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16784 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16785 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016787 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016788 ASSERT_VK_SUCCESS(err);
16789
Karl Schultz6addd812016-02-02 17:17:23 -070016790 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016793 ASSERT_VK_SUCCESS(err);
16794
16795 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016796 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016797 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16798 memAlloc.pNext = NULL;
16799 memAlloc.allocationSize = 0;
16800 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016801
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016802 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016803 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016804 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016805 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016806 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016807 ASSERT_VK_SUCCESS(err);
16808
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016809 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016810 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016811 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016812 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016813 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016814 ASSERT_VK_SUCCESS(err);
16815
16816 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16817 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016818 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016819 ASSERT_VK_SUCCESS(err);
16820
Tony Barbour552f6c02016-12-21 14:34:07 -070016821 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016822 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016823 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16824 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016825 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016826 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016827 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016828 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016829 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016830 resolveRegion.srcOffset.x = 0;
16831 resolveRegion.srcOffset.y = 0;
16832 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016833 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016834 resolveRegion.dstSubresource.mipLevel = 0;
16835 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016836 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016837 resolveRegion.dstOffset.x = 0;
16838 resolveRegion.dstOffset.y = 0;
16839 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016840 resolveRegion.extent.width = 1;
16841 resolveRegion.extent.height = 1;
16842 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016843 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016844 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016845
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016846 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016847
Chia-I Wuf7458c52015-10-26 21:10:41 +080016848 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016849 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016850 vkFreeMemory(m_device->device(), srcMem, NULL);
16851 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016852}
16853
Karl Schultz6addd812016-02-02 17:17:23 -070016854TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16855 VkResult err;
16856 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16859 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016860
Mike Stroyana3082432015-09-25 13:39:21 -060016861 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016862
Chris Forbesa7530692016-05-08 12:35:39 +120016863 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016864 VkImage srcImage;
16865 VkImage dstImage;
16866 VkDeviceMemory srcMem;
16867 VkDeviceMemory destMem;
16868 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016869
16870 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016871 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16872 image_create_info.pNext = NULL;
16873 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16874 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16875 image_create_info.extent.width = 32;
16876 image_create_info.extent.height = 1;
16877 image_create_info.extent.depth = 1;
16878 image_create_info.mipLevels = 1;
16879 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016880 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016881 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16882 // Note: Some implementations expect color attachment usage for any
16883 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016884 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016885 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016887 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016888 ASSERT_VK_SUCCESS(err);
16889
Karl Schultz6addd812016-02-02 17:17:23 -070016890 // Note: Some implementations expect color attachment usage for any
16891 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016892 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016894 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016895 ASSERT_VK_SUCCESS(err);
16896
16897 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016898 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016899 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16900 memAlloc.pNext = NULL;
16901 memAlloc.allocationSize = 0;
16902 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016903
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016904 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016905 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016906 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016907 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016908 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016909 ASSERT_VK_SUCCESS(err);
16910
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016911 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016912 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016913 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016914 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016915 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016916 ASSERT_VK_SUCCESS(err);
16917
16918 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16919 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016920 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016921 ASSERT_VK_SUCCESS(err);
16922
Tony Barbour552f6c02016-12-21 14:34:07 -070016923 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016924 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016925 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16926 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016927 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016928 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016929 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016930 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016931 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016932 resolveRegion.srcOffset.x = 0;
16933 resolveRegion.srcOffset.y = 0;
16934 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016935 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016936 resolveRegion.dstSubresource.mipLevel = 0;
16937 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016938 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016939 resolveRegion.dstOffset.x = 0;
16940 resolveRegion.dstOffset.y = 0;
16941 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016942 resolveRegion.extent.width = 1;
16943 resolveRegion.extent.height = 1;
16944 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016945 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016946 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016948 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016949
Chia-I Wuf7458c52015-10-26 21:10:41 +080016950 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016951 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016952 vkFreeMemory(m_device->device(), srcMem, NULL);
16953 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016954}
16955
Karl Schultz6addd812016-02-02 17:17:23 -070016956TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16957 VkResult err;
16958 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016959
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016961 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016962
Mike Stroyana3082432015-09-25 13:39:21 -060016963 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016964
16965 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016966 VkImage srcImage;
16967 VkImage dstImage;
16968 VkDeviceMemory srcMem;
16969 VkDeviceMemory destMem;
16970 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016971
16972 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016973 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16974 image_create_info.pNext = NULL;
16975 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16976 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16977 image_create_info.extent.width = 32;
16978 image_create_info.extent.height = 1;
16979 image_create_info.extent.depth = 1;
16980 image_create_info.mipLevels = 1;
16981 image_create_info.arrayLayers = 1;
16982 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16983 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16984 // Note: Some implementations expect color attachment usage for any
16985 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016986 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016987 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016989 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016990 ASSERT_VK_SUCCESS(err);
16991
Karl Schultz6addd812016-02-02 17:17:23 -070016992 // Set format to something other than source image
16993 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16994 // Note: Some implementations expect color attachment usage for any
16995 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016996 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016997 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016999 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017000 ASSERT_VK_SUCCESS(err);
17001
17002 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017003 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017004 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17005 memAlloc.pNext = NULL;
17006 memAlloc.allocationSize = 0;
17007 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017008
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017009 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017010 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017011 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017012 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017013 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017014 ASSERT_VK_SUCCESS(err);
17015
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017016 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017017 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017018 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017019 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017020 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017021 ASSERT_VK_SUCCESS(err);
17022
17023 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17024 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017025 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017026 ASSERT_VK_SUCCESS(err);
17027
Tony Barbour552f6c02016-12-21 14:34:07 -070017028 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017029 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017030 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17031 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017032 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017033 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017034 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017035 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017036 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017037 resolveRegion.srcOffset.x = 0;
17038 resolveRegion.srcOffset.y = 0;
17039 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017040 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017041 resolveRegion.dstSubresource.mipLevel = 0;
17042 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017043 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017044 resolveRegion.dstOffset.x = 0;
17045 resolveRegion.dstOffset.y = 0;
17046 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017047 resolveRegion.extent.width = 1;
17048 resolveRegion.extent.height = 1;
17049 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017050 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017051 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017053 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017054
Chia-I Wuf7458c52015-10-26 21:10:41 +080017055 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017056 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017057 vkFreeMemory(m_device->device(), srcMem, NULL);
17058 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017059}
17060
Karl Schultz6addd812016-02-02 17:17:23 -070017061TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17062 VkResult err;
17063 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017064
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017066 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017067
Mike Stroyana3082432015-09-25 13:39:21 -060017068 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017069
17070 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017071 VkImage srcImage;
17072 VkImage dstImage;
17073 VkDeviceMemory srcMem;
17074 VkDeviceMemory destMem;
17075 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017076
17077 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17079 image_create_info.pNext = NULL;
17080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17081 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17082 image_create_info.extent.width = 32;
17083 image_create_info.extent.height = 1;
17084 image_create_info.extent.depth = 1;
17085 image_create_info.mipLevels = 1;
17086 image_create_info.arrayLayers = 1;
17087 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17089 // Note: Some implementations expect color attachment usage for any
17090 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017091 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017092 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017094 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017095 ASSERT_VK_SUCCESS(err);
17096
Karl Schultz6addd812016-02-02 17:17:23 -070017097 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17098 // Note: Some implementations expect color attachment usage for any
17099 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017100 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017103 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017104 ASSERT_VK_SUCCESS(err);
17105
17106 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017107 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017108 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17109 memAlloc.pNext = NULL;
17110 memAlloc.allocationSize = 0;
17111 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017112
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017113 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017114 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017115 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017116 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017117 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017118 ASSERT_VK_SUCCESS(err);
17119
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017120 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017121 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017122 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017123 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017124 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017125 ASSERT_VK_SUCCESS(err);
17126
17127 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17128 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017129 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017130 ASSERT_VK_SUCCESS(err);
17131
Tony Barbour552f6c02016-12-21 14:34:07 -070017132 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017133 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017134 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17135 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017136 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017137 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017138 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017139 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017140 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017141 resolveRegion.srcOffset.x = 0;
17142 resolveRegion.srcOffset.y = 0;
17143 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017144 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017145 resolveRegion.dstSubresource.mipLevel = 0;
17146 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017147 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017148 resolveRegion.dstOffset.x = 0;
17149 resolveRegion.dstOffset.y = 0;
17150 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017151 resolveRegion.extent.width = 1;
17152 resolveRegion.extent.height = 1;
17153 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017154 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017155 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017156
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017157 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017158
Chia-I Wuf7458c52015-10-26 21:10:41 +080017159 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017160 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017161 vkFreeMemory(m_device->device(), srcMem, NULL);
17162 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017163}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017164
Karl Schultz6addd812016-02-02 17:17:23 -070017165TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017166 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017167 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17168 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017169 // The image format check comes 2nd in validation so we trigger it first,
17170 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017171 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17174 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017175
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017176 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017177
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017178 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017179 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17180 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017181
17182 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017183 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17184 ds_pool_ci.pNext = NULL;
17185 ds_pool_ci.maxSets = 1;
17186 ds_pool_ci.poolSizeCount = 1;
17187 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017188
17189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017191 ASSERT_VK_SUCCESS(err);
17192
17193 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017194 dsl_binding.binding = 0;
17195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17196 dsl_binding.descriptorCount = 1;
17197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17198 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017199
17200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17202 ds_layout_ci.pNext = NULL;
17203 ds_layout_ci.bindingCount = 1;
17204 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017205 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017207 ASSERT_VK_SUCCESS(err);
17208
17209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017212 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017213 alloc_info.descriptorPool = ds_pool;
17214 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017216 ASSERT_VK_SUCCESS(err);
17217
Karl Schultz6addd812016-02-02 17:17:23 -070017218 VkImage image_bad;
17219 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017220 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017221 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017222 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017223 const int32_t tex_width = 32;
17224 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017225
17226 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017227 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17228 image_create_info.pNext = NULL;
17229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17230 image_create_info.format = tex_format_bad;
17231 image_create_info.extent.width = tex_width;
17232 image_create_info.extent.height = tex_height;
17233 image_create_info.extent.depth = 1;
17234 image_create_info.mipLevels = 1;
17235 image_create_info.arrayLayers = 1;
17236 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17237 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017238 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017239 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017241 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017242 ASSERT_VK_SUCCESS(err);
17243 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017244 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17245 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017246 ASSERT_VK_SUCCESS(err);
17247
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017248 // ---Bind image memory---
17249 VkMemoryRequirements img_mem_reqs;
17250 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17251 VkMemoryAllocateInfo image_alloc_info = {};
17252 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17253 image_alloc_info.pNext = NULL;
17254 image_alloc_info.memoryTypeIndex = 0;
17255 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017256 bool pass =
17257 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 -070017258 ASSERT_TRUE(pass);
17259 VkDeviceMemory mem;
17260 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17261 ASSERT_VK_SUCCESS(err);
17262 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17263 ASSERT_VK_SUCCESS(err);
17264 // -----------------------
17265
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017266 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017267 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017268 image_view_create_info.image = image_bad;
17269 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17270 image_view_create_info.format = tex_format_bad;
17271 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17272 image_view_create_info.subresourceRange.baseMipLevel = 0;
17273 image_view_create_info.subresourceRange.layerCount = 1;
17274 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017275 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017276
17277 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017278 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017279
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017280 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017281
Chia-I Wuf7458c52015-10-26 21:10:41 +080017282 vkDestroyImage(m_device->device(), image_bad, NULL);
17283 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017284 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17285 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017286
17287 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017288}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017289
17290TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017291 TEST_DESCRIPTION(
17292 "Call ClearColorImage w/ a depth|stencil image and "
17293 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017294
17295 ASSERT_NO_FATAL_FAILURE(InitState());
17296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17297
Tony Barbour552f6c02016-12-21 14:34:07 -070017298 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017299
17300 // Color image
17301 VkClearColorValue clear_color;
17302 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17303 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17304 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17305 const int32_t img_width = 32;
17306 const int32_t img_height = 32;
17307 VkImageCreateInfo image_create_info = {};
17308 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17309 image_create_info.pNext = NULL;
17310 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17311 image_create_info.format = color_format;
17312 image_create_info.extent.width = img_width;
17313 image_create_info.extent.height = img_height;
17314 image_create_info.extent.depth = 1;
17315 image_create_info.mipLevels = 1;
17316 image_create_info.arrayLayers = 1;
17317 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17318 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17319 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17320
17321 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017322 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017324 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017325
17326 // Depth/Stencil image
17327 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017328 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017329 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17330 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17331 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17332 ds_image_create_info.extent.width = 64;
17333 ds_image_create_info.extent.height = 64;
17334 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017335 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 -060017336
17337 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017338 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017340 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 -060017341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017344 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017345 &color_range);
17346
17347 m_errorMonitor->VerifyFound();
17348
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17350 "vkCmdClearColorImage called with "
17351 "image created without "
17352 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017353
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017354 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017355 &color_range);
17356
17357 m_errorMonitor->VerifyFound();
17358
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017359 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17361 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017362
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017363 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17364 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017365
17366 m_errorMonitor->VerifyFound();
17367}
Tobin Ehliscde08892015-09-22 10:11:37 -060017368
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017369// WSI Enabled Tests
17370//
Chris Forbes09368e42016-10-13 11:59:22 +130017371#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017372TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17373
17374#if defined(VK_USE_PLATFORM_XCB_KHR)
17375 VkSurfaceKHR surface = VK_NULL_HANDLE;
17376
17377 VkResult err;
17378 bool pass;
17379 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17380 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17381 // uint32_t swapchain_image_count = 0;
17382 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17383 // uint32_t image_index = 0;
17384 // VkPresentInfoKHR present_info = {};
17385
17386 ASSERT_NO_FATAL_FAILURE(InitState());
17387
17388 // Use the create function from one of the VK_KHR_*_surface extension in
17389 // order to create a surface, testing all known errors in the process,
17390 // before successfully creating a surface:
17391 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17393 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17394 pass = (err != VK_SUCCESS);
17395 ASSERT_TRUE(pass);
17396 m_errorMonitor->VerifyFound();
17397
17398 // Next, try to create a surface with the wrong
17399 // VkXcbSurfaceCreateInfoKHR::sType:
17400 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17401 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17403 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17404 pass = (err != VK_SUCCESS);
17405 ASSERT_TRUE(pass);
17406 m_errorMonitor->VerifyFound();
17407
17408 // Create a native window, and then correctly create a surface:
17409 xcb_connection_t *connection;
17410 xcb_screen_t *screen;
17411 xcb_window_t xcb_window;
17412 xcb_intern_atom_reply_t *atom_wm_delete_window;
17413
17414 const xcb_setup_t *setup;
17415 xcb_screen_iterator_t iter;
17416 int scr;
17417 uint32_t value_mask, value_list[32];
17418 int width = 1;
17419 int height = 1;
17420
17421 connection = xcb_connect(NULL, &scr);
17422 ASSERT_TRUE(connection != NULL);
17423 setup = xcb_get_setup(connection);
17424 iter = xcb_setup_roots_iterator(setup);
17425 while (scr-- > 0)
17426 xcb_screen_next(&iter);
17427 screen = iter.data;
17428
17429 xcb_window = xcb_generate_id(connection);
17430
17431 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17432 value_list[0] = screen->black_pixel;
17433 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17434
17435 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17436 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17437
17438 /* Magic code that will send notification when window is destroyed */
17439 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17440 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17441
17442 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17443 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17444 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17445 free(reply);
17446
17447 xcb_map_window(connection, xcb_window);
17448
17449 // Force the x/y coordinates to 100,100 results are identical in consecutive
17450 // runs
17451 const uint32_t coords[] = { 100, 100 };
17452 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17453
17454 // Finally, try to correctly create a surface:
17455 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17456 xcb_create_info.pNext = NULL;
17457 xcb_create_info.flags = 0;
17458 xcb_create_info.connection = connection;
17459 xcb_create_info.window = xcb_window;
17460 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17461 pass = (err == VK_SUCCESS);
17462 ASSERT_TRUE(pass);
17463
17464 // Check if surface supports presentation:
17465
17466 // 1st, do so without having queried the queue families:
17467 VkBool32 supported = false;
17468 // TODO: Get the following error to come out:
17469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17470 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17471 "function");
17472 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17473 pass = (err != VK_SUCCESS);
17474 // ASSERT_TRUE(pass);
17475 // m_errorMonitor->VerifyFound();
17476
17477 // Next, query a queue family index that's too large:
17478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17479 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17480 pass = (err != VK_SUCCESS);
17481 ASSERT_TRUE(pass);
17482 m_errorMonitor->VerifyFound();
17483
17484 // Finally, do so correctly:
17485 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17486 // SUPPORTED
17487 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17488 pass = (err == VK_SUCCESS);
17489 ASSERT_TRUE(pass);
17490
17491 // Before proceeding, try to create a swapchain without having called
17492 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17493 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17494 swapchain_create_info.pNext = NULL;
17495 swapchain_create_info.flags = 0;
17496 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17497 swapchain_create_info.surface = surface;
17498 swapchain_create_info.imageArrayLayers = 1;
17499 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17500 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17502 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17503 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17504 pass = (err != VK_SUCCESS);
17505 ASSERT_TRUE(pass);
17506 m_errorMonitor->VerifyFound();
17507
17508 // Get the surface capabilities:
17509 VkSurfaceCapabilitiesKHR surface_capabilities;
17510
17511 // Do so correctly (only error logged by this entrypoint is if the
17512 // extension isn't enabled):
17513 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17514 pass = (err == VK_SUCCESS);
17515 ASSERT_TRUE(pass);
17516
17517 // Get the surface formats:
17518 uint32_t surface_format_count;
17519
17520 // First, try without a pointer to surface_format_count:
17521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17522 "specified as NULL");
17523 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17524 pass = (err == VK_SUCCESS);
17525 ASSERT_TRUE(pass);
17526 m_errorMonitor->VerifyFound();
17527
17528 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17529 // correctly done a 1st try (to get the count):
17530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17531 surface_format_count = 0;
17532 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17533 pass = (err == VK_SUCCESS);
17534 ASSERT_TRUE(pass);
17535 m_errorMonitor->VerifyFound();
17536
17537 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17538 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17539 pass = (err == VK_SUCCESS);
17540 ASSERT_TRUE(pass);
17541
17542 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17543 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17544
17545 // Next, do a 2nd try with surface_format_count being set too high:
17546 surface_format_count += 5;
17547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17548 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17549 pass = (err == VK_SUCCESS);
17550 ASSERT_TRUE(pass);
17551 m_errorMonitor->VerifyFound();
17552
17553 // Finally, do a correct 1st and 2nd try:
17554 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17555 pass = (err == VK_SUCCESS);
17556 ASSERT_TRUE(pass);
17557 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17558 pass = (err == VK_SUCCESS);
17559 ASSERT_TRUE(pass);
17560
17561 // Get the surface present modes:
17562 uint32_t surface_present_mode_count;
17563
17564 // First, try without a pointer to surface_format_count:
17565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17566 "specified as NULL");
17567
17568 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17569 pass = (err == VK_SUCCESS);
17570 ASSERT_TRUE(pass);
17571 m_errorMonitor->VerifyFound();
17572
17573 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17574 // correctly done a 1st try (to get the count):
17575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17576 surface_present_mode_count = 0;
17577 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17578 (VkPresentModeKHR *)&surface_present_mode_count);
17579 pass = (err == VK_SUCCESS);
17580 ASSERT_TRUE(pass);
17581 m_errorMonitor->VerifyFound();
17582
17583 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17584 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17585 pass = (err == VK_SUCCESS);
17586 ASSERT_TRUE(pass);
17587
17588 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17589 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17590
17591 // Next, do a 2nd try with surface_format_count being set too high:
17592 surface_present_mode_count += 5;
17593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17594 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17595 pass = (err == VK_SUCCESS);
17596 ASSERT_TRUE(pass);
17597 m_errorMonitor->VerifyFound();
17598
17599 // Finally, do a correct 1st and 2nd try:
17600 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17601 pass = (err == VK_SUCCESS);
17602 ASSERT_TRUE(pass);
17603 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17604 pass = (err == VK_SUCCESS);
17605 ASSERT_TRUE(pass);
17606
17607 // Create a swapchain:
17608
17609 // First, try without a pointer to swapchain_create_info:
17610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17611 "specified as NULL");
17612
17613 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17614 pass = (err != VK_SUCCESS);
17615 ASSERT_TRUE(pass);
17616 m_errorMonitor->VerifyFound();
17617
17618 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17619 // sType:
17620 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17622
17623 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17624 pass = (err != VK_SUCCESS);
17625 ASSERT_TRUE(pass);
17626 m_errorMonitor->VerifyFound();
17627
17628 // Next, call with a NULL swapchain pointer:
17629 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17630 swapchain_create_info.pNext = NULL;
17631 swapchain_create_info.flags = 0;
17632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17633 "specified as NULL");
17634
17635 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17636 pass = (err != VK_SUCCESS);
17637 ASSERT_TRUE(pass);
17638 m_errorMonitor->VerifyFound();
17639
17640 // TODO: Enhance swapchain layer so that
17641 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17642
17643 // Next, call with a queue family index that's too large:
17644 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17645 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17646 swapchain_create_info.queueFamilyIndexCount = 2;
17647 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17649 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17650 pass = (err != VK_SUCCESS);
17651 ASSERT_TRUE(pass);
17652 m_errorMonitor->VerifyFound();
17653
17654 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17655 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17656 swapchain_create_info.queueFamilyIndexCount = 1;
17657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17658 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17659 "pCreateInfo->pQueueFamilyIndices).");
17660 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17661 pass = (err != VK_SUCCESS);
17662 ASSERT_TRUE(pass);
17663 m_errorMonitor->VerifyFound();
17664
17665 // Next, call with an invalid imageSharingMode:
17666 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17667 swapchain_create_info.queueFamilyIndexCount = 1;
17668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17669 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17670 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17671 pass = (err != VK_SUCCESS);
17672 ASSERT_TRUE(pass);
17673 m_errorMonitor->VerifyFound();
17674 // Fix for the future:
17675 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17676 // SUPPORTED
17677 swapchain_create_info.queueFamilyIndexCount = 0;
17678 queueFamilyIndex[0] = 0;
17679 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17680
17681 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17682 // Get the images from a swapchain:
17683 // Acquire an image from a swapchain:
17684 // Present an image to a swapchain:
17685 // Destroy the swapchain:
17686
17687 // TODOs:
17688 //
17689 // - Try destroying the device without first destroying the swapchain
17690 //
17691 // - Try destroying the device without first destroying the surface
17692 //
17693 // - Try destroying the surface without first destroying the swapchain
17694
17695 // Destroy the surface:
17696 vkDestroySurfaceKHR(instance(), surface, NULL);
17697
17698 // Tear down the window:
17699 xcb_destroy_window(connection, xcb_window);
17700 xcb_disconnect(connection);
17701
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017702#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017703 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017704#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017705}
Chris Forbes09368e42016-10-13 11:59:22 +130017706#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017707
17708//
17709// POSITIVE VALIDATION TESTS
17710//
17711// These tests do not expect to encounter ANY validation errors pass only if this is true
17712
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017713TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17714 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17715 ASSERT_NO_FATAL_FAILURE(InitState());
17716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17717
17718 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17719 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17720 command_buffer_allocate_info.commandPool = m_commandPool;
17721 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17722 command_buffer_allocate_info.commandBufferCount = 1;
17723
17724 VkCommandBuffer secondary_command_buffer;
17725 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17726 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17727 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17728 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17729 command_buffer_inheritance_info.renderPass = m_renderPass;
17730 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17731
17732 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17733 command_buffer_begin_info.flags =
17734 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17735 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17736
17737 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17738 VkClearAttachment color_attachment;
17739 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17740 color_attachment.clearValue.color.float32[0] = 0;
17741 color_attachment.clearValue.color.float32[1] = 0;
17742 color_attachment.clearValue.color.float32[2] = 0;
17743 color_attachment.clearValue.color.float32[3] = 0;
17744 color_attachment.colorAttachment = 0;
17745 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17746 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17747}
17748
Tobin Ehlise0006882016-11-03 10:14:28 -060017749TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017750 TEST_DESCRIPTION(
17751 "Perform an image layout transition in a secondary command buffer followed "
17752 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017753 VkResult err;
17754 m_errorMonitor->ExpectSuccess();
17755 ASSERT_NO_FATAL_FAILURE(InitState());
17756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17757 // Allocate a secondary and primary cmd buffer
17758 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17759 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17760 command_buffer_allocate_info.commandPool = m_commandPool;
17761 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17762 command_buffer_allocate_info.commandBufferCount = 1;
17763
17764 VkCommandBuffer secondary_command_buffer;
17765 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17766 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17767 VkCommandBuffer primary_command_buffer;
17768 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17769 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17770 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17771 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17772 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17773 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17774 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17775
17776 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17777 ASSERT_VK_SUCCESS(err);
17778 VkImageObj image(m_device);
17779 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17780 ASSERT_TRUE(image.initialized());
17781 VkImageMemoryBarrier img_barrier = {};
17782 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17783 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17784 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17785 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17786 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17787 img_barrier.image = image.handle();
17788 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17789 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17790 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17791 img_barrier.subresourceRange.baseArrayLayer = 0;
17792 img_barrier.subresourceRange.baseMipLevel = 0;
17793 img_barrier.subresourceRange.layerCount = 1;
17794 img_barrier.subresourceRange.levelCount = 1;
17795 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17796 0, nullptr, 1, &img_barrier);
17797 err = vkEndCommandBuffer(secondary_command_buffer);
17798 ASSERT_VK_SUCCESS(err);
17799
17800 // Now update primary cmd buffer to execute secondary and transitions image
17801 command_buffer_begin_info.pInheritanceInfo = nullptr;
17802 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17803 ASSERT_VK_SUCCESS(err);
17804 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17805 VkImageMemoryBarrier img_barrier2 = {};
17806 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17807 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17808 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17809 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17810 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17811 img_barrier2.image = image.handle();
17812 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17813 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17814 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17815 img_barrier2.subresourceRange.baseArrayLayer = 0;
17816 img_barrier2.subresourceRange.baseMipLevel = 0;
17817 img_barrier2.subresourceRange.layerCount = 1;
17818 img_barrier2.subresourceRange.levelCount = 1;
17819 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17820 nullptr, 1, &img_barrier2);
17821 err = vkEndCommandBuffer(primary_command_buffer);
17822 ASSERT_VK_SUCCESS(err);
17823 VkSubmitInfo submit_info = {};
17824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17825 submit_info.commandBufferCount = 1;
17826 submit_info.pCommandBuffers = &primary_command_buffer;
17827 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17828 ASSERT_VK_SUCCESS(err);
17829 m_errorMonitor->VerifyNotFound();
17830 err = vkDeviceWaitIdle(m_device->device());
17831 ASSERT_VK_SUCCESS(err);
17832 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17833 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17834}
17835
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017836// This is a positive test. No failures are expected.
17837TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017838 TEST_DESCRIPTION(
17839 "Ensure that the vkUpdateDescriptorSets validation code "
17840 "is ignoring VkWriteDescriptorSet members that are not "
17841 "related to the descriptor type specified by "
17842 "VkWriteDescriptorSet::descriptorType. Correct "
17843 "validation behavior will result in the test running to "
17844 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017845
17846 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17847
17848 ASSERT_NO_FATAL_FAILURE(InitState());
17849
17850 // Image Case
17851 {
17852 m_errorMonitor->ExpectSuccess();
17853
17854 VkImage image;
17855 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17856 const int32_t tex_width = 32;
17857 const int32_t tex_height = 32;
17858 VkImageCreateInfo image_create_info = {};
17859 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17860 image_create_info.pNext = NULL;
17861 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17862 image_create_info.format = tex_format;
17863 image_create_info.extent.width = tex_width;
17864 image_create_info.extent.height = tex_height;
17865 image_create_info.extent.depth = 1;
17866 image_create_info.mipLevels = 1;
17867 image_create_info.arrayLayers = 1;
17868 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17869 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17870 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17871 image_create_info.flags = 0;
17872 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17873 ASSERT_VK_SUCCESS(err);
17874
17875 VkMemoryRequirements memory_reqs;
17876 VkDeviceMemory image_memory;
17877 bool pass;
17878 VkMemoryAllocateInfo memory_info = {};
17879 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17880 memory_info.pNext = NULL;
17881 memory_info.allocationSize = 0;
17882 memory_info.memoryTypeIndex = 0;
17883 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17884 memory_info.allocationSize = memory_reqs.size;
17885 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17886 ASSERT_TRUE(pass);
17887 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17888 ASSERT_VK_SUCCESS(err);
17889 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17890 ASSERT_VK_SUCCESS(err);
17891
17892 VkImageViewCreateInfo image_view_create_info = {};
17893 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17894 image_view_create_info.image = image;
17895 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17896 image_view_create_info.format = tex_format;
17897 image_view_create_info.subresourceRange.layerCount = 1;
17898 image_view_create_info.subresourceRange.baseMipLevel = 0;
17899 image_view_create_info.subresourceRange.levelCount = 1;
17900 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17901
17902 VkImageView view;
17903 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17904 ASSERT_VK_SUCCESS(err);
17905
17906 VkDescriptorPoolSize ds_type_count = {};
17907 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17908 ds_type_count.descriptorCount = 1;
17909
17910 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17911 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17912 ds_pool_ci.pNext = NULL;
17913 ds_pool_ci.maxSets = 1;
17914 ds_pool_ci.poolSizeCount = 1;
17915 ds_pool_ci.pPoolSizes = &ds_type_count;
17916
17917 VkDescriptorPool ds_pool;
17918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17919 ASSERT_VK_SUCCESS(err);
17920
17921 VkDescriptorSetLayoutBinding dsl_binding = {};
17922 dsl_binding.binding = 0;
17923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17924 dsl_binding.descriptorCount = 1;
17925 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17926 dsl_binding.pImmutableSamplers = NULL;
17927
17928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17930 ds_layout_ci.pNext = NULL;
17931 ds_layout_ci.bindingCount = 1;
17932 ds_layout_ci.pBindings = &dsl_binding;
17933 VkDescriptorSetLayout ds_layout;
17934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17935 ASSERT_VK_SUCCESS(err);
17936
17937 VkDescriptorSet descriptor_set;
17938 VkDescriptorSetAllocateInfo alloc_info = {};
17939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17940 alloc_info.descriptorSetCount = 1;
17941 alloc_info.descriptorPool = ds_pool;
17942 alloc_info.pSetLayouts = &ds_layout;
17943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17944 ASSERT_VK_SUCCESS(err);
17945
17946 VkDescriptorImageInfo image_info = {};
17947 image_info.imageView = view;
17948 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17949
17950 VkWriteDescriptorSet descriptor_write;
17951 memset(&descriptor_write, 0, sizeof(descriptor_write));
17952 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17953 descriptor_write.dstSet = descriptor_set;
17954 descriptor_write.dstBinding = 0;
17955 descriptor_write.descriptorCount = 1;
17956 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17957 descriptor_write.pImageInfo = &image_info;
17958
17959 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17960 // be
17961 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17962 // This will most likely produce a crash if the parameter_validation
17963 // layer
17964 // does not correctly ignore pBufferInfo.
17965 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17966 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17967
17968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17969
17970 m_errorMonitor->VerifyNotFound();
17971
17972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17973 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17974 vkDestroyImageView(m_device->device(), view, NULL);
17975 vkDestroyImage(m_device->device(), image, NULL);
17976 vkFreeMemory(m_device->device(), image_memory, NULL);
17977 }
17978
17979 // Buffer Case
17980 {
17981 m_errorMonitor->ExpectSuccess();
17982
17983 VkBuffer buffer;
17984 uint32_t queue_family_index = 0;
17985 VkBufferCreateInfo buffer_create_info = {};
17986 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17987 buffer_create_info.size = 1024;
17988 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17989 buffer_create_info.queueFamilyIndexCount = 1;
17990 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17991
17992 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17993 ASSERT_VK_SUCCESS(err);
17994
17995 VkMemoryRequirements memory_reqs;
17996 VkDeviceMemory buffer_memory;
17997 bool pass;
17998 VkMemoryAllocateInfo memory_info = {};
17999 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18000 memory_info.pNext = NULL;
18001 memory_info.allocationSize = 0;
18002 memory_info.memoryTypeIndex = 0;
18003
18004 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18005 memory_info.allocationSize = memory_reqs.size;
18006 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18007 ASSERT_TRUE(pass);
18008
18009 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18010 ASSERT_VK_SUCCESS(err);
18011 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18012 ASSERT_VK_SUCCESS(err);
18013
18014 VkDescriptorPoolSize ds_type_count = {};
18015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18016 ds_type_count.descriptorCount = 1;
18017
18018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18020 ds_pool_ci.pNext = NULL;
18021 ds_pool_ci.maxSets = 1;
18022 ds_pool_ci.poolSizeCount = 1;
18023 ds_pool_ci.pPoolSizes = &ds_type_count;
18024
18025 VkDescriptorPool ds_pool;
18026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18027 ASSERT_VK_SUCCESS(err);
18028
18029 VkDescriptorSetLayoutBinding dsl_binding = {};
18030 dsl_binding.binding = 0;
18031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18032 dsl_binding.descriptorCount = 1;
18033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18034 dsl_binding.pImmutableSamplers = NULL;
18035
18036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18038 ds_layout_ci.pNext = NULL;
18039 ds_layout_ci.bindingCount = 1;
18040 ds_layout_ci.pBindings = &dsl_binding;
18041 VkDescriptorSetLayout ds_layout;
18042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18043 ASSERT_VK_SUCCESS(err);
18044
18045 VkDescriptorSet descriptor_set;
18046 VkDescriptorSetAllocateInfo alloc_info = {};
18047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18048 alloc_info.descriptorSetCount = 1;
18049 alloc_info.descriptorPool = ds_pool;
18050 alloc_info.pSetLayouts = &ds_layout;
18051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18052 ASSERT_VK_SUCCESS(err);
18053
18054 VkDescriptorBufferInfo buffer_info = {};
18055 buffer_info.buffer = buffer;
18056 buffer_info.offset = 0;
18057 buffer_info.range = 1024;
18058
18059 VkWriteDescriptorSet descriptor_write;
18060 memset(&descriptor_write, 0, sizeof(descriptor_write));
18061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18062 descriptor_write.dstSet = descriptor_set;
18063 descriptor_write.dstBinding = 0;
18064 descriptor_write.descriptorCount = 1;
18065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18066 descriptor_write.pBufferInfo = &buffer_info;
18067
18068 // Set pImageInfo and pTexelBufferView to invalid values, which should
18069 // be
18070 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18071 // This will most likely produce a crash if the parameter_validation
18072 // layer
18073 // does not correctly ignore pImageInfo.
18074 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18075 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18076
18077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18078
18079 m_errorMonitor->VerifyNotFound();
18080
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18082 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18083 vkDestroyBuffer(m_device->device(), buffer, NULL);
18084 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18085 }
18086
18087 // Texel Buffer Case
18088 {
18089 m_errorMonitor->ExpectSuccess();
18090
18091 VkBuffer buffer;
18092 uint32_t queue_family_index = 0;
18093 VkBufferCreateInfo buffer_create_info = {};
18094 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18095 buffer_create_info.size = 1024;
18096 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18097 buffer_create_info.queueFamilyIndexCount = 1;
18098 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18099
18100 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18101 ASSERT_VK_SUCCESS(err);
18102
18103 VkMemoryRequirements memory_reqs;
18104 VkDeviceMemory buffer_memory;
18105 bool pass;
18106 VkMemoryAllocateInfo memory_info = {};
18107 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18108 memory_info.pNext = NULL;
18109 memory_info.allocationSize = 0;
18110 memory_info.memoryTypeIndex = 0;
18111
18112 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18113 memory_info.allocationSize = memory_reqs.size;
18114 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18115 ASSERT_TRUE(pass);
18116
18117 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18118 ASSERT_VK_SUCCESS(err);
18119 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18120 ASSERT_VK_SUCCESS(err);
18121
18122 VkBufferViewCreateInfo buff_view_ci = {};
18123 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18124 buff_view_ci.buffer = buffer;
18125 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18126 buff_view_ci.range = VK_WHOLE_SIZE;
18127 VkBufferView buffer_view;
18128 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18129
18130 VkDescriptorPoolSize ds_type_count = {};
18131 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18132 ds_type_count.descriptorCount = 1;
18133
18134 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18135 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18136 ds_pool_ci.pNext = NULL;
18137 ds_pool_ci.maxSets = 1;
18138 ds_pool_ci.poolSizeCount = 1;
18139 ds_pool_ci.pPoolSizes = &ds_type_count;
18140
18141 VkDescriptorPool ds_pool;
18142 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18143 ASSERT_VK_SUCCESS(err);
18144
18145 VkDescriptorSetLayoutBinding dsl_binding = {};
18146 dsl_binding.binding = 0;
18147 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18148 dsl_binding.descriptorCount = 1;
18149 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18150 dsl_binding.pImmutableSamplers = NULL;
18151
18152 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18153 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18154 ds_layout_ci.pNext = NULL;
18155 ds_layout_ci.bindingCount = 1;
18156 ds_layout_ci.pBindings = &dsl_binding;
18157 VkDescriptorSetLayout ds_layout;
18158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18159 ASSERT_VK_SUCCESS(err);
18160
18161 VkDescriptorSet descriptor_set;
18162 VkDescriptorSetAllocateInfo alloc_info = {};
18163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18164 alloc_info.descriptorSetCount = 1;
18165 alloc_info.descriptorPool = ds_pool;
18166 alloc_info.pSetLayouts = &ds_layout;
18167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18168 ASSERT_VK_SUCCESS(err);
18169
18170 VkWriteDescriptorSet descriptor_write;
18171 memset(&descriptor_write, 0, sizeof(descriptor_write));
18172 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18173 descriptor_write.dstSet = descriptor_set;
18174 descriptor_write.dstBinding = 0;
18175 descriptor_write.descriptorCount = 1;
18176 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18177 descriptor_write.pTexelBufferView = &buffer_view;
18178
18179 // Set pImageInfo and pBufferInfo to invalid values, which should be
18180 // ignored for descriptorType ==
18181 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18182 // This will most likely produce a crash if the parameter_validation
18183 // layer
18184 // does not correctly ignore pImageInfo and pBufferInfo.
18185 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18186 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18187
18188 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18189
18190 m_errorMonitor->VerifyNotFound();
18191
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18193 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18194 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18195 vkDestroyBuffer(m_device->device(), buffer, NULL);
18196 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18197 }
18198}
18199
Tobin Ehlisf7428442016-10-25 07:58:24 -060018200TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18201 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18202
18203 ASSERT_NO_FATAL_FAILURE(InitState());
18204 // Create layout where two binding #s are "1"
18205 static const uint32_t NUM_BINDINGS = 3;
18206 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18207 dsl_binding[0].binding = 1;
18208 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18209 dsl_binding[0].descriptorCount = 1;
18210 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18211 dsl_binding[0].pImmutableSamplers = NULL;
18212 dsl_binding[1].binding = 0;
18213 dsl_binding[1].descriptorCount = 1;
18214 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18215 dsl_binding[1].descriptorCount = 1;
18216 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18217 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018218 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018219 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18220 dsl_binding[2].descriptorCount = 1;
18221 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18222 dsl_binding[2].pImmutableSamplers = NULL;
18223
18224 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18225 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18226 ds_layout_ci.pNext = NULL;
18227 ds_layout_ci.bindingCount = NUM_BINDINGS;
18228 ds_layout_ci.pBindings = dsl_binding;
18229 VkDescriptorSetLayout ds_layout;
18230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18231 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18232 m_errorMonitor->VerifyFound();
18233}
18234
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018235TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018236 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18237
18238 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018239
Tony Barbour552f6c02016-12-21 14:34:07 -070018240 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018241
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018242 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18243
18244 {
18245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18246 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18247 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18248 m_errorMonitor->VerifyFound();
18249 }
18250
18251 {
18252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18253 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18254 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18255 m_errorMonitor->VerifyFound();
18256 }
18257
18258 {
18259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18260 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18261 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18262 m_errorMonitor->VerifyFound();
18263 }
18264
18265 {
18266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18267 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18268 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18269 m_errorMonitor->VerifyFound();
18270 }
18271
18272 {
18273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18274 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18275 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18276 m_errorMonitor->VerifyFound();
18277 }
18278
18279 {
18280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18281 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18282 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18283 m_errorMonitor->VerifyFound();
18284 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018285
18286 {
18287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18288 VkRect2D scissor = {{-1, 0}, {16, 16}};
18289 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18290 m_errorMonitor->VerifyFound();
18291 }
18292
18293 {
18294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18295 VkRect2D scissor = {{0, -2}, {16, 16}};
18296 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18297 m_errorMonitor->VerifyFound();
18298 }
18299
18300 {
18301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18302 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18303 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18304 m_errorMonitor->VerifyFound();
18305 }
18306
18307 {
18308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18309 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18310 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18311 m_errorMonitor->VerifyFound();
18312 }
18313
Tony Barbour552f6c02016-12-21 14:34:07 -070018314 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018315}
18316
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018317// This is a positive test. No failures are expected.
18318TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18319 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18320 VkResult err;
18321
18322 ASSERT_NO_FATAL_FAILURE(InitState());
18323 m_errorMonitor->ExpectSuccess();
18324 VkDescriptorPoolSize ds_type_count = {};
18325 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18326 ds_type_count.descriptorCount = 2;
18327
18328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18330 ds_pool_ci.pNext = NULL;
18331 ds_pool_ci.maxSets = 1;
18332 ds_pool_ci.poolSizeCount = 1;
18333 ds_pool_ci.pPoolSizes = &ds_type_count;
18334
18335 VkDescriptorPool ds_pool;
18336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18337 ASSERT_VK_SUCCESS(err);
18338
18339 // Create layout with two uniform buffer descriptors w/ empty binding between them
18340 static const uint32_t NUM_BINDINGS = 3;
18341 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18342 dsl_binding[0].binding = 0;
18343 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18344 dsl_binding[0].descriptorCount = 1;
18345 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18346 dsl_binding[0].pImmutableSamplers = NULL;
18347 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018348 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018349 dsl_binding[2].binding = 2;
18350 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18351 dsl_binding[2].descriptorCount = 1;
18352 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18353 dsl_binding[2].pImmutableSamplers = NULL;
18354
18355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18357 ds_layout_ci.pNext = NULL;
18358 ds_layout_ci.bindingCount = NUM_BINDINGS;
18359 ds_layout_ci.pBindings = dsl_binding;
18360 VkDescriptorSetLayout ds_layout;
18361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18362 ASSERT_VK_SUCCESS(err);
18363
18364 VkDescriptorSet descriptor_set = {};
18365 VkDescriptorSetAllocateInfo alloc_info = {};
18366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18367 alloc_info.descriptorSetCount = 1;
18368 alloc_info.descriptorPool = ds_pool;
18369 alloc_info.pSetLayouts = &ds_layout;
18370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18371 ASSERT_VK_SUCCESS(err);
18372
18373 // Create a buffer to be used for update
18374 VkBufferCreateInfo buff_ci = {};
18375 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18376 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18377 buff_ci.size = 256;
18378 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18379 VkBuffer buffer;
18380 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18381 ASSERT_VK_SUCCESS(err);
18382 // Have to bind memory to buffer before descriptor update
18383 VkMemoryAllocateInfo mem_alloc = {};
18384 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18385 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018386 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018387 mem_alloc.memoryTypeIndex = 0;
18388
18389 VkMemoryRequirements mem_reqs;
18390 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18391 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18392 if (!pass) {
18393 vkDestroyBuffer(m_device->device(), buffer, NULL);
18394 return;
18395 }
18396
18397 VkDeviceMemory mem;
18398 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18399 ASSERT_VK_SUCCESS(err);
18400 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18401 ASSERT_VK_SUCCESS(err);
18402
18403 // Only update the descriptor at binding 2
18404 VkDescriptorBufferInfo buff_info = {};
18405 buff_info.buffer = buffer;
18406 buff_info.offset = 0;
18407 buff_info.range = VK_WHOLE_SIZE;
18408 VkWriteDescriptorSet descriptor_write = {};
18409 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18410 descriptor_write.dstBinding = 2;
18411 descriptor_write.descriptorCount = 1;
18412 descriptor_write.pTexelBufferView = nullptr;
18413 descriptor_write.pBufferInfo = &buff_info;
18414 descriptor_write.pImageInfo = nullptr;
18415 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18416 descriptor_write.dstSet = descriptor_set;
18417
18418 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18419
18420 m_errorMonitor->VerifyNotFound();
18421 // Cleanup
18422 vkFreeMemory(m_device->device(), mem, NULL);
18423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18424 vkDestroyBuffer(m_device->device(), buffer, NULL);
18425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18426}
18427
18428// This is a positive test. No failures are expected.
18429TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18430 VkResult err;
18431 bool pass;
18432
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018433 TEST_DESCRIPTION(
18434 "Create a buffer, allocate memory, bind memory, destroy "
18435 "the buffer, create an image, and bind the same memory to "
18436 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018437
18438 m_errorMonitor->ExpectSuccess();
18439
18440 ASSERT_NO_FATAL_FAILURE(InitState());
18441
18442 VkBuffer buffer;
18443 VkImage image;
18444 VkDeviceMemory mem;
18445 VkMemoryRequirements mem_reqs;
18446
18447 VkBufferCreateInfo buf_info = {};
18448 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18449 buf_info.pNext = NULL;
18450 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18451 buf_info.size = 256;
18452 buf_info.queueFamilyIndexCount = 0;
18453 buf_info.pQueueFamilyIndices = NULL;
18454 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18455 buf_info.flags = 0;
18456 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18457 ASSERT_VK_SUCCESS(err);
18458
18459 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18460
18461 VkMemoryAllocateInfo alloc_info = {};
18462 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18463 alloc_info.pNext = NULL;
18464 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018465
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018466 // Ensure memory is big enough for both bindings
18467 alloc_info.allocationSize = 0x10000;
18468
18469 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18470 if (!pass) {
18471 vkDestroyBuffer(m_device->device(), buffer, NULL);
18472 return;
18473 }
18474
18475 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18476 ASSERT_VK_SUCCESS(err);
18477
18478 uint8_t *pData;
18479 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18480 ASSERT_VK_SUCCESS(err);
18481
18482 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18483
18484 vkUnmapMemory(m_device->device(), mem);
18485
18486 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18487 ASSERT_VK_SUCCESS(err);
18488
18489 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18490 // memory. In fact, it was never used by the GPU.
18491 // Just be be sure, wait for idle.
18492 vkDestroyBuffer(m_device->device(), buffer, NULL);
18493 vkDeviceWaitIdle(m_device->device());
18494
Tobin Ehlis6a005702016-12-28 15:25:56 -070018495 // Use optimal as some platforms report linear support but then fail image creation
18496 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18497 VkImageFormatProperties image_format_properties;
18498 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18499 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18500 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018501 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018502 vkFreeMemory(m_device->device(), mem, NULL);
18503 return;
18504 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018505 VkImageCreateInfo image_create_info = {};
18506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18507 image_create_info.pNext = NULL;
18508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18509 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18510 image_create_info.extent.width = 64;
18511 image_create_info.extent.height = 64;
18512 image_create_info.extent.depth = 1;
18513 image_create_info.mipLevels = 1;
18514 image_create_info.arrayLayers = 1;
18515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018516 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018517 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18518 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18519 image_create_info.queueFamilyIndexCount = 0;
18520 image_create_info.pQueueFamilyIndices = NULL;
18521 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18522 image_create_info.flags = 0;
18523
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018524 /* Create a mappable image. It will be the texture if linear images are ok
18525 * to be textures or it will be the staging image if they are not.
18526 */
18527 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18528 ASSERT_VK_SUCCESS(err);
18529
18530 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18531
Tobin Ehlis6a005702016-12-28 15:25:56 -070018532 VkMemoryAllocateInfo mem_alloc = {};
18533 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18534 mem_alloc.pNext = NULL;
18535 mem_alloc.allocationSize = 0;
18536 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018537 mem_alloc.allocationSize = mem_reqs.size;
18538
18539 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18540 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018541 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018542 vkDestroyImage(m_device->device(), image, NULL);
18543 return;
18544 }
18545
18546 // VALIDATION FAILURE:
18547 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18548 ASSERT_VK_SUCCESS(err);
18549
18550 m_errorMonitor->VerifyNotFound();
18551
18552 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018553 vkDestroyImage(m_device->device(), image, NULL);
18554}
18555
Tony Barbourab713912017-02-02 14:17:35 -070018556// This is a positive test. No failures are expected.
18557TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18558 VkResult err;
18559
18560 TEST_DESCRIPTION(
18561 "Call all applicable destroy and free routines with NULL"
18562 "handles, expecting no validation errors");
18563
18564 m_errorMonitor->ExpectSuccess();
18565
18566 ASSERT_NO_FATAL_FAILURE(InitState());
18567 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18568 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18569 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18570 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18571 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18572 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18573 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18574 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18575 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18576 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18577 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18578 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18579 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18580 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18581 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18582 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18583 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18584 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18585 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18586 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18587
18588 VkCommandPool command_pool;
18589 VkCommandPoolCreateInfo pool_create_info{};
18590 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18591 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18592 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18593 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18594 VkCommandBuffer command_buffers[3] = {};
18595 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18596 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18597 command_buffer_allocate_info.commandPool = command_pool;
18598 command_buffer_allocate_info.commandBufferCount = 1;
18599 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18600 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18601 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18602 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18603
18604 VkDescriptorPoolSize ds_type_count = {};
18605 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18606 ds_type_count.descriptorCount = 1;
18607
18608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18610 ds_pool_ci.pNext = NULL;
18611 ds_pool_ci.maxSets = 1;
18612 ds_pool_ci.poolSizeCount = 1;
18613 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18614 ds_pool_ci.pPoolSizes = &ds_type_count;
18615
18616 VkDescriptorPool ds_pool;
18617 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18618 ASSERT_VK_SUCCESS(err);
18619
18620 VkDescriptorSetLayoutBinding dsl_binding = {};
18621 dsl_binding.binding = 2;
18622 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18623 dsl_binding.descriptorCount = 1;
18624 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18625 dsl_binding.pImmutableSamplers = NULL;
18626 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18627 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18628 ds_layout_ci.pNext = NULL;
18629 ds_layout_ci.bindingCount = 1;
18630 ds_layout_ci.pBindings = &dsl_binding;
18631 VkDescriptorSetLayout ds_layout;
18632 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18633 ASSERT_VK_SUCCESS(err);
18634
18635 VkDescriptorSet descriptor_sets[3] = {};
18636 VkDescriptorSetAllocateInfo alloc_info = {};
18637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18638 alloc_info.descriptorSetCount = 1;
18639 alloc_info.descriptorPool = ds_pool;
18640 alloc_info.pSetLayouts = &ds_layout;
18641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18642 ASSERT_VK_SUCCESS(err);
18643 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18646
18647 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18648
18649 m_errorMonitor->VerifyNotFound();
18650}
18651
Tony Barbour626994c2017-02-08 15:29:37 -070018652TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018653 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018654
18655 m_errorMonitor->ExpectSuccess();
18656
18657 ASSERT_NO_FATAL_FAILURE(InitState());
18658 VkCommandBuffer cmd_bufs[4];
18659 VkCommandBufferAllocateInfo alloc_info;
18660 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18661 alloc_info.pNext = NULL;
18662 alloc_info.commandBufferCount = 4;
18663 alloc_info.commandPool = m_commandPool;
18664 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18665 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18666 VkImageObj image(m_device);
18667 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18668 ASSERT_TRUE(image.initialized());
18669 VkCommandBufferBeginInfo cb_binfo;
18670 cb_binfo.pNext = NULL;
18671 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18672 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18673 cb_binfo.flags = 0;
18674 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18675 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18676 VkImageMemoryBarrier img_barrier = {};
18677 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18678 img_barrier.pNext = NULL;
18679 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18680 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18681 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18682 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18683 img_barrier.image = image.handle();
18684 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18685 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18686 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18687 img_barrier.subresourceRange.baseArrayLayer = 0;
18688 img_barrier.subresourceRange.baseMipLevel = 0;
18689 img_barrier.subresourceRange.layerCount = 1;
18690 img_barrier.subresourceRange.levelCount = 1;
18691 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18692 &img_barrier);
18693 vkEndCommandBuffer(cmd_bufs[0]);
18694 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18695 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18696 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18697 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18698 &img_barrier);
18699 vkEndCommandBuffer(cmd_bufs[1]);
18700 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18701 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18702 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18703 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18704 &img_barrier);
18705 vkEndCommandBuffer(cmd_bufs[2]);
18706 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18707 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18708 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18709 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18710 &img_barrier);
18711 vkEndCommandBuffer(cmd_bufs[3]);
18712
18713 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18714 VkSemaphore semaphore1, semaphore2;
18715 VkSemaphoreCreateInfo semaphore_create_info{};
18716 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18717 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18718 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18719 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18720 VkSubmitInfo submit_info[3];
18721 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18722 submit_info[0].pNext = nullptr;
18723 submit_info[0].commandBufferCount = 1;
18724 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18725 submit_info[0].signalSemaphoreCount = 1;
18726 submit_info[0].pSignalSemaphores = &semaphore1;
18727 submit_info[0].waitSemaphoreCount = 0;
18728 submit_info[0].pWaitDstStageMask = nullptr;
18729 submit_info[0].pWaitDstStageMask = flags;
18730 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18731 submit_info[1].pNext = nullptr;
18732 submit_info[1].commandBufferCount = 1;
18733 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18734 submit_info[1].waitSemaphoreCount = 1;
18735 submit_info[1].pWaitSemaphores = &semaphore1;
18736 submit_info[1].signalSemaphoreCount = 1;
18737 submit_info[1].pSignalSemaphores = &semaphore2;
18738 submit_info[1].pWaitDstStageMask = flags;
18739 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18740 submit_info[2].pNext = nullptr;
18741 submit_info[2].commandBufferCount = 2;
18742 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18743 submit_info[2].waitSemaphoreCount = 1;
18744 submit_info[2].pWaitSemaphores = &semaphore2;
18745 submit_info[2].signalSemaphoreCount = 0;
18746 submit_info[2].pSignalSemaphores = nullptr;
18747 submit_info[2].pWaitDstStageMask = flags;
18748 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18749 vkQueueWaitIdle(m_device->m_queue);
18750
18751 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18752 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18753 m_errorMonitor->VerifyNotFound();
18754}
18755
Tobin Ehlis953e8392016-11-17 10:54:13 -070018756TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18757 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18758 // We previously had a bug where dynamic offset of inactive bindings was still being used
18759 VkResult err;
18760 m_errorMonitor->ExpectSuccess();
18761
18762 ASSERT_NO_FATAL_FAILURE(InitState());
18763 ASSERT_NO_FATAL_FAILURE(InitViewport());
18764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18765
18766 VkDescriptorPoolSize ds_type_count = {};
18767 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18768 ds_type_count.descriptorCount = 3;
18769
18770 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18771 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18772 ds_pool_ci.pNext = NULL;
18773 ds_pool_ci.maxSets = 1;
18774 ds_pool_ci.poolSizeCount = 1;
18775 ds_pool_ci.pPoolSizes = &ds_type_count;
18776
18777 VkDescriptorPool ds_pool;
18778 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18779 ASSERT_VK_SUCCESS(err);
18780
18781 const uint32_t BINDING_COUNT = 3;
18782 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018783 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018784 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18785 dsl_binding[0].descriptorCount = 1;
18786 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18787 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018788 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018789 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18790 dsl_binding[1].descriptorCount = 1;
18791 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18792 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018793 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018794 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18795 dsl_binding[2].descriptorCount = 1;
18796 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18797 dsl_binding[2].pImmutableSamplers = NULL;
18798
18799 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18800 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18801 ds_layout_ci.pNext = NULL;
18802 ds_layout_ci.bindingCount = BINDING_COUNT;
18803 ds_layout_ci.pBindings = dsl_binding;
18804 VkDescriptorSetLayout ds_layout;
18805 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18806 ASSERT_VK_SUCCESS(err);
18807
18808 VkDescriptorSet descriptor_set;
18809 VkDescriptorSetAllocateInfo alloc_info = {};
18810 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18811 alloc_info.descriptorSetCount = 1;
18812 alloc_info.descriptorPool = ds_pool;
18813 alloc_info.pSetLayouts = &ds_layout;
18814 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18815 ASSERT_VK_SUCCESS(err);
18816
18817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18819 pipeline_layout_ci.pNext = NULL;
18820 pipeline_layout_ci.setLayoutCount = 1;
18821 pipeline_layout_ci.pSetLayouts = &ds_layout;
18822
18823 VkPipelineLayout pipeline_layout;
18824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18825 ASSERT_VK_SUCCESS(err);
18826
18827 // Create two buffers to update the descriptors with
18828 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18829 uint32_t qfi = 0;
18830 VkBufferCreateInfo buffCI = {};
18831 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18832 buffCI.size = 2048;
18833 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18834 buffCI.queueFamilyIndexCount = 1;
18835 buffCI.pQueueFamilyIndices = &qfi;
18836
18837 VkBuffer dyub1;
18838 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18839 ASSERT_VK_SUCCESS(err);
18840 // buffer2
18841 buffCI.size = 1024;
18842 VkBuffer dyub2;
18843 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18844 ASSERT_VK_SUCCESS(err);
18845 // Allocate memory and bind to buffers
18846 VkMemoryAllocateInfo mem_alloc[2] = {};
18847 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18848 mem_alloc[0].pNext = NULL;
18849 mem_alloc[0].memoryTypeIndex = 0;
18850 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18851 mem_alloc[1].pNext = NULL;
18852 mem_alloc[1].memoryTypeIndex = 0;
18853
18854 VkMemoryRequirements mem_reqs1;
18855 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18856 VkMemoryRequirements mem_reqs2;
18857 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18858 mem_alloc[0].allocationSize = mem_reqs1.size;
18859 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18860 mem_alloc[1].allocationSize = mem_reqs2.size;
18861 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18862 if (!pass) {
18863 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18864 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18865 return;
18866 }
18867
18868 VkDeviceMemory mem1;
18869 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18870 ASSERT_VK_SUCCESS(err);
18871 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18872 ASSERT_VK_SUCCESS(err);
18873 VkDeviceMemory mem2;
18874 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18875 ASSERT_VK_SUCCESS(err);
18876 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18877 ASSERT_VK_SUCCESS(err);
18878 // Update descriptors
18879 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18880 buff_info[0].buffer = dyub1;
18881 buff_info[0].offset = 0;
18882 buff_info[0].range = 256;
18883 buff_info[1].buffer = dyub1;
18884 buff_info[1].offset = 256;
18885 buff_info[1].range = 512;
18886 buff_info[2].buffer = dyub2;
18887 buff_info[2].offset = 0;
18888 buff_info[2].range = 512;
18889
18890 VkWriteDescriptorSet descriptor_write;
18891 memset(&descriptor_write, 0, sizeof(descriptor_write));
18892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18893 descriptor_write.dstSet = descriptor_set;
18894 descriptor_write.dstBinding = 0;
18895 descriptor_write.descriptorCount = BINDING_COUNT;
18896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18897 descriptor_write.pBufferInfo = buff_info;
18898
18899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18900
Tony Barbour552f6c02016-12-21 14:34:07 -070018901 m_commandBuffer->BeginCommandBuffer();
18902 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018903
18904 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018905 char const *vsSource =
18906 "#version 450\n"
18907 "\n"
18908 "out gl_PerVertex { \n"
18909 " vec4 gl_Position;\n"
18910 "};\n"
18911 "void main(){\n"
18912 " gl_Position = vec4(1);\n"
18913 "}\n";
18914 char const *fsSource =
18915 "#version 450\n"
18916 "\n"
18917 "layout(location=0) out vec4 x;\n"
18918 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18919 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18920 "void main(){\n"
18921 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18922 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18925 VkPipelineObj pipe(m_device);
18926 pipe.SetViewport(m_viewports);
18927 pipe.SetScissor(m_scissors);
18928 pipe.AddShader(&vs);
18929 pipe.AddShader(&fs);
18930 pipe.AddColorAttachment();
18931 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18932
18933 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18934 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18935 // we used to have a bug in this case.
18936 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18937 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18938 &descriptor_set, BINDING_COUNT, dyn_off);
18939 Draw(1, 0, 0, 0);
18940 m_errorMonitor->VerifyNotFound();
18941
18942 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18943 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18944 vkFreeMemory(m_device->device(), mem1, NULL);
18945 vkFreeMemory(m_device->device(), mem2, NULL);
18946
18947 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18949 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18950}
18951
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018952TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018953 TEST_DESCRIPTION(
18954 "Ensure that validations handling of non-coherent memory "
18955 "mapping while using VK_WHOLE_SIZE does not cause access "
18956 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018957 VkResult err;
18958 uint8_t *pData;
18959 ASSERT_NO_FATAL_FAILURE(InitState());
18960
18961 VkDeviceMemory mem;
18962 VkMemoryRequirements mem_reqs;
18963 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018964 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018965 VkMemoryAllocateInfo alloc_info = {};
18966 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18967 alloc_info.pNext = NULL;
18968 alloc_info.memoryTypeIndex = 0;
18969
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018970 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018971 alloc_info.allocationSize = allocation_size;
18972
18973 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18974 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 -070018975 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018976 if (!pass) {
18977 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018978 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18979 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018980 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018981 pass = m_device->phy().set_memory_type(
18982 mem_reqs.memoryTypeBits, &alloc_info,
18983 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18984 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018985 if (!pass) {
18986 return;
18987 }
18988 }
18989 }
18990
18991 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18992 ASSERT_VK_SUCCESS(err);
18993
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018994 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018995 m_errorMonitor->ExpectSuccess();
18996 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18997 ASSERT_VK_SUCCESS(err);
18998 VkMappedMemoryRange mmr = {};
18999 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19000 mmr.memory = mem;
19001 mmr.offset = 0;
19002 mmr.size = VK_WHOLE_SIZE;
19003 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19004 ASSERT_VK_SUCCESS(err);
19005 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19006 ASSERT_VK_SUCCESS(err);
19007 m_errorMonitor->VerifyNotFound();
19008 vkUnmapMemory(m_device->device(), mem);
19009
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019010 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019011 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019012 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019013 ASSERT_VK_SUCCESS(err);
19014 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19015 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019016 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019017 mmr.size = VK_WHOLE_SIZE;
19018 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19019 ASSERT_VK_SUCCESS(err);
19020 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19021 ASSERT_VK_SUCCESS(err);
19022 m_errorMonitor->VerifyNotFound();
19023 vkUnmapMemory(m_device->device(), mem);
19024
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019025 // Map with offset and size
19026 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019027 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019028 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019029 ASSERT_VK_SUCCESS(err);
19030 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19031 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019032 mmr.offset = 4 * atom_size;
19033 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019034 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19035 ASSERT_VK_SUCCESS(err);
19036 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19037 ASSERT_VK_SUCCESS(err);
19038 m_errorMonitor->VerifyNotFound();
19039 vkUnmapMemory(m_device->device(), mem);
19040
19041 // Map without offset and flush WHOLE_SIZE with two separate offsets
19042 m_errorMonitor->ExpectSuccess();
19043 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19044 ASSERT_VK_SUCCESS(err);
19045 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19046 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019047 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019048 mmr.size = VK_WHOLE_SIZE;
19049 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19050 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019051 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019052 mmr.size = VK_WHOLE_SIZE;
19053 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19054 ASSERT_VK_SUCCESS(err);
19055 m_errorMonitor->VerifyNotFound();
19056 vkUnmapMemory(m_device->device(), mem);
19057
19058 vkFreeMemory(m_device->device(), mem, NULL);
19059}
19060
19061// This is a positive test. We used to expect error in this case but spec now allows it
19062TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19063 m_errorMonitor->ExpectSuccess();
19064 vk_testing::Fence testFence;
19065 VkFenceCreateInfo fenceInfo = {};
19066 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19067 fenceInfo.pNext = NULL;
19068
19069 ASSERT_NO_FATAL_FAILURE(InitState());
19070 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019071 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019072 VkResult result = vkResetFences(m_device->device(), 1, fences);
19073 ASSERT_VK_SUCCESS(result);
19074
19075 m_errorMonitor->VerifyNotFound();
19076}
19077
19078TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19079 m_errorMonitor->ExpectSuccess();
19080
19081 ASSERT_NO_FATAL_FAILURE(InitState());
19082 VkResult err;
19083
19084 // Record (empty!) command buffer that can be submitted multiple times
19085 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019086 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19087 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019088 m_commandBuffer->BeginCommandBuffer(&cbbi);
19089 m_commandBuffer->EndCommandBuffer();
19090
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019091 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019092 VkFence fence;
19093 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19094 ASSERT_VK_SUCCESS(err);
19095
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019096 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019097 VkSemaphore s1, s2;
19098 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19099 ASSERT_VK_SUCCESS(err);
19100 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19101 ASSERT_VK_SUCCESS(err);
19102
19103 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019104 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019105 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19106 ASSERT_VK_SUCCESS(err);
19107
19108 // Submit CB again, signaling s2.
19109 si.pSignalSemaphores = &s2;
19110 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19111 ASSERT_VK_SUCCESS(err);
19112
19113 // Wait for fence.
19114 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19115 ASSERT_VK_SUCCESS(err);
19116
19117 // CB is still in flight from second submission, but semaphore s1 is no
19118 // longer in flight. delete it.
19119 vkDestroySemaphore(m_device->device(), s1, nullptr);
19120
19121 m_errorMonitor->VerifyNotFound();
19122
19123 // Force device idle and clean up remaining objects
19124 vkDeviceWaitIdle(m_device->device());
19125 vkDestroySemaphore(m_device->device(), s2, nullptr);
19126 vkDestroyFence(m_device->device(), fence, nullptr);
19127}
19128
19129TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19130 m_errorMonitor->ExpectSuccess();
19131
19132 ASSERT_NO_FATAL_FAILURE(InitState());
19133 VkResult err;
19134
19135 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019136 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019137 VkFence f1;
19138 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19139 ASSERT_VK_SUCCESS(err);
19140
19141 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019142 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019143 VkFence f2;
19144 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19145 ASSERT_VK_SUCCESS(err);
19146
19147 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019148 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019149 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19150
19151 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019152 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019153 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19154
19155 // Should have both retired!
19156 vkDestroyFence(m_device->device(), f1, nullptr);
19157 vkDestroyFence(m_device->device(), f2, nullptr);
19158
19159 m_errorMonitor->VerifyNotFound();
19160}
19161
19162TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019163 TEST_DESCRIPTION(
19164 "Verify that creating an image view from an image with valid usage "
19165 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019166
19167 ASSERT_NO_FATAL_FAILURE(InitState());
19168
19169 m_errorMonitor->ExpectSuccess();
19170 // Verify that we can create a view with usage INPUT_ATTACHMENT
19171 VkImageObj image(m_device);
19172 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19173 ASSERT_TRUE(image.initialized());
19174 VkImageView imageView;
19175 VkImageViewCreateInfo ivci = {};
19176 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19177 ivci.image = image.handle();
19178 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19179 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19180 ivci.subresourceRange.layerCount = 1;
19181 ivci.subresourceRange.baseMipLevel = 0;
19182 ivci.subresourceRange.levelCount = 1;
19183 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19184
19185 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19186 m_errorMonitor->VerifyNotFound();
19187 vkDestroyImageView(m_device->device(), imageView, NULL);
19188}
19189
19190// This is a positive test. No failures are expected.
19191TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019192 TEST_DESCRIPTION(
19193 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19194 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019195
19196 ASSERT_NO_FATAL_FAILURE(InitState());
19197
19198 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019199 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019200
19201 m_errorMonitor->ExpectSuccess();
19202
19203 VkImage image;
19204 VkImageCreateInfo image_create_info = {};
19205 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19206 image_create_info.pNext = NULL;
19207 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19208 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19209 image_create_info.extent.width = 64;
19210 image_create_info.extent.height = 64;
19211 image_create_info.extent.depth = 1;
19212 image_create_info.mipLevels = 1;
19213 image_create_info.arrayLayers = 1;
19214 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19215 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19216 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19217 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19218 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19219 ASSERT_VK_SUCCESS(err);
19220
19221 VkMemoryRequirements memory_reqs;
19222 VkDeviceMemory memory_one, memory_two;
19223 bool pass;
19224 VkMemoryAllocateInfo memory_info = {};
19225 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19226 memory_info.pNext = NULL;
19227 memory_info.allocationSize = 0;
19228 memory_info.memoryTypeIndex = 0;
19229 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19230 // Find an image big enough to allow sparse mapping of 2 memory regions
19231 // Increase the image size until it is at least twice the
19232 // size of the required alignment, to ensure we can bind both
19233 // allocated memory blocks to the image on aligned offsets.
19234 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19235 vkDestroyImage(m_device->device(), image, nullptr);
19236 image_create_info.extent.width *= 2;
19237 image_create_info.extent.height *= 2;
19238 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19239 ASSERT_VK_SUCCESS(err);
19240 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19241 }
19242 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19243 // at the end of the first
19244 memory_info.allocationSize = memory_reqs.alignment;
19245 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19246 ASSERT_TRUE(pass);
19247 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19248 ASSERT_VK_SUCCESS(err);
19249 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19250 ASSERT_VK_SUCCESS(err);
19251 VkSparseMemoryBind binds[2];
19252 binds[0].flags = 0;
19253 binds[0].memory = memory_one;
19254 binds[0].memoryOffset = 0;
19255 binds[0].resourceOffset = 0;
19256 binds[0].size = memory_info.allocationSize;
19257 binds[1].flags = 0;
19258 binds[1].memory = memory_two;
19259 binds[1].memoryOffset = 0;
19260 binds[1].resourceOffset = memory_info.allocationSize;
19261 binds[1].size = memory_info.allocationSize;
19262
19263 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19264 opaqueBindInfo.image = image;
19265 opaqueBindInfo.bindCount = 2;
19266 opaqueBindInfo.pBinds = binds;
19267
19268 VkFence fence = VK_NULL_HANDLE;
19269 VkBindSparseInfo bindSparseInfo = {};
19270 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19271 bindSparseInfo.imageOpaqueBindCount = 1;
19272 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19273
19274 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19275 vkQueueWaitIdle(m_device->m_queue);
19276 vkDestroyImage(m_device->device(), image, NULL);
19277 vkFreeMemory(m_device->device(), memory_one, NULL);
19278 vkFreeMemory(m_device->device(), memory_two, NULL);
19279 m_errorMonitor->VerifyNotFound();
19280}
19281
19282TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019283 TEST_DESCRIPTION(
19284 "Ensure that CmdBeginRenderPass with an attachment's "
19285 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19286 "the command buffer has prior knowledge of that "
19287 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019288
19289 m_errorMonitor->ExpectSuccess();
19290
19291 ASSERT_NO_FATAL_FAILURE(InitState());
19292
19293 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019294 VkAttachmentDescription attachment = {0,
19295 VK_FORMAT_R8G8B8A8_UNORM,
19296 VK_SAMPLE_COUNT_1_BIT,
19297 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19298 VK_ATTACHMENT_STORE_OP_STORE,
19299 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19300 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19301 VK_IMAGE_LAYOUT_UNDEFINED,
19302 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019303
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019304 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019305
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019306 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019308 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019309
19310 VkRenderPass rp;
19311 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19312 ASSERT_VK_SUCCESS(err);
19313
19314 // A compatible framebuffer.
19315 VkImageObj image(m_device);
19316 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19317 ASSERT_TRUE(image.initialized());
19318
19319 VkImageViewCreateInfo ivci = {
19320 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19321 nullptr,
19322 0,
19323 image.handle(),
19324 VK_IMAGE_VIEW_TYPE_2D,
19325 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019326 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19327 VK_COMPONENT_SWIZZLE_IDENTITY},
19328 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019329 };
19330 VkImageView view;
19331 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19332 ASSERT_VK_SUCCESS(err);
19333
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019334 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019335 VkFramebuffer fb;
19336 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19337 ASSERT_VK_SUCCESS(err);
19338
19339 // Record a single command buffer which uses this renderpass twice. The
19340 // bug is triggered at the beginning of the second renderpass, when the
19341 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019342 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 -070019343 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019344 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19345 vkCmdEndRenderPass(m_commandBuffer->handle());
19346 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19347
19348 m_errorMonitor->VerifyNotFound();
19349
19350 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019351 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019352
19353 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19354 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19355 vkDestroyImageView(m_device->device(), view, nullptr);
19356}
19357
19358TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019359 TEST_DESCRIPTION(
19360 "This test should pass. Create a Framebuffer and "
19361 "command buffer, bind them together, then destroy "
19362 "command pool and framebuffer and verify there are no "
19363 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019364
19365 m_errorMonitor->ExpectSuccess();
19366
19367 ASSERT_NO_FATAL_FAILURE(InitState());
19368
19369 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019370 VkAttachmentDescription attachment = {0,
19371 VK_FORMAT_R8G8B8A8_UNORM,
19372 VK_SAMPLE_COUNT_1_BIT,
19373 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19374 VK_ATTACHMENT_STORE_OP_STORE,
19375 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19376 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19377 VK_IMAGE_LAYOUT_UNDEFINED,
19378 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019379
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019380 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019381
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019382 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019383
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019384 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385
19386 VkRenderPass rp;
19387 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19388 ASSERT_VK_SUCCESS(err);
19389
19390 // A compatible framebuffer.
19391 VkImageObj image(m_device);
19392 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19393 ASSERT_TRUE(image.initialized());
19394
19395 VkImageViewCreateInfo ivci = {
19396 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19397 nullptr,
19398 0,
19399 image.handle(),
19400 VK_IMAGE_VIEW_TYPE_2D,
19401 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019402 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19403 VK_COMPONENT_SWIZZLE_IDENTITY},
19404 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019405 };
19406 VkImageView view;
19407 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19408 ASSERT_VK_SUCCESS(err);
19409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019410 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019411 VkFramebuffer fb;
19412 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19413 ASSERT_VK_SUCCESS(err);
19414
19415 // Explicitly create a command buffer to bind the FB to so that we can then
19416 // destroy the command pool in order to implicitly free command buffer
19417 VkCommandPool command_pool;
19418 VkCommandPoolCreateInfo pool_create_info{};
19419 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19420 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19421 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19422 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19423
19424 VkCommandBuffer command_buffer;
19425 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19426 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19427 command_buffer_allocate_info.commandPool = command_pool;
19428 command_buffer_allocate_info.commandBufferCount = 1;
19429 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19430 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19431
19432 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019433 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 -060019434 VkCommandBufferBeginInfo begin_info{};
19435 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19436 vkBeginCommandBuffer(command_buffer, &begin_info);
19437
19438 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19439 vkCmdEndRenderPass(command_buffer);
19440 vkEndCommandBuffer(command_buffer);
19441 vkDestroyImageView(m_device->device(), view, nullptr);
19442 // Destroy command pool to implicitly free command buffer
19443 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19444 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19445 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19446 m_errorMonitor->VerifyNotFound();
19447}
19448
19449TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019450 TEST_DESCRIPTION(
19451 "Ensure that CmdBeginRenderPass applies the layout "
19452 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019453
19454 m_errorMonitor->ExpectSuccess();
19455
19456 ASSERT_NO_FATAL_FAILURE(InitState());
19457
19458 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019459 VkAttachmentDescription attachment = {0,
19460 VK_FORMAT_R8G8B8A8_UNORM,
19461 VK_SAMPLE_COUNT_1_BIT,
19462 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19463 VK_ATTACHMENT_STORE_OP_STORE,
19464 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19465 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19466 VK_IMAGE_LAYOUT_UNDEFINED,
19467 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019469 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019470
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019471 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019472
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019473 VkSubpassDependency dep = {0,
19474 0,
19475 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19476 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19477 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19478 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19479 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019480
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019481 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019482
19483 VkResult err;
19484 VkRenderPass rp;
19485 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19486 ASSERT_VK_SUCCESS(err);
19487
19488 // A compatible framebuffer.
19489 VkImageObj image(m_device);
19490 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19491 ASSERT_TRUE(image.initialized());
19492
19493 VkImageViewCreateInfo ivci = {
19494 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19495 nullptr,
19496 0,
19497 image.handle(),
19498 VK_IMAGE_VIEW_TYPE_2D,
19499 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019500 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19501 VK_COMPONENT_SWIZZLE_IDENTITY},
19502 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019503 };
19504 VkImageView view;
19505 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19506 ASSERT_VK_SUCCESS(err);
19507
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019508 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019509 VkFramebuffer fb;
19510 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19511 ASSERT_VK_SUCCESS(err);
19512
19513 // Record a single command buffer which issues a pipeline barrier w/
19514 // image memory barrier for the attachment. This detects the previously
19515 // missing tracking of the subpass layout by throwing a validation error
19516 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019517 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 -070019518 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019519 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19520
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019521 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19522 nullptr,
19523 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19524 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19525 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19526 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19527 VK_QUEUE_FAMILY_IGNORED,
19528 VK_QUEUE_FAMILY_IGNORED,
19529 image.handle(),
19530 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019531 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019532 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19533 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019534
19535 vkCmdEndRenderPass(m_commandBuffer->handle());
19536 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019537 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019538
19539 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19540 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19541 vkDestroyImageView(m_device->device(), view, nullptr);
19542}
19543
19544TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019545 TEST_DESCRIPTION(
19546 "Validate that when an imageView of a depth/stencil image "
19547 "is used as a depth/stencil framebuffer attachment, the "
19548 "aspectMask is ignored and both depth and stencil image "
19549 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019550
19551 VkFormatProperties format_properties;
19552 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19553 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19554 return;
19555 }
19556
19557 m_errorMonitor->ExpectSuccess();
19558
19559 ASSERT_NO_FATAL_FAILURE(InitState());
19560
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019561 VkAttachmentDescription attachment = {0,
19562 VK_FORMAT_D32_SFLOAT_S8_UINT,
19563 VK_SAMPLE_COUNT_1_BIT,
19564 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19565 VK_ATTACHMENT_STORE_OP_STORE,
19566 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19567 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19568 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19569 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019570
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019571 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019572
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019573 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019574
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019575 VkSubpassDependency dep = {0,
19576 0,
19577 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19578 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19579 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19580 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19581 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019582
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019583 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019584
19585 VkResult err;
19586 VkRenderPass rp;
19587 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19588 ASSERT_VK_SUCCESS(err);
19589
19590 VkImageObj image(m_device);
19591 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019592 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019593 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019594 ASSERT_TRUE(image.initialized());
19595 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19596
19597 VkImageViewCreateInfo ivci = {
19598 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19599 nullptr,
19600 0,
19601 image.handle(),
19602 VK_IMAGE_VIEW_TYPE_2D,
19603 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019604 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19605 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019606 };
19607 VkImageView view;
19608 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19609 ASSERT_VK_SUCCESS(err);
19610
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019611 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019612 VkFramebuffer fb;
19613 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19614 ASSERT_VK_SUCCESS(err);
19615
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
19620 VkImageMemoryBarrier imb = {};
19621 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19622 imb.pNext = nullptr;
19623 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19624 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19625 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19626 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19627 imb.srcQueueFamilyIndex = 0;
19628 imb.dstQueueFamilyIndex = 0;
19629 imb.image = image.handle();
19630 imb.subresourceRange.aspectMask = 0x6;
19631 imb.subresourceRange.baseMipLevel = 0;
19632 imb.subresourceRange.levelCount = 0x1;
19633 imb.subresourceRange.baseArrayLayer = 0;
19634 imb.subresourceRange.layerCount = 0x1;
19635
19636 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019637 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19638 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019639
19640 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019641 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019642 QueueCommandBuffer(false);
19643 m_errorMonitor->VerifyNotFound();
19644
19645 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19646 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19647 vkDestroyImageView(m_device->device(), view, nullptr);
19648}
19649
19650TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019651 TEST_DESCRIPTION(
19652 "Ensure that layout transitions work correctly without "
19653 "errors, when an attachment reference is "
19654 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019655
19656 m_errorMonitor->ExpectSuccess();
19657
19658 ASSERT_NO_FATAL_FAILURE(InitState());
19659
19660 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019661 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019662
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019663 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019664
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019665 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019666
19667 VkRenderPass rp;
19668 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19669 ASSERT_VK_SUCCESS(err);
19670
19671 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019672 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019673 VkFramebuffer fb;
19674 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19675 ASSERT_VK_SUCCESS(err);
19676
19677 // Record a command buffer which just begins and ends the renderpass. The
19678 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019679 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 -070019680 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019681 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19682 vkCmdEndRenderPass(m_commandBuffer->handle());
19683 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019684 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019685
19686 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19687 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19688}
19689
19690// This is a positive test. No errors are expected.
19691TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019692 TEST_DESCRIPTION(
19693 "Create a stencil-only attachment with a LOAD_OP set to "
19694 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019695 VkResult result = VK_SUCCESS;
19696 VkImageFormatProperties formatProps;
19697 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019698 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19699 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019700 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19701 return;
19702 }
19703
19704 ASSERT_NO_FATAL_FAILURE(InitState());
19705 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19706 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019707 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019708 VkAttachmentDescription att = {};
19709 VkAttachmentReference ref = {};
19710 att.format = depth_stencil_fmt;
19711 att.samples = VK_SAMPLE_COUNT_1_BIT;
19712 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19713 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19714 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19715 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19716 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19717 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19718
19719 VkClearValue clear;
19720 clear.depthStencil.depth = 1.0;
19721 clear.depthStencil.stencil = 0;
19722 ref.attachment = 0;
19723 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19724
19725 VkSubpassDescription subpass = {};
19726 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19727 subpass.flags = 0;
19728 subpass.inputAttachmentCount = 0;
19729 subpass.pInputAttachments = NULL;
19730 subpass.colorAttachmentCount = 0;
19731 subpass.pColorAttachments = NULL;
19732 subpass.pResolveAttachments = NULL;
19733 subpass.pDepthStencilAttachment = &ref;
19734 subpass.preserveAttachmentCount = 0;
19735 subpass.pPreserveAttachments = NULL;
19736
19737 VkRenderPass rp;
19738 VkRenderPassCreateInfo rp_info = {};
19739 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19740 rp_info.attachmentCount = 1;
19741 rp_info.pAttachments = &att;
19742 rp_info.subpassCount = 1;
19743 rp_info.pSubpasses = &subpass;
19744 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19745 ASSERT_VK_SUCCESS(result);
19746
19747 VkImageView *depthView = m_depthStencil->BindInfo();
19748 VkFramebufferCreateInfo fb_info = {};
19749 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19750 fb_info.pNext = NULL;
19751 fb_info.renderPass = rp;
19752 fb_info.attachmentCount = 1;
19753 fb_info.pAttachments = depthView;
19754 fb_info.width = 100;
19755 fb_info.height = 100;
19756 fb_info.layers = 1;
19757 VkFramebuffer fb;
19758 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19759 ASSERT_VK_SUCCESS(result);
19760
19761 VkRenderPassBeginInfo rpbinfo = {};
19762 rpbinfo.clearValueCount = 1;
19763 rpbinfo.pClearValues = &clear;
19764 rpbinfo.pNext = NULL;
19765 rpbinfo.renderPass = rp;
19766 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19767 rpbinfo.renderArea.extent.width = 100;
19768 rpbinfo.renderArea.extent.height = 100;
19769 rpbinfo.renderArea.offset.x = 0;
19770 rpbinfo.renderArea.offset.y = 0;
19771 rpbinfo.framebuffer = fb;
19772
19773 VkFence fence = {};
19774 VkFenceCreateInfo fence_ci = {};
19775 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19776 fence_ci.pNext = nullptr;
19777 fence_ci.flags = 0;
19778 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19779 ASSERT_VK_SUCCESS(result);
19780
19781 m_commandBuffer->BeginCommandBuffer();
19782 m_commandBuffer->BeginRenderPass(rpbinfo);
19783 m_commandBuffer->EndRenderPass();
19784 m_commandBuffer->EndCommandBuffer();
19785 m_commandBuffer->QueueCommandBuffer(fence);
19786
19787 VkImageObj destImage(m_device);
19788 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 -070019789 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019790 VkImageMemoryBarrier barrier = {};
19791 VkImageSubresourceRange range;
19792 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19793 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19794 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19795 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19796 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19797 barrier.image = m_depthStencil->handle();
19798 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19799 range.baseMipLevel = 0;
19800 range.levelCount = 1;
19801 range.baseArrayLayer = 0;
19802 range.layerCount = 1;
19803 barrier.subresourceRange = range;
19804 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19805 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19806 cmdbuf.BeginCommandBuffer();
19807 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 -070019808 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019809 barrier.srcAccessMask = 0;
19810 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19811 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19812 barrier.image = destImage.handle();
19813 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19814 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 -070019815 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019816 VkImageCopy cregion;
19817 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19818 cregion.srcSubresource.mipLevel = 0;
19819 cregion.srcSubresource.baseArrayLayer = 0;
19820 cregion.srcSubresource.layerCount = 1;
19821 cregion.srcOffset.x = 0;
19822 cregion.srcOffset.y = 0;
19823 cregion.srcOffset.z = 0;
19824 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19825 cregion.dstSubresource.mipLevel = 0;
19826 cregion.dstSubresource.baseArrayLayer = 0;
19827 cregion.dstSubresource.layerCount = 1;
19828 cregion.dstOffset.x = 0;
19829 cregion.dstOffset.y = 0;
19830 cregion.dstOffset.z = 0;
19831 cregion.extent.width = 100;
19832 cregion.extent.height = 100;
19833 cregion.extent.depth = 1;
19834 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019835 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019836 cmdbuf.EndCommandBuffer();
19837
19838 VkSubmitInfo submit_info;
19839 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19840 submit_info.pNext = NULL;
19841 submit_info.waitSemaphoreCount = 0;
19842 submit_info.pWaitSemaphores = NULL;
19843 submit_info.pWaitDstStageMask = NULL;
19844 submit_info.commandBufferCount = 1;
19845 submit_info.pCommandBuffers = &cmdbuf.handle();
19846 submit_info.signalSemaphoreCount = 0;
19847 submit_info.pSignalSemaphores = NULL;
19848
19849 m_errorMonitor->ExpectSuccess();
19850 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19851 m_errorMonitor->VerifyNotFound();
19852
19853 vkQueueWaitIdle(m_device->m_queue);
19854 vkDestroyFence(m_device->device(), fence, nullptr);
19855 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19856 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19857}
19858
19859// This is a positive test. No errors should be generated.
19860TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19861 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19862
19863 m_errorMonitor->ExpectSuccess();
19864 ASSERT_NO_FATAL_FAILURE(InitState());
19865
19866 VkEvent event;
19867 VkEventCreateInfo event_create_info{};
19868 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19869 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19870
19871 VkCommandPool command_pool;
19872 VkCommandPoolCreateInfo pool_create_info{};
19873 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19874 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19875 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19876 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19877
19878 VkCommandBuffer command_buffer;
19879 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19880 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19881 command_buffer_allocate_info.commandPool = command_pool;
19882 command_buffer_allocate_info.commandBufferCount = 1;
19883 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19884 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19885
19886 VkQueue queue = VK_NULL_HANDLE;
19887 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19888
19889 {
19890 VkCommandBufferBeginInfo begin_info{};
19891 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19892 vkBeginCommandBuffer(command_buffer, &begin_info);
19893
19894 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 -070019895 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019896 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19897 vkEndCommandBuffer(command_buffer);
19898 }
19899 {
19900 VkSubmitInfo submit_info{};
19901 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19902 submit_info.commandBufferCount = 1;
19903 submit_info.pCommandBuffers = &command_buffer;
19904 submit_info.signalSemaphoreCount = 0;
19905 submit_info.pSignalSemaphores = nullptr;
19906 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19907 }
19908 { vkSetEvent(m_device->device(), event); }
19909
19910 vkQueueWaitIdle(queue);
19911
19912 vkDestroyEvent(m_device->device(), event, nullptr);
19913 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19914 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19915
19916 m_errorMonitor->VerifyNotFound();
19917}
19918// This is a positive test. No errors should be generated.
19919TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19920 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19921
19922 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019923 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019924
19925 m_errorMonitor->ExpectSuccess();
19926
19927 VkQueryPool query_pool;
19928 VkQueryPoolCreateInfo query_pool_create_info{};
19929 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19930 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19931 query_pool_create_info.queryCount = 1;
19932 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19933
19934 VkCommandPool command_pool;
19935 VkCommandPoolCreateInfo pool_create_info{};
19936 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19937 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19938 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19939 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19940
19941 VkCommandBuffer command_buffer;
19942 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19943 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19944 command_buffer_allocate_info.commandPool = command_pool;
19945 command_buffer_allocate_info.commandBufferCount = 1;
19946 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19947 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19948
19949 VkCommandBuffer secondary_command_buffer;
19950 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19951 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19952
19953 VkQueue queue = VK_NULL_HANDLE;
19954 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19955
19956 uint32_t qfi = 0;
19957 VkBufferCreateInfo buff_create_info = {};
19958 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19959 buff_create_info.size = 1024;
19960 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19961 buff_create_info.queueFamilyIndexCount = 1;
19962 buff_create_info.pQueueFamilyIndices = &qfi;
19963
19964 VkResult err;
19965 VkBuffer buffer;
19966 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19967 ASSERT_VK_SUCCESS(err);
19968 VkMemoryAllocateInfo mem_alloc = {};
19969 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19970 mem_alloc.pNext = NULL;
19971 mem_alloc.allocationSize = 1024;
19972 mem_alloc.memoryTypeIndex = 0;
19973
19974 VkMemoryRequirements memReqs;
19975 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19976 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19977 if (!pass) {
19978 vkDestroyBuffer(m_device->device(), buffer, NULL);
19979 return;
19980 }
19981
19982 VkDeviceMemory mem;
19983 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19984 ASSERT_VK_SUCCESS(err);
19985 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19986 ASSERT_VK_SUCCESS(err);
19987
19988 VkCommandBufferInheritanceInfo hinfo = {};
19989 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19990 hinfo.renderPass = VK_NULL_HANDLE;
19991 hinfo.subpass = 0;
19992 hinfo.framebuffer = VK_NULL_HANDLE;
19993 hinfo.occlusionQueryEnable = VK_FALSE;
19994 hinfo.queryFlags = 0;
19995 hinfo.pipelineStatistics = 0;
19996
19997 {
19998 VkCommandBufferBeginInfo begin_info{};
19999 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20000 begin_info.pInheritanceInfo = &hinfo;
20001 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20002
20003 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20004 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20005
20006 vkEndCommandBuffer(secondary_command_buffer);
20007
20008 begin_info.pInheritanceInfo = nullptr;
20009 vkBeginCommandBuffer(command_buffer, &begin_info);
20010
20011 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20012 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20013
20014 vkEndCommandBuffer(command_buffer);
20015 }
20016 {
20017 VkSubmitInfo submit_info{};
20018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20019 submit_info.commandBufferCount = 1;
20020 submit_info.pCommandBuffers = &command_buffer;
20021 submit_info.signalSemaphoreCount = 0;
20022 submit_info.pSignalSemaphores = nullptr;
20023 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20024 }
20025
20026 vkQueueWaitIdle(queue);
20027
20028 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20029 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20030 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20031 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20032 vkDestroyBuffer(m_device->device(), buffer, NULL);
20033 vkFreeMemory(m_device->device(), mem, NULL);
20034
20035 m_errorMonitor->VerifyNotFound();
20036}
20037
20038// This is a positive test. No errors should be generated.
20039TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20040 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20041
20042 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020043 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020044
20045 m_errorMonitor->ExpectSuccess();
20046
20047 VkQueryPool query_pool;
20048 VkQueryPoolCreateInfo query_pool_create_info{};
20049 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20050 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20051 query_pool_create_info.queryCount = 1;
20052 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20053
20054 VkCommandPool command_pool;
20055 VkCommandPoolCreateInfo pool_create_info{};
20056 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20057 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20058 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20059 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20060
20061 VkCommandBuffer command_buffer[2];
20062 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20063 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20064 command_buffer_allocate_info.commandPool = command_pool;
20065 command_buffer_allocate_info.commandBufferCount = 2;
20066 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20067 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20068
20069 VkQueue queue = VK_NULL_HANDLE;
20070 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20071
20072 uint32_t qfi = 0;
20073 VkBufferCreateInfo buff_create_info = {};
20074 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20075 buff_create_info.size = 1024;
20076 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20077 buff_create_info.queueFamilyIndexCount = 1;
20078 buff_create_info.pQueueFamilyIndices = &qfi;
20079
20080 VkResult err;
20081 VkBuffer buffer;
20082 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20083 ASSERT_VK_SUCCESS(err);
20084 VkMemoryAllocateInfo mem_alloc = {};
20085 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20086 mem_alloc.pNext = NULL;
20087 mem_alloc.allocationSize = 1024;
20088 mem_alloc.memoryTypeIndex = 0;
20089
20090 VkMemoryRequirements memReqs;
20091 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20092 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20093 if (!pass) {
20094 vkDestroyBuffer(m_device->device(), buffer, NULL);
20095 return;
20096 }
20097
20098 VkDeviceMemory mem;
20099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20100 ASSERT_VK_SUCCESS(err);
20101 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20102 ASSERT_VK_SUCCESS(err);
20103
20104 {
20105 VkCommandBufferBeginInfo begin_info{};
20106 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20107 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20108
20109 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20110 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20111
20112 vkEndCommandBuffer(command_buffer[0]);
20113
20114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20115
20116 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20117
20118 vkEndCommandBuffer(command_buffer[1]);
20119 }
20120 {
20121 VkSubmitInfo submit_info{};
20122 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20123 submit_info.commandBufferCount = 2;
20124 submit_info.pCommandBuffers = command_buffer;
20125 submit_info.signalSemaphoreCount = 0;
20126 submit_info.pSignalSemaphores = nullptr;
20127 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20128 }
20129
20130 vkQueueWaitIdle(queue);
20131
20132 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20133 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20134 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20135 vkDestroyBuffer(m_device->device(), buffer, NULL);
20136 vkFreeMemory(m_device->device(), mem, NULL);
20137
20138 m_errorMonitor->VerifyNotFound();
20139}
20140
Tony Barbourc46924f2016-11-04 11:49:52 -060020141TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020142 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20143
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020144 ASSERT_NO_FATAL_FAILURE(InitState());
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 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020174 vkEndCommandBuffer(command_buffer);
20175 }
20176 {
20177 VkSubmitInfo submit_info{};
20178 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20179 submit_info.commandBufferCount = 1;
20180 submit_info.pCommandBuffers = &command_buffer;
20181 submit_info.signalSemaphoreCount = 0;
20182 submit_info.pSignalSemaphores = nullptr;
20183 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20184 }
20185 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20187 "that is already in use by a "
20188 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020189 vkSetEvent(m_device->device(), event);
20190 m_errorMonitor->VerifyFound();
20191 }
20192
20193 vkQueueWaitIdle(queue);
20194
20195 vkDestroyEvent(m_device->device(), event, nullptr);
20196 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20197 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20198}
20199
20200// This is a positive test. No errors should be generated.
20201TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020202 TEST_DESCRIPTION(
20203 "Two command buffers with two separate fences are each "
20204 "run through a Submit & WaitForFences cycle 3 times. This "
20205 "previously revealed a bug so running this positive test "
20206 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020207 m_errorMonitor->ExpectSuccess();
20208
20209 ASSERT_NO_FATAL_FAILURE(InitState());
20210 VkQueue queue = VK_NULL_HANDLE;
20211 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20212
20213 static const uint32_t NUM_OBJECTS = 2;
20214 static const uint32_t NUM_FRAMES = 3;
20215 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20216 VkFence fences[NUM_OBJECTS] = {};
20217
20218 VkCommandPool cmd_pool;
20219 VkCommandPoolCreateInfo cmd_pool_ci = {};
20220 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20221 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20222 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20223 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20224 ASSERT_VK_SUCCESS(err);
20225
20226 VkCommandBufferAllocateInfo cmd_buf_info = {};
20227 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20228 cmd_buf_info.commandPool = cmd_pool;
20229 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20230 cmd_buf_info.commandBufferCount = 1;
20231
20232 VkFenceCreateInfo fence_ci = {};
20233 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20234 fence_ci.pNext = nullptr;
20235 fence_ci.flags = 0;
20236
20237 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20238 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20239 ASSERT_VK_SUCCESS(err);
20240 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20241 ASSERT_VK_SUCCESS(err);
20242 }
20243
20244 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20245 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20246 // Create empty cmd buffer
20247 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20248 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20249
20250 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20251 ASSERT_VK_SUCCESS(err);
20252 err = vkEndCommandBuffer(cmd_buffers[obj]);
20253 ASSERT_VK_SUCCESS(err);
20254
20255 VkSubmitInfo submit_info = {};
20256 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20257 submit_info.commandBufferCount = 1;
20258 submit_info.pCommandBuffers = &cmd_buffers[obj];
20259 // Submit cmd buffer and wait for fence
20260 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20261 ASSERT_VK_SUCCESS(err);
20262 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20263 ASSERT_VK_SUCCESS(err);
20264 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20265 ASSERT_VK_SUCCESS(err);
20266 }
20267 }
20268 m_errorMonitor->VerifyNotFound();
20269 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20270 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20271 vkDestroyFence(m_device->device(), fences[i], nullptr);
20272 }
20273}
20274// This is a positive test. No errors should be generated.
20275TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020276 TEST_DESCRIPTION(
20277 "Two command buffers, each in a separate QueueSubmit call "
20278 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020279
20280 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020281 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020282
20283 m_errorMonitor->ExpectSuccess();
20284
20285 VkSemaphore semaphore;
20286 VkSemaphoreCreateInfo semaphore_create_info{};
20287 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20288 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20289
20290 VkCommandPool command_pool;
20291 VkCommandPoolCreateInfo pool_create_info{};
20292 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20293 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20294 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20295 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20296
20297 VkCommandBuffer command_buffer[2];
20298 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20299 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20300 command_buffer_allocate_info.commandPool = command_pool;
20301 command_buffer_allocate_info.commandBufferCount = 2;
20302 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20303 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20304
20305 VkQueue queue = VK_NULL_HANDLE;
20306 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20307
20308 {
20309 VkCommandBufferBeginInfo begin_info{};
20310 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20311 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20312
20313 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 -070020314 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020315
20316 VkViewport viewport{};
20317 viewport.maxDepth = 1.0f;
20318 viewport.minDepth = 0.0f;
20319 viewport.width = 512;
20320 viewport.height = 512;
20321 viewport.x = 0;
20322 viewport.y = 0;
20323 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20324 vkEndCommandBuffer(command_buffer[0]);
20325 }
20326 {
20327 VkCommandBufferBeginInfo begin_info{};
20328 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20329 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20330
20331 VkViewport viewport{};
20332 viewport.maxDepth = 1.0f;
20333 viewport.minDepth = 0.0f;
20334 viewport.width = 512;
20335 viewport.height = 512;
20336 viewport.x = 0;
20337 viewport.y = 0;
20338 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20339 vkEndCommandBuffer(command_buffer[1]);
20340 }
20341 {
20342 VkSubmitInfo submit_info{};
20343 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20344 submit_info.commandBufferCount = 1;
20345 submit_info.pCommandBuffers = &command_buffer[0];
20346 submit_info.signalSemaphoreCount = 1;
20347 submit_info.pSignalSemaphores = &semaphore;
20348 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20349 }
20350 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020351 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020352 VkSubmitInfo submit_info{};
20353 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20354 submit_info.commandBufferCount = 1;
20355 submit_info.pCommandBuffers = &command_buffer[1];
20356 submit_info.waitSemaphoreCount = 1;
20357 submit_info.pWaitSemaphores = &semaphore;
20358 submit_info.pWaitDstStageMask = flags;
20359 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20360 }
20361
20362 vkQueueWaitIdle(m_device->m_queue);
20363
20364 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20365 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20366 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20367
20368 m_errorMonitor->VerifyNotFound();
20369}
20370
20371// This is a positive test. No errors should be generated.
20372TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020373 TEST_DESCRIPTION(
20374 "Two command buffers, each in a separate QueueSubmit call "
20375 "submitted on separate queues, the second having a fence"
20376 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020377
20378 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020379 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020380
20381 m_errorMonitor->ExpectSuccess();
20382
20383 VkFence fence;
20384 VkFenceCreateInfo fence_create_info{};
20385 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20386 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20387
20388 VkSemaphore semaphore;
20389 VkSemaphoreCreateInfo semaphore_create_info{};
20390 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20391 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20392
20393 VkCommandPool command_pool;
20394 VkCommandPoolCreateInfo pool_create_info{};
20395 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20396 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20397 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20398 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20399
20400 VkCommandBuffer command_buffer[2];
20401 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20402 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20403 command_buffer_allocate_info.commandPool = command_pool;
20404 command_buffer_allocate_info.commandBufferCount = 2;
20405 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20406 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20407
20408 VkQueue queue = VK_NULL_HANDLE;
20409 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20410
20411 {
20412 VkCommandBufferBeginInfo begin_info{};
20413 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20414 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20415
20416 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 -070020417 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020418
20419 VkViewport viewport{};
20420 viewport.maxDepth = 1.0f;
20421 viewport.minDepth = 0.0f;
20422 viewport.width = 512;
20423 viewport.height = 512;
20424 viewport.x = 0;
20425 viewport.y = 0;
20426 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20427 vkEndCommandBuffer(command_buffer[0]);
20428 }
20429 {
20430 VkCommandBufferBeginInfo begin_info{};
20431 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20432 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20433
20434 VkViewport viewport{};
20435 viewport.maxDepth = 1.0f;
20436 viewport.minDepth = 0.0f;
20437 viewport.width = 512;
20438 viewport.height = 512;
20439 viewport.x = 0;
20440 viewport.y = 0;
20441 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20442 vkEndCommandBuffer(command_buffer[1]);
20443 }
20444 {
20445 VkSubmitInfo submit_info{};
20446 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20447 submit_info.commandBufferCount = 1;
20448 submit_info.pCommandBuffers = &command_buffer[0];
20449 submit_info.signalSemaphoreCount = 1;
20450 submit_info.pSignalSemaphores = &semaphore;
20451 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20452 }
20453 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020454 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020455 VkSubmitInfo submit_info{};
20456 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20457 submit_info.commandBufferCount = 1;
20458 submit_info.pCommandBuffers = &command_buffer[1];
20459 submit_info.waitSemaphoreCount = 1;
20460 submit_info.pWaitSemaphores = &semaphore;
20461 submit_info.pWaitDstStageMask = flags;
20462 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20463 }
20464
20465 vkQueueWaitIdle(m_device->m_queue);
20466
20467 vkDestroyFence(m_device->device(), fence, nullptr);
20468 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20469 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20470 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20471
20472 m_errorMonitor->VerifyNotFound();
20473}
20474
20475// This is a positive test. No errors should be generated.
20476TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020477 TEST_DESCRIPTION(
20478 "Two command buffers, each in a separate QueueSubmit call "
20479 "submitted on separate queues, the second having a fence"
20480 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020481
20482 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020483 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020484
20485 m_errorMonitor->ExpectSuccess();
20486
20487 VkFence fence;
20488 VkFenceCreateInfo fence_create_info{};
20489 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20490 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20491
20492 VkSemaphore semaphore;
20493 VkSemaphoreCreateInfo semaphore_create_info{};
20494 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20495 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20496
20497 VkCommandPool command_pool;
20498 VkCommandPoolCreateInfo pool_create_info{};
20499 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20500 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20501 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20502 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20503
20504 VkCommandBuffer command_buffer[2];
20505 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20506 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20507 command_buffer_allocate_info.commandPool = command_pool;
20508 command_buffer_allocate_info.commandBufferCount = 2;
20509 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20510 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20511
20512 VkQueue queue = VK_NULL_HANDLE;
20513 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20514
20515 {
20516 VkCommandBufferBeginInfo begin_info{};
20517 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20518 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20519
20520 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 -070020521 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020522
20523 VkViewport viewport{};
20524 viewport.maxDepth = 1.0f;
20525 viewport.minDepth = 0.0f;
20526 viewport.width = 512;
20527 viewport.height = 512;
20528 viewport.x = 0;
20529 viewport.y = 0;
20530 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20531 vkEndCommandBuffer(command_buffer[0]);
20532 }
20533 {
20534 VkCommandBufferBeginInfo begin_info{};
20535 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20536 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20537
20538 VkViewport viewport{};
20539 viewport.maxDepth = 1.0f;
20540 viewport.minDepth = 0.0f;
20541 viewport.width = 512;
20542 viewport.height = 512;
20543 viewport.x = 0;
20544 viewport.y = 0;
20545 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20546 vkEndCommandBuffer(command_buffer[1]);
20547 }
20548 {
20549 VkSubmitInfo submit_info{};
20550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20551 submit_info.commandBufferCount = 1;
20552 submit_info.pCommandBuffers = &command_buffer[0];
20553 submit_info.signalSemaphoreCount = 1;
20554 submit_info.pSignalSemaphores = &semaphore;
20555 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20556 }
20557 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020558 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020559 VkSubmitInfo submit_info{};
20560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20561 submit_info.commandBufferCount = 1;
20562 submit_info.pCommandBuffers = &command_buffer[1];
20563 submit_info.waitSemaphoreCount = 1;
20564 submit_info.pWaitSemaphores = &semaphore;
20565 submit_info.pWaitDstStageMask = flags;
20566 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20567 }
20568
20569 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20570 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20571
20572 vkDestroyFence(m_device->device(), fence, nullptr);
20573 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20574 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20575 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20576
20577 m_errorMonitor->VerifyNotFound();
20578}
20579
20580TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020581 ASSERT_NO_FATAL_FAILURE(InitState());
20582 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020583 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020584 return;
20585 }
20586
20587 VkResult err;
20588
20589 m_errorMonitor->ExpectSuccess();
20590
20591 VkQueue q0 = m_device->m_queue;
20592 VkQueue q1 = nullptr;
20593 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20594 ASSERT_NE(q1, nullptr);
20595
20596 // An (empty) command buffer. We must have work in the first submission --
20597 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020598 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020599 VkCommandPool pool;
20600 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20601 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020602 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20603 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020604 VkCommandBuffer cb;
20605 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20606 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020607 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020608 err = vkBeginCommandBuffer(cb, &cbbi);
20609 ASSERT_VK_SUCCESS(err);
20610 err = vkEndCommandBuffer(cb);
20611 ASSERT_VK_SUCCESS(err);
20612
20613 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020614 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020615 VkSemaphore s;
20616 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20617 ASSERT_VK_SUCCESS(err);
20618
20619 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020620 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020621
20622 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20623 ASSERT_VK_SUCCESS(err);
20624
20625 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020626 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020627 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020628
20629 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20630 ASSERT_VK_SUCCESS(err);
20631
20632 // Wait for q0 idle
20633 err = vkQueueWaitIdle(q0);
20634 ASSERT_VK_SUCCESS(err);
20635
20636 // Command buffer should have been completed (it was on q0); reset the pool.
20637 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20638
20639 m_errorMonitor->VerifyNotFound();
20640
20641 // Force device completely idle and clean up resources
20642 vkDeviceWaitIdle(m_device->device());
20643 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20644 vkDestroySemaphore(m_device->device(), s, nullptr);
20645}
20646
20647// This is a positive test. No errors should be generated.
20648TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020649 TEST_DESCRIPTION(
20650 "Two command buffers, each in a separate QueueSubmit call "
20651 "submitted on separate queues, the second having a fence, "
20652 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020653
20654 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020655 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020656
20657 m_errorMonitor->ExpectSuccess();
20658
20659 ASSERT_NO_FATAL_FAILURE(InitState());
20660 VkFence fence;
20661 VkFenceCreateInfo fence_create_info{};
20662 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20663 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20664
20665 VkSemaphore semaphore;
20666 VkSemaphoreCreateInfo semaphore_create_info{};
20667 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20668 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20669
20670 VkCommandPool command_pool;
20671 VkCommandPoolCreateInfo pool_create_info{};
20672 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20673 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20674 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20675 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20676
20677 VkCommandBuffer command_buffer[2];
20678 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20679 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20680 command_buffer_allocate_info.commandPool = command_pool;
20681 command_buffer_allocate_info.commandBufferCount = 2;
20682 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20683 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20684
20685 VkQueue queue = VK_NULL_HANDLE;
20686 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20687
20688 {
20689 VkCommandBufferBeginInfo begin_info{};
20690 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20691 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20692
20693 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 -070020694 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020695
20696 VkViewport viewport{};
20697 viewport.maxDepth = 1.0f;
20698 viewport.minDepth = 0.0f;
20699 viewport.width = 512;
20700 viewport.height = 512;
20701 viewport.x = 0;
20702 viewport.y = 0;
20703 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20704 vkEndCommandBuffer(command_buffer[0]);
20705 }
20706 {
20707 VkCommandBufferBeginInfo begin_info{};
20708 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20709 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20710
20711 VkViewport viewport{};
20712 viewport.maxDepth = 1.0f;
20713 viewport.minDepth = 0.0f;
20714 viewport.width = 512;
20715 viewport.height = 512;
20716 viewport.x = 0;
20717 viewport.y = 0;
20718 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20719 vkEndCommandBuffer(command_buffer[1]);
20720 }
20721 {
20722 VkSubmitInfo submit_info{};
20723 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20724 submit_info.commandBufferCount = 1;
20725 submit_info.pCommandBuffers = &command_buffer[0];
20726 submit_info.signalSemaphoreCount = 1;
20727 submit_info.pSignalSemaphores = &semaphore;
20728 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20729 }
20730 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020731 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020732 VkSubmitInfo submit_info{};
20733 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20734 submit_info.commandBufferCount = 1;
20735 submit_info.pCommandBuffers = &command_buffer[1];
20736 submit_info.waitSemaphoreCount = 1;
20737 submit_info.pWaitSemaphores = &semaphore;
20738 submit_info.pWaitDstStageMask = flags;
20739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20740 }
20741
20742 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20743
20744 vkDestroyFence(m_device->device(), fence, nullptr);
20745 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20746 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20747 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20748
20749 m_errorMonitor->VerifyNotFound();
20750}
20751
20752// This is a positive test. No errors should be generated.
20753TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020754 TEST_DESCRIPTION(
20755 "Two command buffers, each in a separate QueueSubmit call "
20756 "on the same queue, sharing a signal/wait semaphore, the "
20757 "second having a fence, "
20758 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020759
20760 m_errorMonitor->ExpectSuccess();
20761
20762 ASSERT_NO_FATAL_FAILURE(InitState());
20763 VkFence fence;
20764 VkFenceCreateInfo fence_create_info{};
20765 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20766 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20767
20768 VkSemaphore semaphore;
20769 VkSemaphoreCreateInfo semaphore_create_info{};
20770 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20771 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20772
20773 VkCommandPool command_pool;
20774 VkCommandPoolCreateInfo pool_create_info{};
20775 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20776 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20777 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20778 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20779
20780 VkCommandBuffer command_buffer[2];
20781 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20782 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20783 command_buffer_allocate_info.commandPool = command_pool;
20784 command_buffer_allocate_info.commandBufferCount = 2;
20785 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20786 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20787
20788 {
20789 VkCommandBufferBeginInfo begin_info{};
20790 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20791 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20792
20793 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 -070020794 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020795
20796 VkViewport viewport{};
20797 viewport.maxDepth = 1.0f;
20798 viewport.minDepth = 0.0f;
20799 viewport.width = 512;
20800 viewport.height = 512;
20801 viewport.x = 0;
20802 viewport.y = 0;
20803 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20804 vkEndCommandBuffer(command_buffer[0]);
20805 }
20806 {
20807 VkCommandBufferBeginInfo begin_info{};
20808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20809 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20810
20811 VkViewport viewport{};
20812 viewport.maxDepth = 1.0f;
20813 viewport.minDepth = 0.0f;
20814 viewport.width = 512;
20815 viewport.height = 512;
20816 viewport.x = 0;
20817 viewport.y = 0;
20818 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20819 vkEndCommandBuffer(command_buffer[1]);
20820 }
20821 {
20822 VkSubmitInfo submit_info{};
20823 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20824 submit_info.commandBufferCount = 1;
20825 submit_info.pCommandBuffers = &command_buffer[0];
20826 submit_info.signalSemaphoreCount = 1;
20827 submit_info.pSignalSemaphores = &semaphore;
20828 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20829 }
20830 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020831 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020832 VkSubmitInfo submit_info{};
20833 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20834 submit_info.commandBufferCount = 1;
20835 submit_info.pCommandBuffers = &command_buffer[1];
20836 submit_info.waitSemaphoreCount = 1;
20837 submit_info.pWaitSemaphores = &semaphore;
20838 submit_info.pWaitDstStageMask = flags;
20839 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20840 }
20841
20842 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20843
20844 vkDestroyFence(m_device->device(), fence, nullptr);
20845 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20846 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20847 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20848
20849 m_errorMonitor->VerifyNotFound();
20850}
20851
20852// This is a positive test. No errors should be generated.
20853TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020854 TEST_DESCRIPTION(
20855 "Two command buffers, each in a separate QueueSubmit call "
20856 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20857 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020858
20859 m_errorMonitor->ExpectSuccess();
20860
20861 ASSERT_NO_FATAL_FAILURE(InitState());
20862 VkFence fence;
20863 VkFenceCreateInfo fence_create_info{};
20864 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20865 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20866
20867 VkCommandPool command_pool;
20868 VkCommandPoolCreateInfo pool_create_info{};
20869 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20870 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20871 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20872 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20873
20874 VkCommandBuffer command_buffer[2];
20875 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20876 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20877 command_buffer_allocate_info.commandPool = command_pool;
20878 command_buffer_allocate_info.commandBufferCount = 2;
20879 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20880 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20881
20882 {
20883 VkCommandBufferBeginInfo begin_info{};
20884 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20885 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20886
20887 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 -070020888 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020889
20890 VkViewport viewport{};
20891 viewport.maxDepth = 1.0f;
20892 viewport.minDepth = 0.0f;
20893 viewport.width = 512;
20894 viewport.height = 512;
20895 viewport.x = 0;
20896 viewport.y = 0;
20897 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20898 vkEndCommandBuffer(command_buffer[0]);
20899 }
20900 {
20901 VkCommandBufferBeginInfo begin_info{};
20902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20903 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20904
20905 VkViewport viewport{};
20906 viewport.maxDepth = 1.0f;
20907 viewport.minDepth = 0.0f;
20908 viewport.width = 512;
20909 viewport.height = 512;
20910 viewport.x = 0;
20911 viewport.y = 0;
20912 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20913 vkEndCommandBuffer(command_buffer[1]);
20914 }
20915 {
20916 VkSubmitInfo submit_info{};
20917 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20918 submit_info.commandBufferCount = 1;
20919 submit_info.pCommandBuffers = &command_buffer[0];
20920 submit_info.signalSemaphoreCount = 0;
20921 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20922 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20923 }
20924 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020925 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020926 VkSubmitInfo submit_info{};
20927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20928 submit_info.commandBufferCount = 1;
20929 submit_info.pCommandBuffers = &command_buffer[1];
20930 submit_info.waitSemaphoreCount = 0;
20931 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20932 submit_info.pWaitDstStageMask = flags;
20933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20934 }
20935
20936 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20937
20938 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20939 ASSERT_VK_SUCCESS(err);
20940
20941 vkDestroyFence(m_device->device(), fence, nullptr);
20942 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20943 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20944
20945 m_errorMonitor->VerifyNotFound();
20946}
20947
20948// This is a positive test. No errors should be generated.
20949TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020950 TEST_DESCRIPTION(
20951 "Two command buffers, each in a separate QueueSubmit call "
20952 "on the same queue, the second having a fence, followed "
20953 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020954
20955 m_errorMonitor->ExpectSuccess();
20956
20957 ASSERT_NO_FATAL_FAILURE(InitState());
20958 VkFence fence;
20959 VkFenceCreateInfo fence_create_info{};
20960 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20961 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20962
20963 VkCommandPool command_pool;
20964 VkCommandPoolCreateInfo pool_create_info{};
20965 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20966 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20967 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20968 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20969
20970 VkCommandBuffer command_buffer[2];
20971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20972 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20973 command_buffer_allocate_info.commandPool = command_pool;
20974 command_buffer_allocate_info.commandBufferCount = 2;
20975 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20976 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20977
20978 {
20979 VkCommandBufferBeginInfo begin_info{};
20980 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20981 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20982
20983 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 -070020984 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020985
20986 VkViewport viewport{};
20987 viewport.maxDepth = 1.0f;
20988 viewport.minDepth = 0.0f;
20989 viewport.width = 512;
20990 viewport.height = 512;
20991 viewport.x = 0;
20992 viewport.y = 0;
20993 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20994 vkEndCommandBuffer(command_buffer[0]);
20995 }
20996 {
20997 VkCommandBufferBeginInfo begin_info{};
20998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20999 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21000
21001 VkViewport viewport{};
21002 viewport.maxDepth = 1.0f;
21003 viewport.minDepth = 0.0f;
21004 viewport.width = 512;
21005 viewport.height = 512;
21006 viewport.x = 0;
21007 viewport.y = 0;
21008 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21009 vkEndCommandBuffer(command_buffer[1]);
21010 }
21011 {
21012 VkSubmitInfo submit_info{};
21013 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21014 submit_info.commandBufferCount = 1;
21015 submit_info.pCommandBuffers = &command_buffer[0];
21016 submit_info.signalSemaphoreCount = 0;
21017 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21019 }
21020 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021021 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021022 VkSubmitInfo submit_info{};
21023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21024 submit_info.commandBufferCount = 1;
21025 submit_info.pCommandBuffers = &command_buffer[1];
21026 submit_info.waitSemaphoreCount = 0;
21027 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21028 submit_info.pWaitDstStageMask = flags;
21029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21030 }
21031
21032 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21033
21034 vkDestroyFence(m_device->device(), fence, nullptr);
21035 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21036 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21037
21038 m_errorMonitor->VerifyNotFound();
21039}
21040
21041// This is a positive test. No errors should be generated.
21042TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021043 TEST_DESCRIPTION(
21044 "Two command buffers each in a separate SubmitInfo sent in a single "
21045 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021046 ASSERT_NO_FATAL_FAILURE(InitState());
21047
21048 m_errorMonitor->ExpectSuccess();
21049
21050 VkFence fence;
21051 VkFenceCreateInfo fence_create_info{};
21052 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21053 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21054
21055 VkSemaphore semaphore;
21056 VkSemaphoreCreateInfo semaphore_create_info{};
21057 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21058 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21059
21060 VkCommandPool command_pool;
21061 VkCommandPoolCreateInfo pool_create_info{};
21062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21065 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21066
21067 VkCommandBuffer command_buffer[2];
21068 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21069 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21070 command_buffer_allocate_info.commandPool = command_pool;
21071 command_buffer_allocate_info.commandBufferCount = 2;
21072 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21073 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21074
21075 {
21076 VkCommandBufferBeginInfo begin_info{};
21077 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21078 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21079
21080 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 -070021081 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021082
21083 VkViewport viewport{};
21084 viewport.maxDepth = 1.0f;
21085 viewport.minDepth = 0.0f;
21086 viewport.width = 512;
21087 viewport.height = 512;
21088 viewport.x = 0;
21089 viewport.y = 0;
21090 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21091 vkEndCommandBuffer(command_buffer[0]);
21092 }
21093 {
21094 VkCommandBufferBeginInfo begin_info{};
21095 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21096 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21097
21098 VkViewport viewport{};
21099 viewport.maxDepth = 1.0f;
21100 viewport.minDepth = 0.0f;
21101 viewport.width = 512;
21102 viewport.height = 512;
21103 viewport.x = 0;
21104 viewport.y = 0;
21105 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21106 vkEndCommandBuffer(command_buffer[1]);
21107 }
21108 {
21109 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021110 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021111
21112 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21113 submit_info[0].pNext = NULL;
21114 submit_info[0].commandBufferCount = 1;
21115 submit_info[0].pCommandBuffers = &command_buffer[0];
21116 submit_info[0].signalSemaphoreCount = 1;
21117 submit_info[0].pSignalSemaphores = &semaphore;
21118 submit_info[0].waitSemaphoreCount = 0;
21119 submit_info[0].pWaitSemaphores = NULL;
21120 submit_info[0].pWaitDstStageMask = 0;
21121
21122 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21123 submit_info[1].pNext = NULL;
21124 submit_info[1].commandBufferCount = 1;
21125 submit_info[1].pCommandBuffers = &command_buffer[1];
21126 submit_info[1].waitSemaphoreCount = 1;
21127 submit_info[1].pWaitSemaphores = &semaphore;
21128 submit_info[1].pWaitDstStageMask = flags;
21129 submit_info[1].signalSemaphoreCount = 0;
21130 submit_info[1].pSignalSemaphores = NULL;
21131 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21132 }
21133
21134 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21135
21136 vkDestroyFence(m_device->device(), fence, nullptr);
21137 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21139 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21140
21141 m_errorMonitor->VerifyNotFound();
21142}
21143
21144TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21145 m_errorMonitor->ExpectSuccess();
21146
21147 ASSERT_NO_FATAL_FAILURE(InitState());
21148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21149
Tony Barbour552f6c02016-12-21 14:34:07 -070021150 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021151
21152 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21153 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21154 m_errorMonitor->VerifyNotFound();
21155 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21156 m_errorMonitor->VerifyNotFound();
21157 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21158 m_errorMonitor->VerifyNotFound();
21159
21160 m_commandBuffer->EndCommandBuffer();
21161 m_errorMonitor->VerifyNotFound();
21162}
21163
21164TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021165 TEST_DESCRIPTION(
21166 "Positive test where we create a renderpass with an "
21167 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21168 "has a valid layout, and a second subpass then uses a "
21169 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021170 m_errorMonitor->ExpectSuccess();
21171 ASSERT_NO_FATAL_FAILURE(InitState());
21172
21173 VkAttachmentReference attach[2] = {};
21174 attach[0].attachment = 0;
21175 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21176 attach[1].attachment = 0;
21177 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21178 VkSubpassDescription subpasses[2] = {};
21179 // First subpass clears DS attach on load
21180 subpasses[0].pDepthStencilAttachment = &attach[0];
21181 // 2nd subpass reads in DS as input attachment
21182 subpasses[1].inputAttachmentCount = 1;
21183 subpasses[1].pInputAttachments = &attach[1];
21184 VkAttachmentDescription attach_desc = {};
21185 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21186 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21187 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21188 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21189 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21190 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21191 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21192 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21193 VkRenderPassCreateInfo rpci = {};
21194 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21195 rpci.attachmentCount = 1;
21196 rpci.pAttachments = &attach_desc;
21197 rpci.subpassCount = 2;
21198 rpci.pSubpasses = subpasses;
21199
21200 // Now create RenderPass and verify no errors
21201 VkRenderPass rp;
21202 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21203 m_errorMonitor->VerifyNotFound();
21204
21205 vkDestroyRenderPass(m_device->device(), rp, NULL);
21206}
21207
Tobin Ehlis01103de2017-02-16 13:22:47 -070021208TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21209 TEST_DESCRIPTION(
21210 "Create a render pass with depth-stencil attachment where layout transition "
21211 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21212 "transition has correctly occurred at queue submit time with no validation errors.");
21213
21214 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21215 VkImageFormatProperties format_props;
21216 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21217 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21218 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21219 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21220 return;
21221 }
21222
21223 m_errorMonitor->ExpectSuccess();
21224 ASSERT_NO_FATAL_FAILURE(InitState());
21225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21226
21227 // A renderpass with one depth/stencil attachment.
21228 VkAttachmentDescription attachment = {0,
21229 ds_format,
21230 VK_SAMPLE_COUNT_1_BIT,
21231 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21232 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21233 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21234 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21235 VK_IMAGE_LAYOUT_UNDEFINED,
21236 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21237
21238 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21239
21240 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21241
21242 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21243
21244 VkRenderPass rp;
21245 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21246 ASSERT_VK_SUCCESS(err);
21247 // A compatible ds image.
21248 VkImageObj image(m_device);
21249 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21250 ASSERT_TRUE(image.initialized());
21251
21252 VkImageViewCreateInfo ivci = {
21253 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21254 nullptr,
21255 0,
21256 image.handle(),
21257 VK_IMAGE_VIEW_TYPE_2D,
21258 ds_format,
21259 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21260 VK_COMPONENT_SWIZZLE_IDENTITY},
21261 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21262 };
21263 VkImageView view;
21264 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21265 ASSERT_VK_SUCCESS(err);
21266
21267 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21268 VkFramebuffer fb;
21269 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21270 ASSERT_VK_SUCCESS(err);
21271
21272 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21273 m_commandBuffer->BeginCommandBuffer();
21274 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21275 vkCmdEndRenderPass(m_commandBuffer->handle());
21276 m_commandBuffer->EndCommandBuffer();
21277 QueueCommandBuffer(false);
21278 m_errorMonitor->VerifyNotFound();
21279
21280 // Cleanup
21281 vkDestroyImageView(m_device->device(), view, NULL);
21282 vkDestroyRenderPass(m_device->device(), rp, NULL);
21283 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21284}
21285
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021286TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021287 TEST_DESCRIPTION(
21288 "Test that pipeline validation accepts matrices passed "
21289 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021290 m_errorMonitor->ExpectSuccess();
21291
21292 ASSERT_NO_FATAL_FAILURE(InitState());
21293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21294
21295 VkVertexInputBindingDescription input_binding;
21296 memset(&input_binding, 0, sizeof(input_binding));
21297
21298 VkVertexInputAttributeDescription input_attribs[2];
21299 memset(input_attribs, 0, sizeof(input_attribs));
21300
21301 for (int i = 0; i < 2; i++) {
21302 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21303 input_attribs[i].location = i;
21304 }
21305
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021306 char const *vsSource =
21307 "#version 450\n"
21308 "\n"
21309 "layout(location=0) in mat2x4 x;\n"
21310 "out gl_PerVertex {\n"
21311 " vec4 gl_Position;\n"
21312 "};\n"
21313 "void main(){\n"
21314 " gl_Position = x[0] + x[1];\n"
21315 "}\n";
21316 char const *fsSource =
21317 "#version 450\n"
21318 "\n"
21319 "layout(location=0) out vec4 color;\n"
21320 "void main(){\n"
21321 " color = vec4(1);\n"
21322 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021323
21324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21326
21327 VkPipelineObj pipe(m_device);
21328 pipe.AddColorAttachment();
21329 pipe.AddShader(&vs);
21330 pipe.AddShader(&fs);
21331
21332 pipe.AddVertexInputBindings(&input_binding, 1);
21333 pipe.AddVertexInputAttribs(input_attribs, 2);
21334
21335 VkDescriptorSetObj descriptorSet(m_device);
21336 descriptorSet.AppendDummy();
21337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21338
21339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21340
21341 /* expect success */
21342 m_errorMonitor->VerifyNotFound();
21343}
21344
21345TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21346 m_errorMonitor->ExpectSuccess();
21347
21348 ASSERT_NO_FATAL_FAILURE(InitState());
21349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21350
21351 VkVertexInputBindingDescription input_binding;
21352 memset(&input_binding, 0, sizeof(input_binding));
21353
21354 VkVertexInputAttributeDescription input_attribs[2];
21355 memset(input_attribs, 0, sizeof(input_attribs));
21356
21357 for (int i = 0; i < 2; i++) {
21358 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21359 input_attribs[i].location = i;
21360 }
21361
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021362 char const *vsSource =
21363 "#version 450\n"
21364 "\n"
21365 "layout(location=0) in vec4 x[2];\n"
21366 "out gl_PerVertex {\n"
21367 " vec4 gl_Position;\n"
21368 "};\n"
21369 "void main(){\n"
21370 " gl_Position = x[0] + x[1];\n"
21371 "}\n";
21372 char const *fsSource =
21373 "#version 450\n"
21374 "\n"
21375 "layout(location=0) out vec4 color;\n"
21376 "void main(){\n"
21377 " color = vec4(1);\n"
21378 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021379
21380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21382
21383 VkPipelineObj pipe(m_device);
21384 pipe.AddColorAttachment();
21385 pipe.AddShader(&vs);
21386 pipe.AddShader(&fs);
21387
21388 pipe.AddVertexInputBindings(&input_binding, 1);
21389 pipe.AddVertexInputAttribs(input_attribs, 2);
21390
21391 VkDescriptorSetObj descriptorSet(m_device);
21392 descriptorSet.AppendDummy();
21393 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21394
21395 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21396
21397 m_errorMonitor->VerifyNotFound();
21398}
21399
21400TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021401 TEST_DESCRIPTION(
21402 "Test that pipeline validation accepts consuming a vertex attribute "
21403 "through multiple vertex shader inputs, each consuming a different "
21404 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021405 m_errorMonitor->ExpectSuccess();
21406
21407 ASSERT_NO_FATAL_FAILURE(InitState());
21408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21409
21410 VkVertexInputBindingDescription input_binding;
21411 memset(&input_binding, 0, sizeof(input_binding));
21412
21413 VkVertexInputAttributeDescription input_attribs[3];
21414 memset(input_attribs, 0, sizeof(input_attribs));
21415
21416 for (int i = 0; i < 3; i++) {
21417 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21418 input_attribs[i].location = i;
21419 }
21420
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021421 char const *vsSource =
21422 "#version 450\n"
21423 "\n"
21424 "layout(location=0) in vec4 x;\n"
21425 "layout(location=1) in vec3 y1;\n"
21426 "layout(location=1, component=3) in float y2;\n"
21427 "layout(location=2) in vec4 z;\n"
21428 "out gl_PerVertex {\n"
21429 " vec4 gl_Position;\n"
21430 "};\n"
21431 "void main(){\n"
21432 " gl_Position = x + vec4(y1, y2) + z;\n"
21433 "}\n";
21434 char const *fsSource =
21435 "#version 450\n"
21436 "\n"
21437 "layout(location=0) out vec4 color;\n"
21438 "void main(){\n"
21439 " color = vec4(1);\n"
21440 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441
21442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21444
21445 VkPipelineObj pipe(m_device);
21446 pipe.AddColorAttachment();
21447 pipe.AddShader(&vs);
21448 pipe.AddShader(&fs);
21449
21450 pipe.AddVertexInputBindings(&input_binding, 1);
21451 pipe.AddVertexInputAttribs(input_attribs, 3);
21452
21453 VkDescriptorSetObj descriptorSet(m_device);
21454 descriptorSet.AppendDummy();
21455 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21456
21457 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21458
21459 m_errorMonitor->VerifyNotFound();
21460}
21461
21462TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21463 m_errorMonitor->ExpectSuccess();
21464
21465 ASSERT_NO_FATAL_FAILURE(InitState());
21466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21467
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021468 char const *vsSource =
21469 "#version 450\n"
21470 "out gl_PerVertex {\n"
21471 " vec4 gl_Position;\n"
21472 "};\n"
21473 "void main(){\n"
21474 " gl_Position = vec4(0);\n"
21475 "}\n";
21476 char const *fsSource =
21477 "#version 450\n"
21478 "\n"
21479 "layout(location=0) out vec4 color;\n"
21480 "void main(){\n"
21481 " color = vec4(1);\n"
21482 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021483
21484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21486
21487 VkPipelineObj pipe(m_device);
21488 pipe.AddColorAttachment();
21489 pipe.AddShader(&vs);
21490 pipe.AddShader(&fs);
21491
21492 VkDescriptorSetObj descriptorSet(m_device);
21493 descriptorSet.AppendDummy();
21494 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21495
21496 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21497
21498 m_errorMonitor->VerifyNotFound();
21499}
21500
21501TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021502 TEST_DESCRIPTION(
21503 "Test that pipeline validation accepts the relaxed type matching rules "
21504 "set out in 14.1.3: fundamental type must match, and producer side must "
21505 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021506 m_errorMonitor->ExpectSuccess();
21507
21508 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21509
21510 ASSERT_NO_FATAL_FAILURE(InitState());
21511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021513 char const *vsSource =
21514 "#version 450\n"
21515 "out gl_PerVertex {\n"
21516 " vec4 gl_Position;\n"
21517 "};\n"
21518 "layout(location=0) out vec3 x;\n"
21519 "layout(location=1) out ivec3 y;\n"
21520 "layout(location=2) out vec3 z;\n"
21521 "void main(){\n"
21522 " gl_Position = vec4(0);\n"
21523 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21524 "}\n";
21525 char const *fsSource =
21526 "#version 450\n"
21527 "\n"
21528 "layout(location=0) out vec4 color;\n"
21529 "layout(location=0) in float x;\n"
21530 "layout(location=1) flat in int y;\n"
21531 "layout(location=2) in vec2 z;\n"
21532 "void main(){\n"
21533 " color = vec4(1 + x + y + z.x);\n"
21534 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021535
21536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21537 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21538
21539 VkPipelineObj pipe(m_device);
21540 pipe.AddColorAttachment();
21541 pipe.AddShader(&vs);
21542 pipe.AddShader(&fs);
21543
21544 VkDescriptorSetObj descriptorSet(m_device);
21545 descriptorSet.AppendDummy();
21546 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21547
21548 VkResult err = VK_SUCCESS;
21549 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21550 ASSERT_VK_SUCCESS(err);
21551
21552 m_errorMonitor->VerifyNotFound();
21553}
21554
21555TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021556 TEST_DESCRIPTION(
21557 "Test that pipeline validation accepts per-vertex variables "
21558 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021559 m_errorMonitor->ExpectSuccess();
21560
21561 ASSERT_NO_FATAL_FAILURE(InitState());
21562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21563
21564 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021565 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021566 return;
21567 }
21568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021569 char const *vsSource =
21570 "#version 450\n"
21571 "void main(){}\n";
21572 char const *tcsSource =
21573 "#version 450\n"
21574 "layout(location=0) out int x[];\n"
21575 "layout(vertices=3) out;\n"
21576 "void main(){\n"
21577 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21578 " gl_TessLevelInner[0] = 1;\n"
21579 " x[gl_InvocationID] = gl_InvocationID;\n"
21580 "}\n";
21581 char const *tesSource =
21582 "#version 450\n"
21583 "layout(triangles, equal_spacing, cw) in;\n"
21584 "layout(location=0) in int x[];\n"
21585 "out gl_PerVertex { vec4 gl_Position; };\n"
21586 "void main(){\n"
21587 " gl_Position.xyz = gl_TessCoord;\n"
21588 " gl_Position.w = x[0] + x[1] + x[2];\n"
21589 "}\n";
21590 char const *fsSource =
21591 "#version 450\n"
21592 "layout(location=0) out vec4 color;\n"
21593 "void main(){\n"
21594 " color = vec4(1);\n"
21595 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021596
21597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21598 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21599 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21601
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021602 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21603 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021604
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021605 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021606
21607 VkPipelineObj pipe(m_device);
21608 pipe.SetInputAssembly(&iasci);
21609 pipe.SetTessellation(&tsci);
21610 pipe.AddColorAttachment();
21611 pipe.AddShader(&vs);
21612 pipe.AddShader(&tcs);
21613 pipe.AddShader(&tes);
21614 pipe.AddShader(&fs);
21615
21616 VkDescriptorSetObj descriptorSet(m_device);
21617 descriptorSet.AppendDummy();
21618 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21619
21620 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21621
21622 m_errorMonitor->VerifyNotFound();
21623}
21624
21625TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021626 TEST_DESCRIPTION(
21627 "Test that pipeline validation accepts a user-defined "
21628 "interface block passed into the geometry shader. This "
21629 "is interesting because the 'extra' array level is not "
21630 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021631 m_errorMonitor->ExpectSuccess();
21632
21633 ASSERT_NO_FATAL_FAILURE(InitState());
21634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21635
21636 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021637 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021638 return;
21639 }
21640
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021641 char const *vsSource =
21642 "#version 450\n"
21643 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21644 "void main(){\n"
21645 " vs_out.x = vec4(1);\n"
21646 "}\n";
21647 char const *gsSource =
21648 "#version 450\n"
21649 "layout(triangles) in;\n"
21650 "layout(triangle_strip, max_vertices=3) out;\n"
21651 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21652 "out gl_PerVertex { vec4 gl_Position; };\n"
21653 "void main() {\n"
21654 " gl_Position = gs_in[0].x;\n"
21655 " EmitVertex();\n"
21656 "}\n";
21657 char const *fsSource =
21658 "#version 450\n"
21659 "layout(location=0) out vec4 color;\n"
21660 "void main(){\n"
21661 " color = vec4(1);\n"
21662 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021663
21664 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21665 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21666 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21667
21668 VkPipelineObj pipe(m_device);
21669 pipe.AddColorAttachment();
21670 pipe.AddShader(&vs);
21671 pipe.AddShader(&gs);
21672 pipe.AddShader(&fs);
21673
21674 VkDescriptorSetObj descriptorSet(m_device);
21675 descriptorSet.AppendDummy();
21676 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21677
21678 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21679
21680 m_errorMonitor->VerifyNotFound();
21681}
21682
21683TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021684 TEST_DESCRIPTION(
21685 "Test that pipeline validation accepts basic use of 64bit vertex "
21686 "attributes. This is interesting because they consume multiple "
21687 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021688 m_errorMonitor->ExpectSuccess();
21689
21690 ASSERT_NO_FATAL_FAILURE(InitState());
21691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21692
21693 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021694 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021695 return;
21696 }
21697
21698 VkVertexInputBindingDescription input_bindings[1];
21699 memset(input_bindings, 0, sizeof(input_bindings));
21700
21701 VkVertexInputAttributeDescription input_attribs[4];
21702 memset(input_attribs, 0, sizeof(input_attribs));
21703 input_attribs[0].location = 0;
21704 input_attribs[0].offset = 0;
21705 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21706 input_attribs[1].location = 2;
21707 input_attribs[1].offset = 32;
21708 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21709 input_attribs[2].location = 4;
21710 input_attribs[2].offset = 64;
21711 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21712 input_attribs[3].location = 6;
21713 input_attribs[3].offset = 96;
21714 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021716 char const *vsSource =
21717 "#version 450\n"
21718 "\n"
21719 "layout(location=0) in dmat4 x;\n"
21720 "out gl_PerVertex {\n"
21721 " vec4 gl_Position;\n"
21722 "};\n"
21723 "void main(){\n"
21724 " gl_Position = vec4(x[0][0]);\n"
21725 "}\n";
21726 char const *fsSource =
21727 "#version 450\n"
21728 "\n"
21729 "layout(location=0) out vec4 color;\n"
21730 "void main(){\n"
21731 " color = vec4(1);\n"
21732 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021733
21734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21735 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21736
21737 VkPipelineObj pipe(m_device);
21738 pipe.AddColorAttachment();
21739 pipe.AddShader(&vs);
21740 pipe.AddShader(&fs);
21741
21742 pipe.AddVertexInputBindings(input_bindings, 1);
21743 pipe.AddVertexInputAttribs(input_attribs, 4);
21744
21745 VkDescriptorSetObj descriptorSet(m_device);
21746 descriptorSet.AppendDummy();
21747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21748
21749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21750
21751 m_errorMonitor->VerifyNotFound();
21752}
21753
21754TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21755 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21756 m_errorMonitor->ExpectSuccess();
21757
21758 ASSERT_NO_FATAL_FAILURE(InitState());
21759
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021760 char const *vsSource =
21761 "#version 450\n"
21762 "\n"
21763 "out gl_PerVertex {\n"
21764 " vec4 gl_Position;\n"
21765 "};\n"
21766 "void main(){\n"
21767 " gl_Position = vec4(1);\n"
21768 "}\n";
21769 char const *fsSource =
21770 "#version 450\n"
21771 "\n"
21772 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21773 "layout(location=0) out vec4 color;\n"
21774 "void main() {\n"
21775 " color = subpassLoad(x);\n"
21776 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021777
21778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21779 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21780
21781 VkPipelineObj pipe(m_device);
21782 pipe.AddShader(&vs);
21783 pipe.AddShader(&fs);
21784 pipe.AddColorAttachment();
21785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21786
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021787 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21788 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021789 VkDescriptorSetLayout dsl;
21790 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21791 ASSERT_VK_SUCCESS(err);
21792
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021793 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021794 VkPipelineLayout pl;
21795 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21796 ASSERT_VK_SUCCESS(err);
21797
21798 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021799 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21800 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21801 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21802 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21803 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 -060021804 };
21805 VkAttachmentReference color = {
21806 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21807 };
21808 VkAttachmentReference input = {
21809 1, VK_IMAGE_LAYOUT_GENERAL,
21810 };
21811
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021812 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021813
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021814 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021815 VkRenderPass rp;
21816 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21817 ASSERT_VK_SUCCESS(err);
21818
21819 // should be OK. would go wrong here if it's going to...
21820 pipe.CreateVKPipeline(pl, rp);
21821
21822 m_errorMonitor->VerifyNotFound();
21823
21824 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21825 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21826 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21827}
21828
21829TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021830 TEST_DESCRIPTION(
21831 "Test that pipeline validation accepts a compute pipeline which declares a "
21832 "descriptor-backed resource which is not provided, but the shader does not "
21833 "statically use it. This is interesting because it requires compute pipelines "
21834 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021835 m_errorMonitor->ExpectSuccess();
21836
21837 ASSERT_NO_FATAL_FAILURE(InitState());
21838
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021839 char const *csSource =
21840 "#version 450\n"
21841 "\n"
21842 "layout(local_size_x=1) in;\n"
21843 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21844 "void main(){\n"
21845 " // x is not used.\n"
21846 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021847
21848 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21849
21850 VkDescriptorSetObj descriptorSet(m_device);
21851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21852
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021853 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21854 nullptr,
21855 0,
21856 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21857 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21858 descriptorSet.GetPipelineLayout(),
21859 VK_NULL_HANDLE,
21860 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021861
21862 VkPipeline pipe;
21863 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21864
21865 m_errorMonitor->VerifyNotFound();
21866
21867 if (err == VK_SUCCESS) {
21868 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21869 }
21870}
21871
21872TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021873 TEST_DESCRIPTION(
21874 "Test that pipeline validation accepts a shader consuming only the "
21875 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021876 m_errorMonitor->ExpectSuccess();
21877
21878 ASSERT_NO_FATAL_FAILURE(InitState());
21879
21880 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021881 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21882 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21883 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021884 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021885 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021886 VkDescriptorSetLayout dsl;
21887 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21888 ASSERT_VK_SUCCESS(err);
21889
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021890 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021891 VkPipelineLayout pl;
21892 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21893 ASSERT_VK_SUCCESS(err);
21894
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021895 char const *csSource =
21896 "#version 450\n"
21897 "\n"
21898 "layout(local_size_x=1) in;\n"
21899 "layout(set=0, binding=0) uniform sampler s;\n"
21900 "layout(set=0, binding=1) uniform texture2D t;\n"
21901 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21902 "void main() {\n"
21903 " x = texture(sampler2D(t, s), vec2(0));\n"
21904 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021905 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21906
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021907 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21908 nullptr,
21909 0,
21910 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21911 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21912 pl,
21913 VK_NULL_HANDLE,
21914 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021915
21916 VkPipeline pipe;
21917 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21918
21919 m_errorMonitor->VerifyNotFound();
21920
21921 if (err == VK_SUCCESS) {
21922 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21923 }
21924
21925 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21926 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21927}
21928
21929TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021930 TEST_DESCRIPTION(
21931 "Test that pipeline validation accepts a shader consuming only the "
21932 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021933 m_errorMonitor->ExpectSuccess();
21934
21935 ASSERT_NO_FATAL_FAILURE(InitState());
21936
21937 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021938 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21939 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21940 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021941 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021942 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021943 VkDescriptorSetLayout dsl;
21944 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21945 ASSERT_VK_SUCCESS(err);
21946
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021947 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021948 VkPipelineLayout pl;
21949 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21950 ASSERT_VK_SUCCESS(err);
21951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021952 char const *csSource =
21953 "#version 450\n"
21954 "\n"
21955 "layout(local_size_x=1) in;\n"
21956 "layout(set=0, binding=0) uniform texture2D t;\n"
21957 "layout(set=0, binding=1) uniform sampler s;\n"
21958 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21959 "void main() {\n"
21960 " x = texture(sampler2D(t, s), vec2(0));\n"
21961 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021962 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21963
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021964 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21965 nullptr,
21966 0,
21967 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21968 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21969 pl,
21970 VK_NULL_HANDLE,
21971 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021972
21973 VkPipeline pipe;
21974 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21975
21976 m_errorMonitor->VerifyNotFound();
21977
21978 if (err == VK_SUCCESS) {
21979 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21980 }
21981
21982 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21983 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21984}
21985
21986TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021987 TEST_DESCRIPTION(
21988 "Test that pipeline validation accepts a shader consuming "
21989 "both the sampler and the image of a combined image+sampler "
21990 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021991 m_errorMonitor->ExpectSuccess();
21992
21993 ASSERT_NO_FATAL_FAILURE(InitState());
21994
21995 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021996 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21997 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021998 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021999 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022000 VkDescriptorSetLayout dsl;
22001 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22002 ASSERT_VK_SUCCESS(err);
22003
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022004 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022005 VkPipelineLayout pl;
22006 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22007 ASSERT_VK_SUCCESS(err);
22008
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022009 char const *csSource =
22010 "#version 450\n"
22011 "\n"
22012 "layout(local_size_x=1) in;\n"
22013 "layout(set=0, binding=0) uniform texture2D t;\n"
22014 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22015 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22016 "void main() {\n"
22017 " x = texture(sampler2D(t, s), vec2(0));\n"
22018 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022019 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022021 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22022 nullptr,
22023 0,
22024 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22025 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22026 pl,
22027 VK_NULL_HANDLE,
22028 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022029
22030 VkPipeline pipe;
22031 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22032
22033 m_errorMonitor->VerifyNotFound();
22034
22035 if (err == VK_SUCCESS) {
22036 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22037 }
22038
22039 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22040 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22041}
22042
22043TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22044 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22045
22046 ASSERT_NO_FATAL_FAILURE(InitState());
22047
22048 // Positive test to check parameter_validation and unique_objects support
22049 // for NV_dedicated_allocation
22050 uint32_t extension_count = 0;
22051 bool supports_nv_dedicated_allocation = false;
22052 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22053 ASSERT_VK_SUCCESS(err);
22054
22055 if (extension_count > 0) {
22056 std::vector<VkExtensionProperties> available_extensions(extension_count);
22057
22058 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22059 ASSERT_VK_SUCCESS(err);
22060
22061 for (const auto &extension_props : available_extensions) {
22062 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22063 supports_nv_dedicated_allocation = true;
22064 }
22065 }
22066 }
22067
22068 if (supports_nv_dedicated_allocation) {
22069 m_errorMonitor->ExpectSuccess();
22070
22071 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22072 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22073 dedicated_buffer_create_info.pNext = nullptr;
22074 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22075
22076 uint32_t queue_family_index = 0;
22077 VkBufferCreateInfo buffer_create_info = {};
22078 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22079 buffer_create_info.pNext = &dedicated_buffer_create_info;
22080 buffer_create_info.size = 1024;
22081 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22082 buffer_create_info.queueFamilyIndexCount = 1;
22083 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22084
22085 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022086 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022087 ASSERT_VK_SUCCESS(err);
22088
22089 VkMemoryRequirements memory_reqs;
22090 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22091
22092 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22093 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22094 dedicated_memory_info.pNext = nullptr;
22095 dedicated_memory_info.buffer = buffer;
22096 dedicated_memory_info.image = VK_NULL_HANDLE;
22097
22098 VkMemoryAllocateInfo memory_info = {};
22099 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22100 memory_info.pNext = &dedicated_memory_info;
22101 memory_info.allocationSize = memory_reqs.size;
22102
22103 bool pass;
22104 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22105 ASSERT_TRUE(pass);
22106
22107 VkDeviceMemory buffer_memory;
22108 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22109 ASSERT_VK_SUCCESS(err);
22110
22111 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22112 ASSERT_VK_SUCCESS(err);
22113
22114 vkDestroyBuffer(m_device->device(), buffer, NULL);
22115 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22116
22117 m_errorMonitor->VerifyNotFound();
22118 }
22119}
22120
22121TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22122 VkResult err;
22123
22124 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22125
22126 ASSERT_NO_FATAL_FAILURE(InitState());
22127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22128
22129 std::vector<const char *> device_extension_names;
22130 auto features = m_device->phy().features();
22131 // Artificially disable support for non-solid fill modes
22132 features.fillModeNonSolid = false;
22133 // The sacrificial device object
22134 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22135
22136 VkRenderpassObj render_pass(&test_device);
22137
22138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22140 pipeline_layout_ci.setLayoutCount = 0;
22141 pipeline_layout_ci.pSetLayouts = NULL;
22142
22143 VkPipelineLayout pipeline_layout;
22144 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22145 ASSERT_VK_SUCCESS(err);
22146
22147 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22148 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22149 rs_ci.pNext = nullptr;
22150 rs_ci.lineWidth = 1.0f;
22151 rs_ci.rasterizerDiscardEnable = true;
22152
22153 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22154 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22155
22156 // Set polygonMode=FILL. No error is expected
22157 m_errorMonitor->ExpectSuccess();
22158 {
22159 VkPipelineObj pipe(&test_device);
22160 pipe.AddShader(&vs);
22161 pipe.AddShader(&fs);
22162 pipe.AddColorAttachment();
22163 // Set polygonMode to a good value
22164 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22165 pipe.SetRasterization(&rs_ci);
22166 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22167 }
22168 m_errorMonitor->VerifyNotFound();
22169
22170 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22171}
22172
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022173#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022174TEST_F(VkPositiveLayerTest, LongFenceChain)
22175{
22176 m_errorMonitor->ExpectSuccess();
22177
22178 ASSERT_NO_FATAL_FAILURE(InitState());
22179 VkResult err;
22180
22181 std::vector<VkFence> fences;
22182
22183 const int chainLength = 32768;
22184
22185 for (int i = 0; i < chainLength; i++) {
22186 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22187 VkFence fence;
22188 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22189 ASSERT_VK_SUCCESS(err);
22190
22191 fences.push_back(fence);
22192
22193 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22194 0, nullptr, 0, nullptr };
22195 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22196 ASSERT_VK_SUCCESS(err);
22197
22198 }
22199
22200 // BOOM, stack overflow.
22201 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22202
22203 for (auto fence : fences)
22204 vkDestroyFence(m_device->device(), fence, nullptr);
22205
22206 m_errorMonitor->VerifyNotFound();
22207}
22208#endif
22209
Cody Northrop1242dfd2016-07-13 17:24:59 -060022210#if defined(ANDROID) && defined(VALIDATION_APK)
22211static bool initialized = false;
22212static bool active = false;
22213
22214// Convert Intents to argv
22215// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022216std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022217 std::vector<std::string> args;
22218 JavaVM &vm = *app.activity->vm;
22219 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022220 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022221
22222 JNIEnv &env = *p_env;
22223 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022224 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022225 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022226 jmethodID get_string_extra_method =
22227 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022228 jvalue get_string_extra_args;
22229 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022230 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022231
22232 std::string args_str;
22233 if (extra_str) {
22234 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22235 args_str = extra_utf;
22236 env.ReleaseStringUTFChars(extra_str, extra_utf);
22237 env.DeleteLocalRef(extra_str);
22238 }
22239
22240 env.DeleteLocalRef(get_string_extra_args.l);
22241 env.DeleteLocalRef(intent);
22242 vm.DetachCurrentThread();
22243
22244 // split args_str
22245 std::stringstream ss(args_str);
22246 std::string arg;
22247 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022248 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022249 }
22250
22251 return args;
22252}
22253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022254static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022256static void processCommand(struct android_app *app, int32_t cmd) {
22257 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022258 case APP_CMD_INIT_WINDOW: {
22259 if (app->window) {
22260 initialized = true;
22261 }
22262 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022263 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022264 case APP_CMD_GAINED_FOCUS: {
22265 active = true;
22266 break;
22267 }
22268 case APP_CMD_LOST_FOCUS: {
22269 active = false;
22270 break;
22271 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022272 }
22273}
22274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022275void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022276 app_dummy();
22277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022278 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022279
22280 int vulkanSupport = InitVulkan();
22281 if (vulkanSupport == 0) {
22282 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22283 return;
22284 }
22285
22286 app->onAppCmd = processCommand;
22287 app->onInputEvent = processInput;
22288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022289 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022290 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022291 struct android_poll_source *source;
22292 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022293 if (source) {
22294 source->process(app, source);
22295 }
22296
22297 if (app->destroyRequested != 0) {
22298 VkTestFramework::Finish();
22299 return;
22300 }
22301 }
22302
22303 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022304 // Use the following key to send arguments to gtest, i.e.
22305 // --es args "--gtest_filter=-VkLayerTest.foo"
22306 const char key[] = "args";
22307 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022309 std::string filter = "";
22310 if (args.size() > 0) {
22311 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22312 filter += args[0];
22313 } else {
22314 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22315 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022317 int argc = 2;
22318 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22319 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022321 // Route output to files until we can override the gtest output
22322 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22323 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022325 ::testing::InitGoogleTest(&argc, argv);
22326 VkTestFramework::InitArgs(&argc, argv);
22327 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022329 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022331 if (result != 0) {
22332 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22333 } else {
22334 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22335 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022337 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022339 fclose(stdout);
22340 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022342 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022343 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022344 }
22345 }
22346}
22347#endif
22348
Tony Barbour300a6082015-04-07 13:44:53 -060022349int main(int argc, char **argv) {
22350 int result;
22351
Cody Northrop8e54a402016-03-08 22:25:52 -070022352#ifdef ANDROID
22353 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022354 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022355#endif
22356
Tony Barbour300a6082015-04-07 13:44:53 -060022357 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022358 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022359
22360 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22361
22362 result = RUN_ALL_TESTS();
22363
Tony Barbour6918cd52015-04-09 12:58:51 -060022364 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022365 return result;
22366}