blob: 6517f38a0e7a47b0b72c27d99de1c4e52c842599 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tobin Ehliscdf95132017-03-15 13:50:56 -0600358 bool m_enable_maintenance1_ext = false;
Tony Barbour300a6082015-04-07 13:44:53 -0600359
360 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600361 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600362 std::vector<const char *> instance_extension_names;
363 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600364
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700365 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600366 /*
367 * Since CreateDbgMsgCallback is an instance level extension call
368 * any extension / layer that utilizes that feature also needs
369 * to be enabled at create instance time.
370 */
Karl Schultz6addd812016-02-02 17:17:23 -0700371 // Use Threading layer first to protect others from
372 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700373 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600374 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700376 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600403 if (m_enable_maintenance1_ext) {
404 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
405 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600406
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 this->app_info.pApplicationName = "layer_tests";
410 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600411 this->app_info.pEngineName = "unittest";
412 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600413 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600414
Tony Barbour15524c32015-04-29 17:34:29 -0600415 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600417 }
418
419 virtual void TearDown() {
420 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600421 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600422 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600423 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600424
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600425 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600426};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429 // Create identity matrix
430 int i;
431 struct vktriangle_vs_uniform data;
432
433 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 glm::mat4 View = glm::mat4(1.0f);
435 glm::mat4 Model = glm::mat4(1.0f);
436 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700438 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500439
440 memcpy(&data.mvp, &MVP[0][0], matrixSize);
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444 };
445
Karl Schultz6addd812016-02-02 17:17:23 -0700446 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 data.position[i][0] = tri_data[i].posX;
448 data.position[i][1] = tri_data[i].posY;
449 data.position[i][2] = tri_data[i].posZ;
450 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700451 data.color[i][0] = tri_data[i].r;
452 data.color[i][1] = tri_data[i].g;
453 data.color[i][2] = tri_data[i].b;
454 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500455 }
456
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 ASSERT_NO_FATAL_FAILURE(InitViewport());
458
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200459 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
460 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
465 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800466 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 pipelineobj.AddShader(&vs);
468 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 if (failMask & BsoFailLineWidth) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600472 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600473 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
474 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 }
476 if (failMask & BsoFailDepthBias) {
477 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600481 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600482 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600483 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700484 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700485 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600486 if (failMask & BsoFailViewport) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
488 }
489 if (failMask & BsoFailScissor) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
491 }
492 if (failMask & BsoFailBlend) {
493 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600494 VkPipelineColorBlendAttachmentState att_state = {};
495 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
496 att_state.blendEnable = VK_TRUE;
497 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600498 }
499 if (failMask & BsoFailDepthBounds) {
500 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
501 }
502 if (failMask & BsoFailStencilReadMask) {
503 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
504 }
505 if (failMask & BsoFailStencilWriteMask) {
506 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
507 }
508 if (failMask & BsoFailStencilReference) {
509 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
510 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
512 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700516 m_commandBuffer->BeginCommandBuffer();
517 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518
Tony Barbourfe3351b2015-07-28 10:17:20 -0600519 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520
521 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600522 if (failMask & BsoFailIndexBuffer) {
523 // Use DrawIndexed w/o an index buffer bound
524 DrawIndexed(3, 1, 0, 0, 0);
525 } else {
526 Draw(3, 1, 0, 0);
527 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Mark Muellerd4914412016-06-13 17:52:06 -0600529 if (failMask & BsoFailCmdClearAttachments) {
530 VkClearAttachment color_attachment = {};
531 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700532 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600533 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600536 }
537
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700539 m_commandBuffer->EndRenderPass();
540 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600541 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542}
543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
545 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600547 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500550 }
551
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700553 // Make sure depthWriteEnable is set so that Depth fail test will work
554 // correctly
555 // Make sure stencilTestEnable is set so that Stencil fail test will work
556 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600557 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800558 stencil.failOp = VK_STENCIL_OP_KEEP;
559 stencil.passOp = VK_STENCIL_OP_KEEP;
560 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
561 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600562
563 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
564 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600565 ds_ci.pNext = NULL;
566 ds_ci.depthTestEnable = VK_FALSE;
567 ds_ci.depthWriteEnable = VK_TRUE;
568 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
569 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 if (failMask & BsoFailDepthBounds) {
571 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600572 ds_ci.maxDepthBounds = 0.0f;
573 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600574 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600575 ds_ci.stencilTestEnable = VK_TRUE;
576 ds_ci.front = stencil;
577 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600578
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600579 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600580 pipelineobj.SetViewport(m_viewports);
581 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600583 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600584 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800585 commandBuffer->BindPipeline(pipelineobj);
586 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500587}
588
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600589class VkMaintenance1LayerTest : public VkLayerTest {
590 public:
591 protected:
592 VkMaintenance1LayerTest(){ m_enable_maintenance1_ext = true; }
593};
594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600595class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700596 public:
597 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600598};
599
Ian Elliott2c1daf52016-05-12 09:41:46 -0600600class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700601 public:
602 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600604};
605
Mark Muellerdfe37552016-07-07 14:47:42 -0600606class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700607 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 enum eTestEnFlags {
609 eDoubleDelete,
610 eInvalidDeviceOffset,
611 eInvalidMemoryOffset,
612 eBindNullBuffer,
613 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600614 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600615 };
616
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600618
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
620 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 return true;
622 }
623 VkDeviceSize offset_limit = 0;
624 if (eInvalidMemoryOffset == aTestFlag) {
625 VkBuffer vulkanBuffer;
626 VkBufferCreateInfo buffer_create_info = {};
627 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
628 buffer_create_info.size = 32;
629 buffer_create_info.usage = aBufferUsage;
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600632 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600633
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600634 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
636 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600637 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
638 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600639 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 }
644 if (eOffsetAlignment < offset_limit) {
645 return true;
646 }
647 return false;
648 }
649
650 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
652 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 if (eBindNullBuffer == aTestFlag) {
654 VulkanMemory = 0;
655 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
656 } else {
657 VkBufferCreateInfo buffer_create_info = {};
658 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
659 buffer_create_info.size = 32;
660 buffer_create_info.usage = aBufferUsage;
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663
664 CreateCurrent = true;
665
666 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 VkMemoryAllocateInfo memory_allocate_info = {};
670 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800671 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
673 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 if (!pass) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 return;
677 }
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600680 AllocateCurrent = true;
681 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
683 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600684 BoundCurrent = true;
685
686 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
687 }
688 }
689
690 ~VkBufferTest() {
691 if (CreateCurrent) {
692 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
693 }
694 if (AllocateCurrent) {
695 if (InvalidDeleteEn) {
696 union {
697 VkDeviceMemory device_memory;
698 unsigned long long index_access;
699 } bad_index;
700
701 bad_index.device_memory = VulkanMemory;
702 bad_index.index_access++;
703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600705 }
706 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
707 }
708 }
709
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600710 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600711
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600713
714 void TestDoubleDestroy() {
715 // Destroy the buffer but leave the flag set, which will cause
716 // the buffer to be destroyed again in the destructor.
717 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
718 }
719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700720 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600721 bool AllocateCurrent;
722 bool BoundCurrent;
723 bool CreateCurrent;
724 bool InvalidDeleteEn;
725
726 VkBuffer VulkanBuffer;
727 VkDevice VulkanDevice;
728 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729};
730
731class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600733 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600734 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700735 : BoundCurrent(false),
736 AttributeCount(aAttributeCount),
737 BindingCount(aBindingCount),
738 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600740 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
741 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700742 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600743
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600744 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
745 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
748 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
749 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
750 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
751 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600752
753 unsigned i = 0;
754 do {
755 VertexInputAttributeDescription[i].binding = BindId;
756 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
758 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 i++;
760 } while (AttributeCount < i);
761
762 i = 0;
763 do {
764 VertexInputBindingDescription[i].binding = BindId;
765 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 i++;
768 } while (BindingCount < i);
769 }
770
771 ~VkVerticesObj() {
772 if (VertexInputAttributeDescription) {
773 delete[] VertexInputAttributeDescription;
774 }
775 if (VertexInputBindingDescription) {
776 delete[] VertexInputBindingDescription;
777 }
778 }
779
780 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600781 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
782 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 return true;
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 VkDeviceSize *offsetList;
788 unsigned offsetCount;
789
790 if (aOffsetCount) {
791 offsetList = aOffsetList;
792 offsetCount = aOffsetCount;
793 } else {
794 offsetList = new VkDeviceSize[1]();
795 offsetCount = 1;
796 }
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600799 BoundCurrent = true;
800
801 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600802 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600803 }
804 }
805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700806 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600807 static uint32_t BindIdGenerator;
808
809 bool BoundCurrent;
810 unsigned AttributeCount;
811 unsigned BindingCount;
812 uint32_t BindId;
813
814 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
815 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
816 VkVertexInputBindingDescription *VertexInputBindingDescription;
817 VkConstantBufferObj VulkanMemoryBuffer;
818};
819
820uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500821// ********************************************************************************************************************
822// ********************************************************************************************************************
823// ********************************************************************************************************************
824// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700826 TEST_DESCRIPTION(
827 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
828 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600833 // Specify NULL for a pointer to a handle
834 // Expected to trigger an error with
835 // parameter_validation::validate_required_pointer
836 vkGetPhysicalDeviceFeatures(gpu(), NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
840 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600841 // Specify NULL for pointer to array count
842 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600843 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify 0 for a required array count
848 // Expected to trigger an error with parameter_validation::validate_array
849 VkViewport view_port = {};
850 m_commandBuffer->SetViewport(0, 0, &view_port);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600854 // Specify NULL for a required array
855 // Expected to trigger an error with parameter_validation::validate_array
856 m_commandBuffer->SetViewport(0, 1, NULL);
857 m_errorMonitor->VerifyFound();
858
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600860 // Specify VK_NULL_HANDLE for a required handle
861 // Expected to trigger an error with
862 // parameter_validation::validate_required_handle
863 vkUnmapMemory(device(), VK_NULL_HANDLE);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
867 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify VK_NULL_HANDLE for a required handle array entry
869 // Expected to trigger an error with
870 // parameter_validation::validate_required_handle_array
871 VkFence fence = VK_NULL_HANDLE;
872 vkResetFences(device(), 1, &fence);
873 m_errorMonitor->VerifyFound();
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600876 // Specify NULL for a required struct pointer
877 // Expected to trigger an error with
878 // parameter_validation::validate_struct_type
879 VkDeviceMemory memory = VK_NULL_HANDLE;
880 vkAllocateMemory(device(), NULL, NULL, &memory);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600884 // Specify 0 for a required VkFlags parameter
885 // Expected to trigger an error with parameter_validation::validate_flags
886 m_commandBuffer->SetStencilReference(0, 0);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify 0 for a required VkFlags array entry
891 // Expected to trigger an error with
892 // parameter_validation::validate_flags_array
893 VkSemaphore semaphore = VK_NULL_HANDLE;
894 VkPipelineStageFlags stageFlags = 0;
895 VkSubmitInfo submitInfo = {};
896 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
897 submitInfo.waitSemaphoreCount = 1;
898 submitInfo.pWaitSemaphores = &semaphore;
899 submitInfo.pWaitDstStageMask = &stageFlags;
900 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
901 m_errorMonitor->VerifyFound();
902}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600903
Dustin Gravesfce74c02016-05-10 11:42:58 -0600904TEST_F(VkLayerTest, ReservedParameter) {
905 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600910 // Specify 0 for a reserved VkFlags parameter
911 // Expected to trigger an error with
912 // parameter_validation::validate_reserved_flags
913 VkEvent event_handle = VK_NULL_HANDLE;
914 VkEventCreateInfo event_info = {};
915 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
916 event_info.flags = 1;
917 vkCreateEvent(device(), &event_info, NULL, &event_handle);
918 m_errorMonitor->VerifyFound();
919}
920
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600921TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700922 TEST_DESCRIPTION(
923 "Specify an invalid VkStructureType for a Vulkan "
924 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type
933 VkMemoryAllocateInfo alloc_info = {};
934 VkDeviceMemory memory = VK_NULL_HANDLE;
935 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
936 m_errorMonitor->VerifyFound();
937
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939 // Zero struct memory, effectively setting sType to
940 // VK_STRUCTURE_TYPE_APPLICATION_INFO
941 // Expected to trigger an error with
942 // parameter_validation::validate_struct_type_array
943 VkSubmitInfo submit_info = {};
944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
945 m_errorMonitor->VerifyFound();
946}
947
948TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600950
951 ASSERT_NO_FATAL_FAILURE(InitState());
952
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600954 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600955 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600956 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600957 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600958 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600959 // Zero-initialization will provide the correct sType
960 VkApplicationInfo app_info = {};
961 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
962 event_alloc_info.pNext = &app_info;
963 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
967 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
969 // a function that has allowed pNext structure types and specify
970 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600971 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600972 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600973 VkMemoryAllocateInfo memory_alloc_info = {};
974 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
975 memory_alloc_info.pNext = &app_info;
976 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600977 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600978}
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600981 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600982
983 ASSERT_NO_FATAL_FAILURE(InitState());
984
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
986 "does not fall within the begin..end "
987 "range of the core VkFormat "
988 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkFormat value
990 // Expected to trigger an error with
991 // parameter_validation::validate_ranged_enum
992 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600997 // Specify an invalid VkFlags bitmask value
998 // Expected to trigger an error with parameter_validation::validate_flags
999 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1001 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001002 m_errorMonitor->VerifyFound();
1003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001005 // Specify an invalid VkFlags array entry
1006 // Expected to trigger an error with
1007 // parameter_validation::validate_flags_array
1008 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001010 VkSubmitInfo submit_info = {};
1011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1012 submit_info.waitSemaphoreCount = 1;
1013 submit_info.pWaitSemaphores = &semaphore;
1014 submit_info.pWaitDstStageMask = &stage_flags;
1015 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkBool32 value
1020 // Expected to trigger a warning with
1021 // parameter_validation::validate_bool32
1022 VkSampler sampler = VK_NULL_HANDLE;
1023 VkSamplerCreateInfo sampler_info = {};
1024 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1025 sampler_info.pNext = NULL;
1026 sampler_info.magFilter = VK_FILTER_NEAREST;
1027 sampler_info.minFilter = VK_FILTER_NEAREST;
1028 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1029 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1030 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1031 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1032 sampler_info.mipLodBias = 1.0;
1033 sampler_info.maxAnisotropy = 1;
1034 sampler_info.compareEnable = VK_FALSE;
1035 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1036 sampler_info.minLod = 1.0;
1037 sampler_info.maxLod = 1.0;
1038 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1039 sampler_info.unnormalizedCoordinates = VK_FALSE;
1040 // Not VK_TRUE or VK_FALSE
1041 sampler_info.anisotropyEnable = 3;
1042 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1043 m_errorMonitor->VerifyFound();
1044}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045
1046TEST_F(VkLayerTest, FailedReturnValue) {
1047 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1048
1049 ASSERT_NO_FATAL_FAILURE(InitState());
1050
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001051 // Find an unsupported image format
1052 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1053 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1054 VkFormat format = static_cast<VkFormat>(f);
1055 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001057 unsupported = format;
1058 break;
1059 }
1060 }
1061
1062 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1064 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Specify an unsupported VkFormat value to generate a
1066 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1067 // Expected to trigger a warning from
1068 // parameter_validation::validate_result
1069 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1071 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001072 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1073 m_errorMonitor->VerifyFound();
1074 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001075}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077TEST_F(VkLayerTest, UpdateBufferAlignment) {
1078 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080
1081 ASSERT_NO_FATAL_FAILURE(InitState());
1082
1083 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1084 vk_testing::Buffer buffer;
1085 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1086
Tony Barbour552f6c02016-12-21 14:34:07 -07001087 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using dataSize that is < 0
1099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using dataSize that is > 65536
1105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001106 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001107 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1108 m_errorMonitor->VerifyFound();
1109
Tony Barbour552f6c02016-12-21 14:34:07 -07001110 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111}
1112
1113TEST_F(VkLayerTest, FillBufferAlignment) {
1114 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1115
1116 ASSERT_NO_FATAL_FAILURE(InitState());
1117
1118 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1119 vk_testing::Buffer buffer;
1120 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123
1124 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
1129 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1132 m_errorMonitor->VerifyFound();
1133
1134 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1137 m_errorMonitor->VerifyFound();
1138
Tony Barbour552f6c02016-12-21 14:34:07 -07001139 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140}
Dustin Graves40f35822016-06-23 11:12:53 -06001141
Cortd889ff92016-07-27 09:51:27 -07001142TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1143 VkResult err;
1144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001145 TEST_DESCRIPTION(
1146 "Attempt to use a non-solid polygon fill mode in a "
1147 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001148
1149 ASSERT_NO_FATAL_FAILURE(InitState());
1150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1151
1152 std::vector<const char *> device_extension_names;
1153 auto features = m_device->phy().features();
1154 // Artificially disable support for non-solid fill modes
1155 features.fillModeNonSolid = false;
1156 // The sacrificial device object
1157 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1158
1159 VkRenderpassObj render_pass(&test_device);
1160
1161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1163 pipeline_layout_ci.setLayoutCount = 0;
1164 pipeline_layout_ci.pSetLayouts = NULL;
1165
1166 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001168 ASSERT_VK_SUCCESS(err);
1169
1170 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1171 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1172 rs_ci.pNext = nullptr;
1173 rs_ci.lineWidth = 1.0f;
1174 rs_ci.rasterizerDiscardEnable = true;
1175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001176 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1177 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001178
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001179 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1181 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001182 {
1183 VkPipelineObj pipe(&test_device);
1184 pipe.AddShader(&vs);
1185 pipe.AddShader(&fs);
1186 pipe.AddColorAttachment();
1187 // Introduce failure by setting unsupported polygon mode
1188 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1189 pipe.SetRasterization(&rs_ci);
1190 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1191 }
1192 m_errorMonitor->VerifyFound();
1193
1194 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1196 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001197 {
1198 VkPipelineObj pipe(&test_device);
1199 pipe.AddShader(&vs);
1200 pipe.AddShader(&fs);
1201 pipe.AddColorAttachment();
1202 // Introduce failure by setting unsupported polygon mode
1203 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1204 pipe.SetRasterization(&rs_ci);
1205 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1206 }
1207 m_errorMonitor->VerifyFound();
1208
Cortd889ff92016-07-27 09:51:27 -07001209 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1210}
1211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001212#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214{
1215 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001216 VkFenceCreateInfo fenceInfo = {};
1217 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1218 fenceInfo.pNext = NULL;
1219 fenceInfo.flags = 0;
1220
Mike Weiblencce7ec72016-10-17 19:33:05 -06001221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001222
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001224
1225 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1226 vk_testing::Buffer buffer;
1227 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228
Tony Barbourfe3351b2015-07-28 10:17:20 -06001229 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001230 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001231 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232
1233 testFence.init(*m_device, fenceInfo);
1234
1235 // Bypass framework since it does the waits automatically
1236 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001237 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1239 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001240 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001241 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001242 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001243 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001246 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001247
1248 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001249 ASSERT_VK_SUCCESS( err );
1250
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001253
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001254 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001255}
1256
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258{
1259 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001260 VkFenceCreateInfo fenceInfo = {};
1261 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1262 fenceInfo.pNext = NULL;
1263 fenceInfo.flags = 0;
1264
Mike Weiblencce7ec72016-10-17 19:33:05 -06001265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001266
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267 ASSERT_NO_FATAL_FAILURE(InitState());
1268 ASSERT_NO_FATAL_FAILURE(InitViewport());
1269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1270
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001272 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001273 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274
1275 testFence.init(*m_device, fenceInfo);
1276
1277 // Bypass framework since it does the waits automatically
1278 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001279 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1281 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001282 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001283 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001284 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001287 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001288 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001289
1290 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 ASSERT_VK_SUCCESS( err );
1292
Jon Ashburnf19916e2016-01-11 13:12:43 -07001293 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 VkCommandBufferBeginInfo info = {};
1295 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1296 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001297 info.renderPass = VK_NULL_HANDLE;
1298 info.subpass = 0;
1299 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001300 info.occlusionQueryEnable = VK_FALSE;
1301 info.queryFlags = 0;
1302 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001303
1304 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001305 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001307 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001310
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001311TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1312 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1313
1314 ASSERT_NO_FATAL_FAILURE(InitState());
1315
1316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1317 VkBuffer buffer;
1318 VkBufferCreateInfo buf_info = {};
1319 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1320 buf_info.pNext = NULL;
1321 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1322 buf_info.size = 2048;
1323 buf_info.queueFamilyIndexCount = 0;
1324 buf_info.pQueueFamilyIndices = NULL;
1325 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1326 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1327 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1328 m_errorMonitor->VerifyFound();
1329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1331 VkImage image;
1332 VkImageCreateInfo image_create_info = {};
1333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1334 image_create_info.pNext = NULL;
1335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1336 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1337 image_create_info.extent.width = 512;
1338 image_create_info.extent.height = 64;
1339 image_create_info.extent.depth = 1;
1340 image_create_info.mipLevels = 1;
1341 image_create_info.arrayLayers = 1;
1342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1350 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1351 m_errorMonitor->VerifyFound();
1352}
1353
Dave Houlton829c0d82017-01-24 15:09:17 -07001354TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1355 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1356
1357 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001358 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001359 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1360
1361 // Mask out device features we don't want
1362 VkPhysicalDeviceFeatures desired_features = available_features;
1363 desired_features.sparseResidencyImage2D = VK_FALSE;
1364 desired_features.sparseResidencyImage3D = VK_FALSE;
1365 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1366
1367 VkImage image = VK_NULL_HANDLE;
1368 VkResult result = VK_RESULT_MAX_ENUM;
1369 VkImageCreateInfo image_create_info = {};
1370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1371 image_create_info.pNext = NULL;
1372 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1373 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1374 image_create_info.extent.width = 512;
1375 image_create_info.extent.height = 1;
1376 image_create_info.extent.depth = 1;
1377 image_create_info.mipLevels = 1;
1378 image_create_info.arrayLayers = 1;
1379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1381 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1383 image_create_info.queueFamilyIndexCount = 0;
1384 image_create_info.pQueueFamilyIndices = NULL;
1385 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1386 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1387
1388 // 1D image w/ sparse residency is an error
1389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1390 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392 if (VK_SUCCESS == result) {
1393 vkDestroyImage(m_device->device(), image, NULL);
1394 image = VK_NULL_HANDLE;
1395 }
1396
1397 // 2D image w/ sparse residency when feature isn't available
1398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1399 image_create_info.extent.height = 64;
1400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1401 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1402 m_errorMonitor->VerifyFound();
1403 if (VK_SUCCESS == result) {
1404 vkDestroyImage(m_device->device(), image, NULL);
1405 image = VK_NULL_HANDLE;
1406 }
1407
1408 // 3D image w/ sparse residency when feature isn't available
1409 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1410 image_create_info.extent.depth = 8;
1411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1412 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1413 m_errorMonitor->VerifyFound();
1414 if (VK_SUCCESS == result) {
1415 vkDestroyImage(m_device->device(), image, NULL);
1416 image = VK_NULL_HANDLE;
1417 }
1418}
1419
1420TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1421 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1422
1423 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001424 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001425 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1426
1427 // These tests all require that the device support sparse residency for 2D images
1428 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1429 return;
1430 }
1431
1432 // Mask out device features we don't want
1433 VkPhysicalDeviceFeatures desired_features = available_features;
1434 desired_features.sparseResidency2Samples = VK_FALSE;
1435 desired_features.sparseResidency4Samples = VK_FALSE;
1436 desired_features.sparseResidency8Samples = VK_FALSE;
1437 desired_features.sparseResidency16Samples = VK_FALSE;
1438 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1439
1440 VkImage image = VK_NULL_HANDLE;
1441 VkResult result = VK_RESULT_MAX_ENUM;
1442 VkImageCreateInfo image_create_info = {};
1443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1444 image_create_info.pNext = NULL;
1445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1446 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1447 image_create_info.extent.width = 64;
1448 image_create_info.extent.height = 64;
1449 image_create_info.extent.depth = 1;
1450 image_create_info.mipLevels = 1;
1451 image_create_info.arrayLayers = 1;
1452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1454 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1455 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1456 image_create_info.queueFamilyIndexCount = 0;
1457 image_create_info.pQueueFamilyIndices = NULL;
1458 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1459 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1460
1461 // 2D image w/ sparse residency and linear tiling is an error
1462 m_errorMonitor->SetDesiredFailureMsg(
1463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1464 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1465 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1466 m_errorMonitor->VerifyFound();
1467 if (VK_SUCCESS == result) {
1468 vkDestroyImage(m_device->device(), image, NULL);
1469 image = VK_NULL_HANDLE;
1470 }
1471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1472
1473 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1474 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482
1483 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1485 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1486 m_errorMonitor->VerifyFound();
1487 if (VK_SUCCESS == result) {
1488 vkDestroyImage(m_device->device(), image, NULL);
1489 image = VK_NULL_HANDLE;
1490 }
1491
1492 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1494 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1495 m_errorMonitor->VerifyFound();
1496 if (VK_SUCCESS == result) {
1497 vkDestroyImage(m_device->device(), image, NULL);
1498 image = VK_NULL_HANDLE;
1499 }
1500
1501 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1503 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1504 m_errorMonitor->VerifyFound();
1505 if (VK_SUCCESS == result) {
1506 vkDestroyImage(m_device->device(), image, NULL);
1507 image = VK_NULL_HANDLE;
1508 }
1509}
1510
Tobin Ehlisf11be982016-05-11 13:52:53 -06001511TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 TEST_DESCRIPTION(
1513 "Create a buffer and image, allocate memory, and bind the "
1514 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001515 VkResult err;
1516 bool pass;
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518
Tobin Ehlis077ded32016-05-12 17:39:13 -06001519 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001520 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001521 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001522 VkDeviceMemory mem; // buffer will be bound first
1523 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001524 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001525 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkBufferCreateInfo buf_info = {};
1528 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1529 buf_info.pNext = NULL;
1530 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1531 buf_info.size = 256;
1532 buf_info.queueFamilyIndexCount = 0;
1533 buf_info.pQueueFamilyIndices = NULL;
1534 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1535 buf_info.flags = 0;
1536 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1537 ASSERT_VK_SUCCESS(err);
1538
Tobin Ehlis077ded32016-05-12 17:39:13 -06001539 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540
1541 VkImageCreateInfo image_create_info = {};
1542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1543 image_create_info.pNext = NULL;
1544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1545 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1546 image_create_info.extent.width = 64;
1547 image_create_info.extent.height = 64;
1548 image_create_info.extent.depth = 1;
1549 image_create_info.mipLevels = 1;
1550 image_create_info.arrayLayers = 1;
1551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001552 // Image tiling must be optimal to trigger error when aliasing linear buffer
1553 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1556 image_create_info.queueFamilyIndexCount = 0;
1557 image_create_info.pQueueFamilyIndices = NULL;
1558 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1559 image_create_info.flags = 0;
1560
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1562 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1564 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001565
Tobin Ehlis077ded32016-05-12 17:39:13 -06001566 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1567
1568 VkMemoryAllocateInfo alloc_info = {};
1569 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1570 alloc_info.pNext = NULL;
1571 alloc_info.memoryTypeIndex = 0;
1572 // Ensure memory is big enough for both bindings
1573 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1575 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001576 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001577 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001579 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001580 return;
1581 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1583 ASSERT_VK_SUCCESS(err);
1584 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1585 ASSERT_VK_SUCCESS(err);
1586
Rene Lindsayd14f5572016-12-16 14:57:18 -07001587 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1588
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1592 m_errorMonitor->VerifyFound();
1593
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001594 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 // aliasing buffer2
1596 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1597 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001598 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001603 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001604 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001605 m_errorMonitor->VerifyFound();
1606
1607 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001608 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001609 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001610 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001611 vkFreeMemory(m_device->device(), mem, NULL);
1612 vkFreeMemory(m_device->device(), mem_img, NULL);
1613}
1614
Tobin Ehlis35372522016-05-12 08:32:31 -06001615TEST_F(VkLayerTest, InvalidMemoryMapping) {
1616 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1617 VkResult err;
1618 bool pass;
1619 ASSERT_NO_FATAL_FAILURE(InitState());
1620
1621 VkBuffer buffer;
1622 VkDeviceMemory mem;
1623 VkMemoryRequirements mem_reqs;
1624
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001625 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1626
Tobin Ehlis35372522016-05-12 08:32:31 -06001627 VkBufferCreateInfo buf_info = {};
1628 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1629 buf_info.pNext = NULL;
1630 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1631 buf_info.size = 256;
1632 buf_info.queueFamilyIndexCount = 0;
1633 buf_info.pQueueFamilyIndices = NULL;
1634 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1635 buf_info.flags = 0;
1636 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1637 ASSERT_VK_SUCCESS(err);
1638
1639 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1640 VkMemoryAllocateInfo alloc_info = {};
1641 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1642 alloc_info.pNext = NULL;
1643 alloc_info.memoryTypeIndex = 0;
1644
1645 // Ensure memory is big enough for both bindings
1646 static const VkDeviceSize allocation_size = 0x10000;
1647 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 if (!pass) {
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
1651 return;
1652 }
1653 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 uint8_t *pData;
1657 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001659 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1660 m_errorMonitor->VerifyFound();
1661 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001663 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1665 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1666 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001667 m_errorMonitor->VerifyFound();
1668
1669 // Unmap the memory to avoid re-map error
1670 vkUnmapMemory(m_device->device(), mem);
1671 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1673 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1674 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 m_errorMonitor->VerifyFound();
1676 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1678 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 m_errorMonitor->VerifyFound();
1680 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 vkUnmapMemory(m_device->device(), mem);
1683 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 ASSERT_VK_SUCCESS(err);
1688 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001689 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001695
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 // Now flush range that oversteps mapped range
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001701 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1707 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001708 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001710 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001711 mmr.size = VK_WHOLE_SIZE;
1712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1714 m_errorMonitor->VerifyFound();
1715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001716#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001717 // Some platforms have an atomsize of 1 which makes the test meaningless
1718 if (atom_size > 3) {
1719 // Now with an offset NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = 3; // Not a multiple of atom_size
1724 mmr.size = VK_WHOLE_SIZE;
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Now with a size NOT a multiple of the device limit
1730 vkUnmapMemory(m_device->device(), mem);
1731 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1732 ASSERT_VK_SUCCESS(err);
1733 mmr.offset = atom_size;
1734 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
1738 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001739#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1741 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 if (!pass) {
1743 vkFreeMemory(m_device->device(), mem, NULL);
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 return;
1746 }
1747 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1748 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1749
1750 vkDestroyBuffer(m_device->device(), buffer, NULL);
1751 vkFreeMemory(m_device->device(), mem, NULL);
1752}
1753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001754#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001755TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1756 VkResult err;
1757 bool pass;
1758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1760 // following declaration (which is temporarily being moved below):
1761 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001762 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001765 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001766 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001768
1769 ASSERT_NO_FATAL_FAILURE(InitState());
1770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1772#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1773 // Use the functions from the VK_KHR_android_surface extension without
1774 // enabling that extension:
1775
1776 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001777 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1779 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001780 pass = (err != VK_SUCCESS);
1781 ASSERT_TRUE(pass);
1782 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001783#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784
Ian Elliott3f06ce52016-04-29 14:46:21 -06001785#if defined(VK_USE_PLATFORM_MIR_KHR)
1786 // Use the functions from the VK_KHR_mir_surface extension without enabling
1787 // that extension:
1788
1789 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001790 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1793 pass = (err != VK_SUCCESS);
1794 ASSERT_TRUE(pass);
1795 m_errorMonitor->VerifyFound();
1796
1797 // Tell whether an mir_connection supports presentation:
1798 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1800 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001802#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001803
Ian Elliott3f06ce52016-04-29 14:46:21 -06001804#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1805 // Use the functions from the VK_KHR_wayland_surface extension without
1806 // enabling that extension:
1807
1808 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001809 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1811 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812 pass = (err != VK_SUCCESS);
1813 ASSERT_TRUE(pass);
1814 m_errorMonitor->VerifyFound();
1815
1816 // Tell whether an wayland_display supports presentation:
1817 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1819 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001821#endif // VK_USE_PLATFORM_WAYLAND_KHR
1822#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823
Ian Elliott3f06ce52016-04-29 14:46:21 -06001824#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001825 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1826 // TO NON-LINUX PLATFORMS:
1827 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 // Use the functions from the VK_KHR_win32_surface extension without
1829 // enabling that extension:
1830
1831 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001832 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1834 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 pass = (err != VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837 m_errorMonitor->VerifyFound();
1838
1839 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001841 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001842 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001843// Set this (for now, until all platforms are supported and tested):
1844#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001846#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1848 // TO NON-LINUX PLATFORMS:
1849 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001850#endif
1851#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001852 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1853 // that extension:
1854
1855 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001856 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1859 pass = (err != VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861 m_errorMonitor->VerifyFound();
1862
1863 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001864 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001865 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1867 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001868 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001869// Set this (for now, until all platforms are supported and tested):
1870#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001871#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001872
Ian Elliott12630812016-04-29 14:35:43 -06001873#if defined(VK_USE_PLATFORM_XLIB_KHR)
1874 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1875 // that extension:
1876
1877 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001878 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001880 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1881 pass = (err != VK_SUCCESS);
1882 ASSERT_TRUE(pass);
1883 m_errorMonitor->VerifyFound();
1884
1885 // Tell whether an Xlib VisualID supports presentation:
1886 Display *dpy = NULL;
1887 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001889 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1890 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001891// Set this (for now, until all platforms are supported and tested):
1892#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001893#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895// Use the functions from the VK_KHR_surface extension without enabling
1896// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001897
Ian Elliott489eec02016-05-05 14:12:44 -06001898#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001899 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 vkDestroySurfaceKHR(instance(), surface, NULL);
1902 m_errorMonitor->VerifyFound();
1903
1904 // Check if surface supports presentation:
1905 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001907 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1908 pass = (err != VK_SUCCESS);
1909 ASSERT_TRUE(pass);
1910 m_errorMonitor->VerifyFound();
1911
1912 // Check surface capabilities:
1913 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1915 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 pass = (err != VK_SUCCESS);
1917 ASSERT_TRUE(pass);
1918 m_errorMonitor->VerifyFound();
1919
1920 // Check surface formats:
1921 uint32_t format_count = 0;
1922 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1924 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface present modes:
1930 uint32_t present_mode_count = 0;
1931 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1933 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 pass = (err != VK_SUCCESS);
1935 ASSERT_TRUE(pass);
1936 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001937#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001938
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 // Use the functions from the VK_KHR_swapchain extension without enabling
1940 // that extension:
1941
1942 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1945 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001947 pass = (err != VK_SUCCESS);
1948 ASSERT_TRUE(pass);
1949 m_errorMonitor->VerifyFound();
1950
1951 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1953 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001954 pass = (err != VK_SUCCESS);
1955 ASSERT_TRUE(pass);
1956 m_errorMonitor->VerifyFound();
1957
Chris Forbeseb7d5502016-09-13 18:19:21 +12001958 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1959 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1960 VkFence fence;
1961 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1962
Ian Elliott1c32c772016-04-28 14:47:13 -06001963 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001965 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 pass = (err != VK_SUCCESS);
1967 ASSERT_TRUE(pass);
1968 m_errorMonitor->VerifyFound();
1969
Chris Forbeseb7d5502016-09-13 18:19:21 +12001970 vkDestroyFence(m_device->device(), fence, nullptr);
1971
Ian Elliott1c32c772016-04-28 14:47:13 -06001972 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001973 //
1974 // NOTE: Currently can't test this because a real swapchain is needed (as
1975 // opposed to the fake one we created) in order for the layer to lookup the
1976 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001977
1978 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1981 m_errorMonitor->VerifyFound();
1982}
Chris Forbes09368e42016-10-13 11:59:22 +13001983#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1986 VkResult err;
1987 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1990 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001991
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
1994 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001995 VkImage image;
1996 VkDeviceMemory mem;
1997 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001998
Karl Schultz6addd812016-02-02 17:17:23 -07001999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2000 const int32_t tex_width = 32;
2001 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002
Tony Barboureb254902015-07-15 12:50:33 -06002003 VkImageCreateInfo image_create_info = {};
2004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002005 image_create_info.pNext = NULL;
2006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2007 image_create_info.format = tex_format;
2008 image_create_info.extent.width = tex_width;
2009 image_create_info.extent.height = tex_height;
2010 image_create_info.extent.depth = 1;
2011 image_create_info.mipLevels = 1;
2012 image_create_info.arrayLayers = 1;
2013 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2016 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002018
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002019 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002020 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002021 mem_alloc.pNext = NULL;
2022 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002023
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002025 ASSERT_VK_SUCCESS(err);
2026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Mark Lobodzinski23065352015-05-29 09:32:35 -05002029 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002032 if (!pass) { // If we can't find any unmappable memory this test doesn't
2033 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002034 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002035 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002036 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002037
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002038 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040 ASSERT_VK_SUCCESS(err);
2041
2042 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map memory as if to initialize the image
2047 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002049
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002051
Chia-I Wuf7458c52015-10-26 21:10:41 +08002052 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002053 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002054}
2055
Karl Schultz6addd812016-02-02 17:17:23 -07002056TEST_F(VkLayerTest, RebindMemory) {
2057 VkResult err;
2058 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002061
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
2064 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002065 VkImage image;
2066 VkDeviceMemory mem1;
2067 VkDeviceMemory mem2;
2068 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2071 const int32_t tex_width = 32;
2072 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002073
Tony Barboureb254902015-07-15 12:50:33 -06002074 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2076 image_create_info.pNext = NULL;
2077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2078 image_create_info.format = tex_format;
2079 image_create_info.extent.width = tex_width;
2080 image_create_info.extent.height = tex_height;
2081 image_create_info.extent.depth = 1;
2082 image_create_info.mipLevels = 1;
2083 image_create_info.arrayLayers = 1;
2084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2085 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2087 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002089 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2091 mem_alloc.pNext = NULL;
2092 mem_alloc.allocationSize = 0;
2093 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002094
Karl Schultz6addd812016-02-02 17:17:23 -07002095 // Introduce failure, do NOT set memProps to
2096 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002097 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
2100
Karl Schultz6addd812016-02-02 17:17:23 -07002101 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
2103 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002105 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002108 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002114 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002115 ASSERT_VK_SUCCESS(err);
2116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 // Introduce validation failure, try to bind a different memory object to
2118 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002119 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002122
Chia-I Wuf7458c52015-10-26 21:10:41 +08002123 vkDestroyImage(m_device->device(), image, NULL);
2124 vkFreeMemory(m_device->device(), mem1, NULL);
2125 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002129 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2132 "submitted in SIGNALED state. Fences "
2133 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002134
2135 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002136 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2137 fenceInfo.pNext = NULL;
2138 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002139
Tony Barbour300a6082015-04-07 13:44:53 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitViewport());
2142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2143
Tony Barbour552f6c02016-12-21 14:34:07 -07002144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002145 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002146 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002147
2148 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002150 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2152 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002153 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002154 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002155 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002156 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002157 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002158 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002159 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002160
2161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002162 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002165}
Chris Forbes4e44c912016-06-16 10:20:00 +12002166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002168 TEST_DESCRIPTION(
2169 "Specify wrong usage for image then create conflicting view of image "
2170 "Initialize buffer with wrong usage then perform copy expecting errors "
2171 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002173
2174 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002175
Tony Barbourf887b162017-03-09 10:06:46 -07002176 auto format = find_depth_stencil_format(m_device);
2177 if (!format) {
2178 printf(" No Depth + Stencil format found. Skipped.\n");
2179 return;
2180 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002181
Tony Barbourf92621a2016-05-02 14:28:12 -06002182 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002183 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002184 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002185 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002186
Tony Barbourf92621a2016-05-02 14:28:12 -06002187 VkImageView dsv;
2188 VkImageViewCreateInfo dsvci = {};
2189 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2190 dsvci.image = image.handle();
2191 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002192 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002193 dsvci.subresourceRange.layerCount = 1;
2194 dsvci.subresourceRange.baseMipLevel = 0;
2195 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 // Create a view with depth / stencil aspect for image with different usage
2199 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002201 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002202
2203 // Initialize buffer with TRANSFER_DST usage
2204 vk_testing::Buffer buffer;
2205 VkMemoryPropertyFlags reqs = 0;
2206 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2207 VkBufferImageCopy region = {};
2208 region.bufferRowLength = 128;
2209 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002210 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 region.imageSubresource.layerCount = 1;
2212 region.imageExtent.height = 16;
2213 region.imageExtent.width = 16;
2214 region.imageExtent.depth = 1;
2215
Mark Lobodzinski80871462017-02-16 10:37:27 -07002216 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002217 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
Chris Forbesda581202016-10-06 18:25:26 +13002219 // two separate errors from this call:
2220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2224 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002225 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002226}
Tony Barbour75d79f02016-08-30 09:39:07 -06002227
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228TEST_F(VkLayerTest, LeakAnObject) {
2229 VkResult err;
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232
2233 // Note that we have to create a new device since destroying the
2234 // framework's device causes Teardown() to fail and just calling Teardown
2235 // will destroy the errorMonitor.
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002238
2239 ASSERT_NO_FATAL_FAILURE(InitState());
2240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002241 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<VkDeviceQueueCreateInfo> queue_info;
2243 queue_info.reserve(queue_props.size());
2244 std::vector<std::vector<float>> queue_priorities;
2245 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2246 VkDeviceQueueCreateInfo qi = {};
2247 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2248 qi.pNext = NULL;
2249 qi.queueFamilyIndex = i;
2250 qi.queueCount = queue_props[i].queueCount;
2251 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2252 qi.pQueuePriorities = queue_priorities[i].data();
2253 queue_info.push_back(qi);
2254 }
2255
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002257
2258 // The sacrificial device object
2259 VkDevice testDevice;
2260 VkDeviceCreateInfo device_create_info = {};
2261 auto features = m_device->phy().features();
2262 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2263 device_create_info.pNext = NULL;
2264 device_create_info.queueCreateInfoCount = queue_info.size();
2265 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002266 device_create_info.enabledLayerCount = 0;
2267 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002268 device_create_info.pEnabledFeatures = &features;
2269 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 VkFence fence;
2273 VkFenceCreateInfo fence_create_info = {};
2274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2275 fence_create_info.pNext = NULL;
2276 fence_create_info.flags = 0;
2277 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2278 ASSERT_VK_SUCCESS(err);
2279
2280 // Induce failure by not calling vkDestroyFence
2281 vkDestroyDevice(testDevice, NULL);
2282 m_errorMonitor->VerifyFound();
2283}
2284
2285TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002286 TEST_DESCRIPTION(
2287 "Allocate command buffers from one command pool and "
2288 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291
Cody Northropc31a84f2016-08-22 10:41:47 -06002292 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 VkCommandPool command_pool_one;
2294 VkCommandPool command_pool_two;
2295
2296 VkCommandPoolCreateInfo pool_create_info{};
2297 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2298 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2299 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002301 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002303 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002305 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002306 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002307 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002308 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002309 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002311 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002313 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
2315 m_errorMonitor->VerifyFound();
2316
2317 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2318 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2319}
2320
2321TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2322 VkResult err;
2323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002324 TEST_DESCRIPTION(
2325 "Allocate descriptor sets from one DS pool and "
2326 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2332
2333 VkDescriptorPoolSize ds_type_count = {};
2334 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2335 ds_type_count.descriptorCount = 1;
2336
2337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2339 ds_pool_ci.pNext = NULL;
2340 ds_pool_ci.flags = 0;
2341 ds_pool_ci.maxSets = 1;
2342 ds_pool_ci.poolSizeCount = 1;
2343 ds_pool_ci.pPoolSizes = &ds_type_count;
2344
2345 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_VK_SUCCESS(err);
2348
2349 // Create a second descriptor pool
2350 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 ASSERT_VK_SUCCESS(err);
2353
2354 VkDescriptorSetLayoutBinding dsl_binding = {};
2355 dsl_binding.binding = 0;
2356 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2357 dsl_binding.descriptorCount = 1;
2358 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2359 dsl_binding.pImmutableSamplers = NULL;
2360
2361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2363 ds_layout_ci.pNext = NULL;
2364 ds_layout_ci.bindingCount = 1;
2365 ds_layout_ci.pBindings = &dsl_binding;
2366
2367 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369 ASSERT_VK_SUCCESS(err);
2370
2371 VkDescriptorSet descriptorSet;
2372 VkDescriptorSetAllocateInfo alloc_info = {};
2373 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2374 alloc_info.descriptorSetCount = 1;
2375 alloc_info.descriptorPool = ds_pool_one;
2376 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378 ASSERT_VK_SUCCESS(err);
2379
2380 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2381
2382 m_errorMonitor->VerifyFound();
2383
2384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2385 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2386 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2387}
2388
2389TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002393
2394 ASSERT_NO_FATAL_FAILURE(InitState());
2395
2396 // Pass bogus handle into GetImageMemoryRequirements
2397 VkMemoryRequirements mem_reqs;
2398 uint64_t fakeImageHandle = 0xCADECADE;
2399 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2400
2401 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2402
2403 m_errorMonitor->VerifyFound();
2404}
2405
Mike Schuchardt17838902017-02-21 09:48:06 -07002406TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2407 TEST_DESCRIPTION(
2408 "Try to destroy a render pass object using a device other than the one it was created on. "
2409 "This should generate a distinct error from the invalid handle error.");
2410 // Create first device and renderpass
2411 ASSERT_NO_FATAL_FAILURE(InitState());
2412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2413
2414 // Create second device
2415 float priorities[] = {1.0f};
2416 VkDeviceQueueCreateInfo queue_info{};
2417 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2418 queue_info.pNext = NULL;
2419 queue_info.flags = 0;
2420 queue_info.queueFamilyIndex = 0;
2421 queue_info.queueCount = 1;
2422 queue_info.pQueuePriorities = &priorities[0];
2423
2424 VkDeviceCreateInfo device_create_info = {};
2425 auto features = m_device->phy().features();
2426 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2427 device_create_info.pNext = NULL;
2428 device_create_info.queueCreateInfoCount = 1;
2429 device_create_info.pQueueCreateInfos = &queue_info;
2430 device_create_info.enabledLayerCount = 0;
2431 device_create_info.ppEnabledLayerNames = NULL;
2432 device_create_info.pEnabledFeatures = &features;
2433
2434 VkDevice second_device;
2435 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2436
2437 // Try to destroy the renderpass from the first device using the second device
2438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2439 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2440 m_errorMonitor->VerifyFound();
2441
2442 vkDestroyDevice(second_device, NULL);
2443}
2444
Karl Schultz6addd812016-02-02 17:17:23 -07002445TEST_F(VkLayerTest, PipelineNotBound) {
2446 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002448 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002449
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002451
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002455 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2457 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458
2459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2461 ds_pool_ci.pNext = NULL;
2462 ds_pool_ci.maxSets = 1;
2463 ds_pool_ci.poolSizeCount = 1;
2464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002465
2466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002471 dsl_binding.binding = 0;
2472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 dsl_binding.descriptorCount = 1;
2474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2475 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002476
2477 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002478 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2479 ds_layout_ci.pNext = NULL;
2480 ds_layout_ci.bindingCount = 1;
2481 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002482
2483 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002490 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002491 alloc_info.descriptorPool = ds_pool;
2492 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
2496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2498 pipeline_layout_ci.pNext = NULL;
2499 pipeline_layout_ci.setLayoutCount = 1;
2500 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
2502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002504 ASSERT_VK_SUCCESS(err);
2505
Mark Youngad779052016-01-06 14:26:04 -07002506 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
Tony Barbour552f6c02016-12-21 14:34:07 -07002508 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002511 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002512
Chia-I Wuf7458c52015-10-26 21:10:41 +08002513 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2514 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002516}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002517
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002518TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2519 VkResult err;
2520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002521 TEST_DESCRIPTION(
2522 "Test validation check for an invalid memory type index "
2523 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002524
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002525 ASSERT_NO_FATAL_FAILURE(InitState());
2526
2527 // Create an image, allocate memory, set a bad typeIndex and then try to
2528 // bind it
2529 VkImage image;
2530 VkDeviceMemory mem;
2531 VkMemoryRequirements mem_reqs;
2532 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2533 const int32_t tex_width = 32;
2534 const int32_t tex_height = 32;
2535
2536 VkImageCreateInfo image_create_info = {};
2537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2538 image_create_info.pNext = NULL;
2539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2540 image_create_info.format = tex_format;
2541 image_create_info.extent.width = tex_width;
2542 image_create_info.extent.height = tex_height;
2543 image_create_info.extent.depth = 1;
2544 image_create_info.mipLevels = 1;
2545 image_create_info.arrayLayers = 1;
2546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2547 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2549 image_create_info.flags = 0;
2550
2551 VkMemoryAllocateInfo mem_alloc = {};
2552 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2553 mem_alloc.pNext = NULL;
2554 mem_alloc.allocationSize = 0;
2555 mem_alloc.memoryTypeIndex = 0;
2556
2557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2558 ASSERT_VK_SUCCESS(err);
2559
2560 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2561 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562
2563 // Introduce Failure, select invalid TypeIndex
2564 VkPhysicalDeviceMemoryProperties memory_info;
2565
2566 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2567 unsigned int i;
2568 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2569 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2570 mem_alloc.memoryTypeIndex = i;
2571 break;
2572 }
2573 }
2574 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002575 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002576 vkDestroyImage(m_device->device(), image, NULL);
2577 return;
2578 }
2579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002581
2582 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2583 ASSERT_VK_SUCCESS(err);
2584
2585 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2586 (void)err;
2587
2588 m_errorMonitor->VerifyFound();
2589
2590 vkDestroyImage(m_device->device(), image, NULL);
2591 vkFreeMemory(m_device->device(), mem, NULL);
2592}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002593
Karl Schultz6addd812016-02-02 17:17:23 -07002594TEST_F(VkLayerTest, BindInvalidMemory) {
2595 VkResult err;
2596 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002597
2598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002599
Cortf801b982017-01-17 18:10:21 -08002600 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002601 const int32_t tex_width = 256;
2602 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
2604 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2606 image_create_info.pNext = NULL;
2607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2608 image_create_info.format = tex_format;
2609 image_create_info.extent.width = tex_width;
2610 image_create_info.extent.height = tex_height;
2611 image_create_info.extent.depth = 1;
2612 image_create_info.mipLevels = 1;
2613 image_create_info.arrayLayers = 1;
2614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2617 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002618
Cortf801b982017-01-17 18:10:21 -08002619 VkBufferCreateInfo buffer_create_info = {};
2620 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2621 buffer_create_info.pNext = NULL;
2622 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002623 buffer_create_info.size = 4 * 1024 * 1024;
2624 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002625 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002626
Cortf801b982017-01-17 18:10:21 -08002627 // Create an image/buffer, allocate memory, free it, and then try to bind it
2628 {
2629 VkImage image = VK_NULL_HANDLE;
2630 VkBuffer buffer = VK_NULL_HANDLE;
2631 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2632 ASSERT_VK_SUCCESS(err);
2633 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2634 ASSERT_VK_SUCCESS(err);
2635 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2636 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2637 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2640 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2641 image_mem_alloc.allocationSize = image_mem_reqs.size;
2642 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2643 ASSERT_TRUE(pass);
2644 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2645 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2646 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2647 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2650 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2651 ASSERT_VK_SUCCESS(err);
2652 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2653 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 vkFreeMemory(device(), image_mem, NULL);
2656 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2659 err = vkBindImageMemory(device(), image, image_mem, 0);
2660 (void)err; // This may very well return an error.
2661 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Cortf801b982017-01-17 18:10:21 -08002663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2664 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2665 (void)err; // This may very well return an error.
2666 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002667
Cortf801b982017-01-17 18:10:21 -08002668 vkDestroyImage(m_device->device(), image, NULL);
2669 vkDestroyBuffer(m_device->device(), buffer, NULL);
2670 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002671
2672 // Try to bind memory to an object that already has a memory binding
2673 {
2674 VkImage image = VK_NULL_HANDLE;
2675 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2676 ASSERT_VK_SUCCESS(err);
2677 VkBuffer buffer = VK_NULL_HANDLE;
2678 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2679 ASSERT_VK_SUCCESS(err);
2680 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2681 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2682 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2683 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2684 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2685 image_alloc_info.allocationSize = image_mem_reqs.size;
2686 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2689 ASSERT_TRUE(pass);
2690 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2691 ASSERT_TRUE(pass);
2692 VkDeviceMemory image_mem, buffer_mem;
2693 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2694 ASSERT_VK_SUCCESS(err);
2695 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2696 ASSERT_VK_SUCCESS(err);
2697
2698 err = vkBindImageMemory(device(), image, image_mem, 0);
2699 ASSERT_VK_SUCCESS(err);
2700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
2704
2705 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2706 ASSERT_VK_SUCCESS(err);
2707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2708 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2709 (void)err; // This may very well return an error.
2710 m_errorMonitor->VerifyFound();
2711
2712 vkFreeMemory(device(), image_mem, NULL);
2713 vkFreeMemory(device(), buffer_mem, NULL);
2714 vkDestroyImage(device(), image, NULL);
2715 vkDestroyBuffer(device(), buffer, NULL);
2716 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002717
Cort Strattonde748202017-02-17 12:50:01 -08002718 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002719 {
2720 VkImage image = VK_NULL_HANDLE;
2721 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2722 ASSERT_VK_SUCCESS(err);
2723 VkBuffer buffer = VK_NULL_HANDLE;
2724 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2725 ASSERT_VK_SUCCESS(err);
2726 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2727 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2728 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2729 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2730 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Leave some extra space for alignment wiggle room
2732 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002733 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002734 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002735 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2736 ASSERT_TRUE(pass);
2737 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2738 ASSERT_TRUE(pass);
2739 VkDeviceMemory image_mem, buffer_mem;
2740 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2741 ASSERT_VK_SUCCESS(err);
2742 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2743 ASSERT_VK_SUCCESS(err);
2744
Cort Strattonde748202017-02-17 12:50:01 -08002745 // Test unaligned memory offset
2746 {
2747 if (image_mem_reqs.alignment > 1) {
2748 VkDeviceSize image_offset = 1;
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2750 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753 }
Cort6c7dff72017-01-27 18:34:50 -08002754
Cort Strattonde748202017-02-17 12:50:01 -08002755 if (buffer_mem_reqs.alignment > 1) {
2756 VkDeviceSize buffer_offset = 1;
2757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2758 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2759 (void)err; // This may very well return an error.
2760 m_errorMonitor->VerifyFound();
2761 }
2762 }
2763
2764 // Test memory offsets outside the memory allocation
2765 {
2766 VkDeviceSize image_offset =
2767 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2769 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2770 (void)err; // This may very well return an error.
2771 m_errorMonitor->VerifyFound();
2772
2773 VkDeviceSize buffer_offset =
2774 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2776 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2777 (void)err; // This may very well return an error.
2778 m_errorMonitor->VerifyFound();
2779 }
2780
2781 // Test memory offsets within the memory allocation, but which leave too little memory for
2782 // the resource.
2783 {
2784 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2785 if (image_offset > 0) {
2786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2787 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2788 (void)err; // This may very well return an error.
2789 m_errorMonitor->VerifyFound();
2790 }
2791
2792 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2793 if (buffer_offset > 0) {
2794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2795 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2796 (void)err; // This may very well return an error.
2797 m_errorMonitor->VerifyFound();
2798 }
2799 }
Cort6c7dff72017-01-27 18:34:50 -08002800
2801 vkFreeMemory(device(), image_mem, NULL);
2802 vkFreeMemory(device(), buffer_mem, NULL);
2803 vkDestroyImage(device(), image, NULL);
2804 vkDestroyBuffer(device(), buffer, NULL);
2805 }
2806
Cort Stratton4c38bb52017-01-28 13:33:10 -08002807 // Try to bind memory to an object with an invalid memory type
2808 {
2809 VkImage image = VK_NULL_HANDLE;
2810 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2811 ASSERT_VK_SUCCESS(err);
2812 VkBuffer buffer = VK_NULL_HANDLE;
2813 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2814 ASSERT_VK_SUCCESS(err);
2815 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2816 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2817 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2818 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2819 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2820 image_alloc_info.allocationSize = image_mem_reqs.size;
2821 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002823 // Create a mask of available memory types *not* supported by these resources,
2824 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002825 VkPhysicalDeviceMemoryProperties memory_properties = {};
2826 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002827 VkDeviceMemory image_mem, buffer_mem;
2828
Cort Stratton4c38bb52017-01-28 13:33:10 -08002829 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2836 err = vkBindImageMemory(device(), image, image_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
2841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 uint32_t buffer_unsupported_mem_type_bits =
2843 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002845 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2846 ASSERT_TRUE(pass);
2847 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2848 ASSERT_VK_SUCCESS(err);
2849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2850 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2851 (void)err; // This may very well return an error.
2852 m_errorMonitor->VerifyFound();
2853 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002854 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002855
Cort Stratton4c38bb52017-01-28 13:33:10 -08002856 vkDestroyImage(device(), image, NULL);
2857 vkDestroyBuffer(device(), buffer, NULL);
2858 }
2859
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 // Try to bind memory to an image created with sparse memory flags
2861 {
2862 VkImageCreateInfo sparse_image_create_info = image_create_info;
2863 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2864 VkImageFormatProperties image_format_properties = {};
2865 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2866 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2867 sparse_image_create_info.usage, sparse_image_create_info.flags,
2868 &image_format_properties);
2869 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2870 // most likely means sparse formats aren't supported here; skip this test.
2871 } else {
2872 ASSERT_VK_SUCCESS(err);
2873 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002874 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002875 return;
2876 } else {
2877 VkImage sparse_image = VK_NULL_HANDLE;
2878 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2879 ASSERT_VK_SUCCESS(err);
2880 VkMemoryRequirements sparse_mem_reqs = {};
2881 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2882 if (sparse_mem_reqs.memoryTypeBits != 0) {
2883 VkMemoryAllocateInfo sparse_mem_alloc = {};
2884 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2885 sparse_mem_alloc.pNext = NULL;
2886 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2887 sparse_mem_alloc.memoryTypeIndex = 0;
2888 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2889 ASSERT_TRUE(pass);
2890 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2891 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2892 ASSERT_VK_SUCCESS(err);
2893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2894 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2895 // This may very well return an error.
2896 (void)err;
2897 m_errorMonitor->VerifyFound();
2898 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2899 }
2900 vkDestroyImage(m_device->device(), sparse_image, NULL);
2901 }
2902 }
2903 }
2904
2905 // Try to bind memory to a buffer created with sparse memory flags
2906 {
2907 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2908 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2909 if (!m_device->phy().features().sparseResidencyBuffer) {
2910 // most likely means sparse formats aren't supported here; skip this test.
2911 } else {
2912 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2913 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2914 ASSERT_VK_SUCCESS(err);
2915 VkMemoryRequirements sparse_mem_reqs = {};
2916 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2917 if (sparse_mem_reqs.memoryTypeBits != 0) {
2918 VkMemoryAllocateInfo sparse_mem_alloc = {};
2919 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2920 sparse_mem_alloc.pNext = NULL;
2921 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2922 sparse_mem_alloc.memoryTypeIndex = 0;
2923 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2924 ASSERT_TRUE(pass);
2925 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2926 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2927 ASSERT_VK_SUCCESS(err);
2928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2929 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2930 // This may very well return an error.
2931 (void)err;
2932 m_errorMonitor->VerifyFound();
2933 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2934 }
2935 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2936 }
2937 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002938}
2939
Karl Schultz6addd812016-02-02 17:17:23 -07002940TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2941 VkResult err;
2942 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002945
Tobin Ehlisec598302015-09-15 15:02:17 -06002946 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
Karl Schultz6addd812016-02-02 17:17:23 -07002948 // Create an image object, allocate memory, destroy the object and then try
2949 // to bind it
2950 VkImage image;
2951 VkDeviceMemory mem;
2952 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002953
Karl Schultz6addd812016-02-02 17:17:23 -07002954 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2955 const int32_t tex_width = 32;
2956 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
2958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2960 image_create_info.pNext = NULL;
2961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2962 image_create_info.format = tex_format;
2963 image_create_info.extent.width = tex_width;
2964 image_create_info.extent.height = tex_height;
2965 image_create_info.extent.depth = 1;
2966 image_create_info.mipLevels = 1;
2967 image_create_info.arrayLayers = 1;
2968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2969 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2971 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002973 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002974 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2975 mem_alloc.pNext = NULL;
2976 mem_alloc.allocationSize = 0;
2977 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002978
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002983
2984 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002985 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002986 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002987
2988 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002990 ASSERT_VK_SUCCESS(err);
2991
2992 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002994 ASSERT_VK_SUCCESS(err);
2995
2996 // Now Try to bind memory to this destroyed object
2997 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2998 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002999 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003001 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003002
Chia-I Wuf7458c52015-10-26 21:10:41 +08003003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003004}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003005
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003006TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3007 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3008
3009 ASSERT_NO_FATAL_FAILURE(InitState());
3010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3011
3012 VkVertexInputBindingDescription input_binding;
3013 memset(&input_binding, 0, sizeof(input_binding));
3014
3015 VkVertexInputAttributeDescription input_attribs;
3016 memset(&input_attribs, 0, sizeof(input_attribs));
3017
3018 // Pick a really bad format for this purpose and make sure it should fail
3019 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3020 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3021 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003022 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003023 return;
3024 }
3025
3026 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003027 char const *vsSource =
3028 "#version 450\n"
3029 "\n"
3030 "out gl_PerVertex {\n"
3031 " vec4 gl_Position;\n"
3032 "};\n"
3033 "void main(){\n"
3034 " gl_Position = vec4(1);\n"
3035 "}\n";
3036 char const *fsSource =
3037 "#version 450\n"
3038 "\n"
3039 "layout(location=0) out vec4 color;\n"
3040 "void main(){\n"
3041 " color = vec4(1);\n"
3042 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003043
3044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3047
3048 VkPipelineObj pipe(m_device);
3049 pipe.AddColorAttachment();
3050 pipe.AddShader(&vs);
3051 pipe.AddShader(&fs);
3052
3053 pipe.AddVertexInputBindings(&input_binding, 1);
3054 pipe.AddVertexInputAttribs(&input_attribs, 1);
3055
3056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3059
3060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3061
3062 m_errorMonitor->VerifyFound();
3063}
3064
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003065TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003066 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3067 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003068
3069 VkMemoryPropertyFlags reqs = 0;
3070 VkImageCreateInfo image_create_info = {};
3071 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3072 image_create_info.pNext = NULL;
3073 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3074 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3075 image_create_info.extent.width = 256;
3076 image_create_info.extent.height = 256;
3077 image_create_info.extent.depth = 1;
3078 image_create_info.mipLevels = 1;
3079 image_create_info.arrayLayers = 1;
3080 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3081 image_create_info.flags = 0;
3082
3083 VkImageBlit blit_region = {};
3084 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3085 blit_region.srcSubresource.baseArrayLayer = 0;
3086 blit_region.srcSubresource.layerCount = 1;
3087 blit_region.srcSubresource.mipLevel = 0;
3088 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3089 blit_region.dstSubresource.baseArrayLayer = 0;
3090 blit_region.dstSubresource.layerCount = 1;
3091 blit_region.dstSubresource.mipLevel = 0;
3092
3093 // Create two images, the source with sampleCount = 2, and attempt to blit
3094 // between them
3095 {
3096 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003098 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003099 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003102 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003105 m_errorMonitor->SetDesiredFailureMsg(
3106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_errorMonitor->VerifyFound();
3111 m_commandBuffer->EndCommandBuffer();
3112 }
3113
3114 // Create two images, the dest with sampleCount = 4, and attempt to blit
3115 // between them
3116 {
3117 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003118 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003119 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003123 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003125 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003126 m_errorMonitor->SetDesiredFailureMsg(
3127 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3128 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3130 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003131 m_errorMonitor->VerifyFound();
3132 m_commandBuffer->EndCommandBuffer();
3133 }
3134
3135 VkBufferImageCopy copy_region = {};
3136 copy_region.bufferRowLength = 128;
3137 copy_region.bufferImageHeight = 128;
3138 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3139 copy_region.imageSubresource.layerCount = 1;
3140 copy_region.imageExtent.height = 64;
3141 copy_region.imageExtent.width = 64;
3142 copy_region.imageExtent.depth = 1;
3143
3144 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3145 // buffer to image
3146 {
3147 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003148 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3149 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003151 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003152 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003153 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003154 m_errorMonitor->SetDesiredFailureMsg(
3155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3156 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3158 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003159 m_errorMonitor->VerifyFound();
3160 m_commandBuffer->EndCommandBuffer();
3161 }
3162
3163 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3164 // image to buffer
3165 {
3166 vk_testing::Buffer dst_buffer;
3167 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3168 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003170 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003172 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003173 m_errorMonitor->SetDesiredFailureMsg(
3174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003177 dst_buffer.handle(), 1, &copy_region);
3178 m_errorMonitor->VerifyFound();
3179 m_commandBuffer->EndCommandBuffer();
3180 }
3181}
3182
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003183TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003184 ASSERT_NO_FATAL_FAILURE(InitState());
3185
3186 VkImageObj src_image(m_device);
3187 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3188 VkImageObj dst_image(m_device);
3189 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3190 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003191 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003192
3193 VkImageBlit blitRegion = {};
3194 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3195 blitRegion.srcSubresource.baseArrayLayer = 0;
3196 blitRegion.srcSubresource.layerCount = 1;
3197 blitRegion.srcSubresource.mipLevel = 0;
3198 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3199 blitRegion.dstSubresource.baseArrayLayer = 0;
3200 blitRegion.dstSubresource.layerCount = 1;
3201 blitRegion.dstSubresource.mipLevel = 0;
3202
Dave Houlton34df4cb2016-12-01 16:43:06 -07003203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3204
3205 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3206 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
3208 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003209 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 m_errorMonitor->VerifyFound();
3214
Dave Houlton34df4cb2016-12-01 16:43:06 -07003215 // Test should generate 2 VU failures
3216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218
3219 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003220 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3221 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003222
Dave Houlton34df4cb2016-12-01 16:43:06 -07003223 // TODO: Note that this only verifies that at least one of the VU enums was found
3224 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003225 m_errorMonitor->VerifyFound();
3226
Tony Barbour552f6c02016-12-21 14:34:07 -07003227 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228}
3229
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003230TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3231 VkResult err;
3232 bool pass;
3233
3234 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3235 ASSERT_NO_FATAL_FAILURE(InitState());
3236
3237 // If w/d/h granularity is 1, test is not meaningful
3238 // TODO: When virtual device limits are available, create a set of limits for this test that
3239 // will always have a granularity of > 1 for w, h, and d
3240 auto index = m_device->graphics_queue_node_index_;
3241 auto queue_family_properties = m_device->phy().queue_properties();
3242
3243 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3244 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3245 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3246 return;
3247 }
3248
3249 // Create two images of different types and try to copy between them
3250 VkImage srcImage;
3251 VkImage dstImage;
3252 VkDeviceMemory srcMem;
3253 VkDeviceMemory destMem;
3254 VkMemoryRequirements memReqs;
3255
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003256 VkImageCreateInfo image_create_info = {};
3257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3258 image_create_info.pNext = NULL;
3259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3260 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3261 image_create_info.extent.width = 32;
3262 image_create_info.extent.height = 32;
3263 image_create_info.extent.depth = 1;
3264 image_create_info.mipLevels = 1;
3265 image_create_info.arrayLayers = 4;
3266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3268 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3269 image_create_info.flags = 0;
3270
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_VK_SUCCESS(err);
3273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 // Allocate memory
3278 VkMemoryAllocateInfo memAlloc = {};
3279 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3280 memAlloc.pNext = NULL;
3281 memAlloc.allocationSize = 0;
3282 memAlloc.memoryTypeIndex = 0;
3283
3284 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3285 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003287 ASSERT_TRUE(pass);
3288 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3289 ASSERT_VK_SUCCESS(err);
3290
3291 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3292 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 ASSERT_VK_SUCCESS(err);
3295 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3296 ASSERT_VK_SUCCESS(err);
3297
3298 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3299 ASSERT_VK_SUCCESS(err);
3300 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3301 ASSERT_VK_SUCCESS(err);
3302
Tony Barbour552f6c02016-12-21 14:34:07 -07003303 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 VkImageCopy copyRegion;
3305 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3306 copyRegion.srcSubresource.mipLevel = 0;
3307 copyRegion.srcSubresource.baseArrayLayer = 0;
3308 copyRegion.srcSubresource.layerCount = 1;
3309 copyRegion.srcOffset.x = 0;
3310 copyRegion.srcOffset.y = 0;
3311 copyRegion.srcOffset.z = 0;
3312 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3313 copyRegion.dstSubresource.mipLevel = 0;
3314 copyRegion.dstSubresource.baseArrayLayer = 0;
3315 copyRegion.dstSubresource.layerCount = 1;
3316 copyRegion.dstOffset.x = 0;
3317 copyRegion.dstOffset.y = 0;
3318 copyRegion.dstOffset.z = 0;
3319 copyRegion.extent.width = 1;
3320 copyRegion.extent.height = 1;
3321 copyRegion.extent.depth = 1;
3322
3323 // Introduce failure by setting srcOffset to a bad granularity value
3324 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3326 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003327 m_errorMonitor->VerifyFound();
3328
3329 // Introduce failure by setting extent to a bad granularity value
3330 copyRegion.srcOffset.y = 0;
3331 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3333 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334 m_errorMonitor->VerifyFound();
3335
3336 // Now do some buffer/image copies
3337 vk_testing::Buffer buffer;
3338 VkMemoryPropertyFlags reqs = 0;
3339 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3340 VkBufferImageCopy region = {};
3341 region.bufferOffset = 0;
3342 region.bufferRowLength = 3;
3343 region.bufferImageHeight = 128;
3344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3345 region.imageSubresource.layerCount = 1;
3346 region.imageExtent.height = 16;
3347 region.imageExtent.width = 16;
3348 region.imageExtent.depth = 1;
3349 region.imageOffset.x = 0;
3350 region.imageOffset.y = 0;
3351 region.imageOffset.z = 0;
3352
3353 // Introduce failure by setting bufferRowLength to a bad granularity value
3354 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3356 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3357 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003358 m_errorMonitor->VerifyFound();
3359 region.bufferRowLength = 128;
3360
3361 // Introduce failure by setting bufferOffset to a bad granularity value
3362 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3365 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003366 m_errorMonitor->VerifyFound();
3367 region.bufferOffset = 0;
3368
3369 // Introduce failure by setting bufferImageHeight to a bad granularity value
3370 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferImageHeight = 128;
3376
3377 // Introduce failure by setting imageExtent to a bad granularity value
3378 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.imageExtent.width = 16;
3384
3385 // Introduce failure by setting imageOffset to a bad granularity value
3386 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391
Tony Barbour552f6c02016-12-21 14:34:07 -07003392 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003393
3394 vkDestroyImage(m_device->device(), srcImage, NULL);
3395 vkDestroyImage(m_device->device(), dstImage, NULL);
3396 vkFreeMemory(m_device->device(), srcMem, NULL);
3397 vkFreeMemory(m_device->device(), destMem, NULL);
3398}
3399
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003401 TEST_DESCRIPTION(
3402 "Submit command buffer created using one queue family and "
3403 "attempt to submit them on a queue created in a different "
3404 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003405
Cody Northropc31a84f2016-08-22 10:41:47 -06003406 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003407
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003408 // This test is meaningless unless we have multiple queue families
3409 auto queue_family_properties = m_device->phy().queue_properties();
3410 if (queue_family_properties.size() < 2) {
3411 return;
3412 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003414 // Get safe index of another queue family
3415 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3416 ASSERT_NO_FATAL_FAILURE(InitState());
3417 // Create a second queue using a different queue family
3418 VkQueue other_queue;
3419 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3420
3421 // Record an empty cmd buffer
3422 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3423 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3424 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3425 vkEndCommandBuffer(m_commandBuffer->handle());
3426
3427 // And submit on the wrong queue
3428 VkSubmitInfo submit_info = {};
3429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3430 submit_info.commandBufferCount = 1;
3431 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003432 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003433
3434 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003435}
3436
Chris Forbes4c24a922016-11-16 08:59:10 +13003437TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3438 ASSERT_NO_FATAL_FAILURE(InitState());
3439
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003440 // There are no attachments, but refer to attachment 0.
3441 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003442 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003443 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003444 };
3445
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003446 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003447 VkRenderPass rp;
3448
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003449 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003451 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3452 m_errorMonitor->VerifyFound();
3453}
3454
Chris Forbesa58c4522016-09-28 15:19:39 +13003455TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3456 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3457 ASSERT_NO_FATAL_FAILURE(InitState());
3458
3459 // A renderpass with two subpasses, both writing the same attachment.
3460 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3462 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003465 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003466 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003467 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3468 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003469 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003470 VkSubpassDependency dep = {0,
3471 1,
3472 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3473 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3474 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3475 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3476 VK_DEPENDENCY_BY_REGION_BIT};
3477 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 VkRenderPass rp;
3479 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3480 ASSERT_VK_SUCCESS(err);
3481
3482 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003484 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003487 VkFramebuffer fb;
3488 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3489 ASSERT_VK_SUCCESS(err);
3490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003491 char const *vsSource =
3492 "#version 450\n"
3493 "void main() { gl_Position = vec4(1); }\n";
3494 char const *fsSource =
3495 "#version 450\n"
3496 "layout(location=0) out vec4 color;\n"
3497 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3501 VkPipelineObj pipe(m_device);
3502 pipe.AddColorAttachment();
3503 pipe.AddShader(&vs);
3504 pipe.AddShader(&fs);
3505 VkViewport view_port = {};
3506 m_viewports.push_back(view_port);
3507 pipe.SetViewport(m_viewports);
3508 VkRect2D rect = {};
3509 m_scissors.push_back(rect);
3510 pipe.SetScissor(m_scissors);
3511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003512 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513 VkPipelineLayout pl;
3514 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3515 ASSERT_VK_SUCCESS(err);
3516 pipe.CreateVKPipeline(pl, rp);
3517
Tony Barbour552f6c02016-12-21 14:34:07 -07003518 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003519
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3521 nullptr,
3522 rp,
3523 fb,
3524 {{
3525 0, 0,
3526 },
3527 {32, 32}},
3528 0,
3529 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003530
3531 // subtest 1: bind in the wrong subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003535 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
3541 // subtest 2: bind in correct subpass, then transition to next subpass
3542 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3543 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3544 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003546 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3547 m_errorMonitor->VerifyFound();
3548
3549 vkCmdEndRenderPass(m_commandBuffer->handle());
3550
Tony Barbour552f6c02016-12-21 14:34:07 -07003551 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003552
3553 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3556}
3557
Tony Barbour4e919972016-08-09 13:27:40 -06003558TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003559 TEST_DESCRIPTION(
3560 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3561 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003562 ASSERT_NO_FATAL_FAILURE(InitState());
3563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3566 "Cannot execute a render pass with renderArea "
3567 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003568
3569 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3570 m_renderPassBeginInfo.renderArea.extent.width = 257;
3571 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003572 m_commandBuffer->BeginCommandBuffer();
3573 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003574 m_errorMonitor->VerifyFound();
3575}
3576
3577TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003578 TEST_DESCRIPTION(
3579 "Generate INDEPENDENT_BLEND by disabling independent "
3580 "blend and then specifying different blend states for two "
3581 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003582 VkPhysicalDeviceFeatures features = {};
3583 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Invalid Pipeline CreateInfo: If independent blend feature not "
3588 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003589
Cody Northropc31a84f2016-08-22 10:41:47 -06003590 VkDescriptorSetObj descriptorSet(m_device);
3591 descriptorSet.AppendDummy();
3592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003593
Cody Northropc31a84f2016-08-22 10:41:47 -06003594 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003595 // Create a renderPass with two color attachments
3596 VkAttachmentReference attachments[2] = {};
3597 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 VkSubpassDescription subpass = {};
3602 subpass.pColorAttachments = attachments;
3603 subpass.colorAttachmentCount = 2;
3604
3605 VkRenderPassCreateInfo rpci = {};
3606 rpci.subpassCount = 1;
3607 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003608 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 VkAttachmentDescription attach_desc[2] = {};
3611 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3612 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3613 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3614 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3615 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3616 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3617 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3618 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003619
Tony Barbourffd60bd2017-03-09 12:04:55 -07003620 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003621 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3622
3623 VkRenderPass renderpass;
3624 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003627
Cody Northropc31a84f2016-08-22 10:41:47 -06003628 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3629 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3630 att_state1.blendEnable = VK_TRUE;
3631 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3632 att_state2.blendEnable = VK_FALSE;
3633 pipeline.AddColorAttachment(0, &att_state1);
3634 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003636 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003637 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003638}
3639
Mike Weiblen40b160e2017-02-06 19:21:52 -07003640// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3641TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3642 TEST_DESCRIPTION(
3643 "Create a graphics pipeline that is incompatible with the requirements "
3644 "of its contained Renderpass/subpasses.");
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646
3647 VkDescriptorSetObj ds_obj(m_device);
3648 ds_obj.AppendDummy();
3649 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3650
3651 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3652
3653 VkPipelineColorBlendAttachmentState att_state1 = {};
3654 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3655 att_state1.blendEnable = VK_TRUE;
3656
3657 VkRenderpassObj rp_obj(m_device);
3658
3659 {
3660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3661 VkPipelineObj pipeline(m_device);
3662 pipeline.AddShader(&vs_obj);
3663 pipeline.AddColorAttachment(0, &att_state1);
3664
3665 VkGraphicsPipelineCreateInfo info = {};
3666 pipeline.InitGraphicsPipelineCreateInfo(&info);
3667 info.pColorBlendState = nullptr;
3668
3669 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3670 m_errorMonitor->VerifyFound();
3671 }
3672}
3673
Chris Forbes26ec2122016-11-29 08:58:33 +13003674#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003675TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3676 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3677 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003678 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3681 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003682
3683 // Create a renderPass with a single color attachment
3684 VkAttachmentReference attach = {};
3685 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3686 VkSubpassDescription subpass = {};
3687 VkRenderPassCreateInfo rpci = {};
3688 rpci.subpassCount = 1;
3689 rpci.pSubpasses = &subpass;
3690 rpci.attachmentCount = 1;
3691 VkAttachmentDescription attach_desc = {};
3692 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3693 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3694 rpci.pAttachments = &attach_desc;
3695 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3696 VkRenderPass rp;
3697 subpass.pDepthStencilAttachment = &attach;
3698 subpass.pColorAttachments = NULL;
3699 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3700 m_errorMonitor->VerifyFound();
3701}
Chris Forbes26ec2122016-11-29 08:58:33 +13003702#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003703
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003704TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003705 TEST_DESCRIPTION(
3706 "Create a framebuffer where a subpass has a preserve "
3707 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003708
3709 ASSERT_NO_FATAL_FAILURE(InitState());
3710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003713
3714 VkAttachmentReference color_attach = {};
3715 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3716 color_attach.attachment = 0;
3717 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3718 VkSubpassDescription subpass = {};
3719 subpass.colorAttachmentCount = 1;
3720 subpass.pColorAttachments = &color_attach;
3721 subpass.preserveAttachmentCount = 1;
3722 subpass.pPreserveAttachments = &preserve_attachment;
3723
3724 VkRenderPassCreateInfo rpci = {};
3725 rpci.subpassCount = 1;
3726 rpci.pSubpasses = &subpass;
3727 rpci.attachmentCount = 1;
3728 VkAttachmentDescription attach_desc = {};
3729 attach_desc.format = VK_FORMAT_UNDEFINED;
3730 rpci.pAttachments = &attach_desc;
3731 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3732 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003733 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003734
3735 m_errorMonitor->VerifyFound();
3736
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003737 if (result == VK_SUCCESS) {
3738 vkDestroyRenderPass(m_device->device(), rp, NULL);
3739 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003740}
3741
Chris Forbesc5389742016-06-29 11:49:23 +12003742TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003743 TEST_DESCRIPTION(
3744 "Ensure that CreateRenderPass produces a validation error "
3745 "when the source of a subpass multisample resolve "
3746 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003747
Chris Forbesc5389742016-06-29 11:49:23 +12003748 ASSERT_NO_FATAL_FAILURE(InitState());
3749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3751 "Subpass 0 requests multisample resolve from attachment 0 which has "
3752 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003753
3754 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3756 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3758 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3759 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003761 };
3762
3763 VkAttachmentReference color = {
3764 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3765 };
3766
3767 VkAttachmentReference resolve = {
3768 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3769 };
3770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003774
3775 VkRenderPass rp;
3776 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3777
3778 m_errorMonitor->VerifyFound();
3779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003780 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003781}
3782
3783TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003784 TEST_DESCRIPTION(
3785 "Ensure CreateRenderPass produces a validation error "
3786 "when a subpass multisample resolve operation is "
3787 "requested, and the destination of that resolve has "
3788 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003789
Chris Forbesc5389742016-06-29 11:49:23 +12003790 ASSERT_NO_FATAL_FAILURE(InitState());
3791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3793 "Subpass 0 requests multisample resolve into attachment 1, which "
3794 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003795
3796 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003797 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3798 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3800 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3801 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3802 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003803 };
3804
3805 VkAttachmentReference color = {
3806 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3807 };
3808
3809 VkAttachmentReference resolve = {
3810 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3811 };
3812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003813 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003816
3817 VkRenderPass rp;
3818 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3819
3820 m_errorMonitor->VerifyFound();
3821
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003822 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003823}
3824
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003826 TEST_DESCRIPTION(
3827 "Ensure CreateRenderPass produces a validation error "
3828 "when the color and depth attachments used by a subpass "
3829 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003830
Chris Forbes3f128ef2016-06-29 14:58:53 +12003831 ASSERT_NO_FATAL_FAILURE(InitState());
3832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3834 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003835
3836 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3838 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3839 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3840 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3841 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3842 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003843 };
3844
3845 VkAttachmentReference color[] = {
3846 {
3847 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3848 },
3849 {
3850 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3851 },
3852 };
3853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003857
3858 VkRenderPass rp;
3859 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3860
3861 m_errorMonitor->VerifyFound();
3862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003863 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003864}
3865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003867 TEST_DESCRIPTION(
3868 "Hit errors when attempting to create a framebuffer :\n"
3869 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3870 " 2. Use a color image as depthStencil attachment\n"
3871 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3872 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3873 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3874 " 6. Framebuffer attachment where dimensions don't match\n"
3875 " 7. Framebuffer attachment w/o identity swizzle\n"
3876 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3880
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003881 m_errorMonitor->SetDesiredFailureMsg(
3882 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3883 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003885 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003886 VkAttachmentReference attach = {};
3887 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3888 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003889 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003890 VkRenderPassCreateInfo rpci = {};
3891 rpci.subpassCount = 1;
3892 rpci.pSubpasses = &subpass;
3893 rpci.attachmentCount = 1;
3894 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003896 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003897 rpci.pAttachments = &attach_desc;
3898 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3899 VkRenderPass rp;
3900 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3901 ASSERT_VK_SUCCESS(err);
3902
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003903 VkImageView ivs[2];
3904 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3905 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003906 VkFramebufferCreateInfo fb_info = {};
3907 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3908 fb_info.pNext = NULL;
3909 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 // Set mis-matching attachmentCount
3911 fb_info.attachmentCount = 2;
3912 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003913 fb_info.width = 100;
3914 fb_info.height = 100;
3915 fb_info.layers = 1;
3916
3917 VkFramebuffer fb;
3918 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3919
3920 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003921 if (err == VK_SUCCESS) {
3922 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3923 }
3924 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003925
3926 // Create a renderPass with a depth-stencil attachment created with
3927 // IMAGE_USAGE_COLOR_ATTACHMENT
3928 // Add our color attachment to pDepthStencilAttachment
3929 subpass.pDepthStencilAttachment = &attach;
3930 subpass.pColorAttachments = NULL;
3931 VkRenderPass rp_ds;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3933 ASSERT_VK_SUCCESS(err);
3934 // Set correct attachment count, but attachment has COLOR usage bit set
3935 fb_info.attachmentCount = 1;
3936 fb_info.renderPass = rp_ds;
3937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003939 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3940
3941 m_errorMonitor->VerifyFound();
3942 if (err == VK_SUCCESS) {
3943 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3944 }
3945 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003946
3947 // Create new renderpass with alternate attachment format from fb
3948 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3949 subpass.pDepthStencilAttachment = NULL;
3950 subpass.pColorAttachments = &attach;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched formats between rp & fb
3955 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3956 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3958 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003959 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3960
3961 m_errorMonitor->VerifyFound();
3962 if (err == VK_SUCCESS) {
3963 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3964 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003965 vkDestroyRenderPass(m_device->device(), rp, NULL);
3966
3967 // Create new renderpass with alternate sample count from fb
3968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3969 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3970 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 // Cause error due to mis-matched sample count between rp & fb
3974 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003976 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003977 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3978
3979 m_errorMonitor->VerifyFound();
3980 if (err == VK_SUCCESS) {
3981 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3982 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003983
3984 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003985
3986 // Create a custom imageView with non-1 mip levels
3987 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003988 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003989 ASSERT_TRUE(image.initialized());
3990
3991 VkImageView view;
3992 VkImageViewCreateInfo ivci = {};
3993 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3994 ivci.image = image.handle();
3995 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3996 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3997 ivci.subresourceRange.layerCount = 1;
3998 ivci.subresourceRange.baseMipLevel = 0;
3999 // Set level count 2 (only 1 is allowed for FB attachment)
4000 ivci.subresourceRange.levelCount = 2;
4001 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4002 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4003 ASSERT_VK_SUCCESS(err);
4004 // Re-create renderpass to have matching sample count
4005 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4006 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4007 ASSERT_VK_SUCCESS(err);
4008
4009 fb_info.renderPass = rp;
4010 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004012 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4013
4014 m_errorMonitor->VerifyFound();
4015 if (err == VK_SUCCESS) {
4016 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4017 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004018 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004019 // Update view to original color buffer and grow FB dimensions too big
4020 fb_info.pAttachments = ivs;
4021 fb_info.height = 1024;
4022 fb_info.width = 1024;
4023 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004025 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4026
4027 m_errorMonitor->VerifyFound();
4028 if (err == VK_SUCCESS) {
4029 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4030 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004031 // Create view attachment with non-identity swizzle
4032 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4033 ivci.image = image.handle();
4034 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4035 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4036 ivci.subresourceRange.layerCount = 1;
4037 ivci.subresourceRange.baseMipLevel = 0;
4038 ivci.subresourceRange.levelCount = 1;
4039 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4040 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4041 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4042 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4043 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4044 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 fb_info.pAttachments = &view;
4048 fb_info.height = 100;
4049 fb_info.width = 100;
4050 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004051 m_errorMonitor->SetDesiredFailureMsg(
4052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4053 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4055
4056 m_errorMonitor->VerifyFound();
4057 if (err == VK_SUCCESS) {
4058 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4059 }
4060 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004061 // reset attachment to color attachment
4062 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063
4064 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004065 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004066 fb_info.height = 100;
4067 fb_info.layers = 1;
4068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004069 m_errorMonitor->SetDesiredFailureMsg(
4070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004071 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4072 "Here are the respective dimensions for attachment");
4073
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4075
4076 m_errorMonitor->VerifyFound();
4077 if (err == VK_SUCCESS) {
4078 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4079 }
4080
4081 // Request fb that exceeds max height
4082 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004083 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004084 fb_info.layers = 1;
4085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004086 m_errorMonitor->SetDesiredFailureMsg(
4087 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004088 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4089 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004090 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4091
4092 m_errorMonitor->VerifyFound();
4093 if (err == VK_SUCCESS) {
4094 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4095 }
4096
4097 // Request fb that exceeds max layers
4098 fb_info.width = 100;
4099 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004100 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004102 m_errorMonitor->SetDesiredFailureMsg(
4103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004104 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4105 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4107
4108 m_errorMonitor->VerifyFound();
4109 if (err == VK_SUCCESS) {
4110 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4111 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004112
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004113 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004114}
4115
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004116TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004117 TEST_DESCRIPTION(
4118 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4119 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120
Cody Northropc31a84f2016-08-22 10:41:47 -06004121 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004122 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4124 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125 m_errorMonitor->VerifyFound();
4126}
4127
4128TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004129 TEST_DESCRIPTION(
4130 "Run a simple draw calls to validate failure when Line Width dynamic "
4131 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004132
Cody Northropc31a84f2016-08-22 10:41:47 -06004133 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004134 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004137 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138}
4139
4140TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004141 TEST_DESCRIPTION(
4142 "Run a simple draw calls to validate failure when Viewport dynamic "
4143 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004144
Cody Northropc31a84f2016-08-22 10:41:47 -06004145 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004146 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4148 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004149 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004150 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004151}
4152
4153TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004154 TEST_DESCRIPTION(
4155 "Run a simple draw calls to validate failure when Scissor dynamic "
4156 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004157
Cody Northropc31a84f2016-08-22 10:41:47 -06004158 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004159 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4161 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004164}
4165
Cortd713fe82016-07-27 09:51:27 -07004166TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004167 TEST_DESCRIPTION(
4168 "Run a simple draw calls to validate failure when Blend Constants "
4169 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004170
4171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004172 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4174 "Dynamic blend constants state not set for this command buffer");
4175 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004176 m_errorMonitor->VerifyFound();
4177}
4178
4179TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004180 TEST_DESCRIPTION(
4181 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4182 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004183
4184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004185 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004186 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004187 return;
4188 }
4189 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4191 "Dynamic depth bounds state not set for this command buffer");
4192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004193 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004194}
4195
4196TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004197 TEST_DESCRIPTION(
4198 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4199 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004202 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4204 "Dynamic stencil read mask state not set for this command buffer");
4205 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004206 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004207}
4208
4209TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004210 TEST_DESCRIPTION(
4211 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4212 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004213
4214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004215 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Dynamic stencil write mask state not set for this command buffer");
4218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004220}
4221
4222TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004223 TEST_DESCRIPTION(
4224 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004226
4227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004228 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Dynamic stencil reference state not set for this command buffer");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004232 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004233}
4234
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004235TEST_F(VkLayerTest, IndexBufferNotBound) {
4236 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004237
4238 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4240 "Index buffer object not bound to this command buffer when Indexed ");
4241 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004242 m_errorMonitor->VerifyFound();
4243}
4244
Karl Schultz6addd812016-02-02 17:17:23 -07004245TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4247 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4248 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 ASSERT_NO_FATAL_FAILURE(InitState());
4251 ASSERT_NO_FATAL_FAILURE(InitViewport());
4252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4253
Karl Schultz6addd812016-02-02 17:17:23 -07004254 // We luck out b/c by default the framework creates CB w/ the
4255 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004256 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004258 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004259
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004260 // Bypass framework since it does the waits automatically
4261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004271 submit_info.pSignalSemaphores = NULL;
4272
Chris Forbes40028e22016-06-13 09:59:34 +12004273 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Karl Schultz6addd812016-02-02 17:17:23 -07004277 // Cause validation error by re-submitting cmd buffer that should only be
4278 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004279 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004280 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004282 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004283}
4284
Karl Schultz6addd812016-02-02 17:17:23 -07004285TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004287 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004288
4289 ASSERT_NO_FATAL_FAILURE(InitState());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004291
Karl Schultz6addd812016-02-02 17:17:23 -07004292 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4293 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004295 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004296 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004297
4298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4300 ds_pool_ci.pNext = NULL;
4301 ds_pool_ci.flags = 0;
4302 ds_pool_ci.maxSets = 1;
4303 ds_pool_ci.poolSizeCount = 1;
4304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004305
4306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004308 ASSERT_VK_SUCCESS(err);
4309
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004310 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4311 dsl_binding_samp.binding = 0;
4312 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4313 dsl_binding_samp.descriptorCount = 1;
4314 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4315 dsl_binding_samp.pImmutableSamplers = NULL;
4316
4317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4319 ds_layout_ci.pNext = NULL;
4320 ds_layout_ci.bindingCount = 1;
4321 ds_layout_ci.pBindings = &dsl_binding_samp;
4322
4323 VkDescriptorSetLayout ds_layout_samp;
4324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4325 ASSERT_VK_SUCCESS(err);
4326
4327 // Try to allocate 2 sets when pool only has 1 set
4328 VkDescriptorSet descriptor_sets[2];
4329 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4330 VkDescriptorSetAllocateInfo alloc_info = {};
4331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4332 alloc_info.descriptorSetCount = 2;
4333 alloc_info.descriptorPool = ds_pool;
4334 alloc_info.pSetLayouts = set_layouts;
4335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4337 m_errorMonitor->VerifyFound();
4338
4339 alloc_info.descriptorSetCount = 1;
4340 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004342 dsl_binding.binding = 0;
4343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4344 dsl_binding.descriptorCount = 1;
4345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4346 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347
Karl Schultz6addd812016-02-02 17:17:23 -07004348 ds_layout_ci.bindingCount = 1;
4349 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004351 VkDescriptorSetLayout ds_layout_ub;
4352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004353 ASSERT_VK_SUCCESS(err);
4354
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004355 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004356 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004357 alloc_info.pSetLayouts = &ds_layout_ub;
4358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004362
Karl Schultz2825ab92016-12-02 08:23:14 -07004363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004366}
4367
Karl Schultz6addd812016-02-02 17:17:23 -07004368TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4369 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004372
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_NO_FATAL_FAILURE(InitState());
4374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004375
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4382 ds_pool_ci.pNext = NULL;
4383 ds_pool_ci.maxSets = 1;
4384 ds_pool_ci.poolSizeCount = 1;
4385 ds_pool_ci.flags = 0;
4386 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4387 // app can only call vkResetDescriptorPool on this pool.;
4388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004389
4390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004392 ASSERT_VK_SUCCESS(err);
4393
4394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004395 dsl_binding.binding = 0;
4396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4397 dsl_binding.descriptorCount = 1;
4398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004400
4401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4403 ds_layout_ci.pNext = NULL;
4404 ds_layout_ci.bindingCount = 1;
4405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004406
4407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004409 ASSERT_VK_SUCCESS(err);
4410
4411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004415 alloc_info.descriptorPool = ds_pool;
4416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004418 ASSERT_VK_SUCCESS(err);
4419
4420 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004421 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Chia-I Wuf7458c52015-10-26 21:10:41 +08004423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004425}
4426
Karl Schultz6addd812016-02-02 17:17:23 -07004427TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 // Attempt to clear Descriptor Pool with bad object.
4429 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004433 uint64_t fake_pool_handle = 0xbaad6001;
4434 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4435 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004436 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437}
4438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004439TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004440 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4441 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004442 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004443 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004444
4445 uint64_t fake_set_handle = 0xbaad6001;
4446 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004447 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004449
4450 ASSERT_NO_FATAL_FAILURE(InitState());
4451
4452 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4453 layout_bindings[0].binding = 0;
4454 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4455 layout_bindings[0].descriptorCount = 1;
4456 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4457 layout_bindings[0].pImmutableSamplers = NULL;
4458
4459 VkDescriptorSetLayout descriptor_set_layout;
4460 VkDescriptorSetLayoutCreateInfo dslci = {};
4461 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4462 dslci.pNext = NULL;
4463 dslci.bindingCount = 1;
4464 dslci.pBindings = layout_bindings;
4465 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004466 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004467
4468 VkPipelineLayout pipeline_layout;
4469 VkPipelineLayoutCreateInfo plci = {};
4470 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4471 plci.pNext = NULL;
4472 plci.setLayoutCount = 1;
4473 plci.pSetLayouts = &descriptor_set_layout;
4474 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004475 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004476
Tony Barbour552f6c02016-12-21 14:34:07 -07004477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4479 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004481 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4483 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004484}
4485
Karl Schultz6addd812016-02-02 17:17:23 -07004486TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004487 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4488 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004489 uint64_t fake_layout_handle = 0xbaad6001;
4490 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004492 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004493 VkPipelineLayout pipeline_layout;
4494 VkPipelineLayoutCreateInfo plci = {};
4495 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4496 plci.pNext = NULL;
4497 plci.setLayoutCount = 1;
4498 plci.pSetLayouts = &bad_layout;
4499 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4500
4501 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004502}
4503
Mark Muellerd4914412016-06-13 17:52:06 -06004504TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004505 TEST_DESCRIPTION(
4506 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4507 "1) A uniform buffer update must have a valid buffer index."
4508 "2) When using an array of descriptors in a single WriteDescriptor,"
4509 " the descriptor types and stageflags must all be the same."
4510 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004511
Mike Weiblena6666382017-01-05 15:16:11 -07004512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004513
4514 ASSERT_NO_FATAL_FAILURE(InitState());
4515 VkDescriptorPoolSize ds_type_count[4] = {};
4516 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4517 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004518 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004519 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004520 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004521 ds_type_count[2].descriptorCount = 1;
4522 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4523 ds_type_count[3].descriptorCount = 1;
4524
4525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4527 ds_pool_ci.maxSets = 1;
4528 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4529 ds_pool_ci.pPoolSizes = ds_type_count;
4530
4531 VkDescriptorPool ds_pool;
4532 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4533 ASSERT_VK_SUCCESS(err);
4534
Mark Muellerb9896722016-06-16 09:54:29 -06004535 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004536 layout_binding[0].binding = 0;
4537 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4538 layout_binding[0].descriptorCount = 1;
4539 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4540 layout_binding[0].pImmutableSamplers = NULL;
4541
4542 layout_binding[1].binding = 1;
4543 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4544 layout_binding[1].descriptorCount = 1;
4545 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4546 layout_binding[1].pImmutableSamplers = NULL;
4547
4548 VkSamplerCreateInfo sampler_ci = {};
4549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4550 sampler_ci.pNext = NULL;
4551 sampler_ci.magFilter = VK_FILTER_NEAREST;
4552 sampler_ci.minFilter = VK_FILTER_NEAREST;
4553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4557 sampler_ci.mipLodBias = 1.0;
4558 sampler_ci.anisotropyEnable = VK_FALSE;
4559 sampler_ci.maxAnisotropy = 1;
4560 sampler_ci.compareEnable = VK_FALSE;
4561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4562 sampler_ci.minLod = 1.0;
4563 sampler_ci.maxLod = 1.0;
4564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4566 VkSampler sampler;
4567
4568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4569 ASSERT_VK_SUCCESS(err);
4570
4571 layout_binding[2].binding = 2;
4572 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4573 layout_binding[2].descriptorCount = 1;
4574 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4575 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4576
Mark Muellerd4914412016-06-13 17:52:06 -06004577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4579 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4580 ds_layout_ci.pBindings = layout_binding;
4581 VkDescriptorSetLayout ds_layout;
4582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
4585 VkDescriptorSetAllocateInfo alloc_info = {};
4586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4587 alloc_info.descriptorSetCount = 1;
4588 alloc_info.descriptorPool = ds_pool;
4589 alloc_info.pSetLayouts = &ds_layout;
4590 VkDescriptorSet descriptorSet;
4591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4592 ASSERT_VK_SUCCESS(err);
4593
4594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4596 pipeline_layout_ci.pNext = NULL;
4597 pipeline_layout_ci.setLayoutCount = 1;
4598 pipeline_layout_ci.pSetLayouts = &ds_layout;
4599
4600 VkPipelineLayout pipeline_layout;
4601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4602 ASSERT_VK_SUCCESS(err);
4603
Mark Mueller5c838ce2016-06-16 09:54:29 -06004604 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4606 descriptor_write.dstSet = descriptorSet;
4607 descriptor_write.dstBinding = 0;
4608 descriptor_write.descriptorCount = 1;
4609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4610
Mark Mueller5c838ce2016-06-16 09:54:29 -06004611 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4613 m_errorMonitor->VerifyFound();
4614
4615 // Create a buffer to update the descriptor with
4616 uint32_t qfi = 0;
4617 VkBufferCreateInfo buffCI = {};
4618 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4619 buffCI.size = 1024;
4620 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4621 buffCI.queueFamilyIndexCount = 1;
4622 buffCI.pQueueFamilyIndices = &qfi;
4623
4624 VkBuffer dyub;
4625 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4626 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004627
Tony Barboure132c5f2016-12-12 11:50:20 -07004628 VkDeviceMemory mem;
4629 VkMemoryRequirements mem_reqs;
4630 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4631
4632 VkMemoryAllocateInfo mem_alloc_info = {};
4633 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4634 mem_alloc_info.allocationSize = mem_reqs.size;
4635 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4636 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4637 ASSERT_VK_SUCCESS(err);
4638
4639 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4640 ASSERT_VK_SUCCESS(err);
4641
4642 VkDescriptorBufferInfo buffInfo[2] = {};
4643 buffInfo[0].buffer = dyub;
4644 buffInfo[0].offset = 0;
4645 buffInfo[0].range = 1024;
4646 buffInfo[1].buffer = dyub;
4647 buffInfo[1].offset = 0;
4648 buffInfo[1].range = 1024;
4649 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004650 descriptor_write.descriptorCount = 2;
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4655 m_errorMonitor->VerifyFound();
4656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4658 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004659 descriptor_write.dstBinding = 1;
4660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004661
Mark Mueller5c838ce2016-06-16 09:54:29 -06004662 // Make pImageInfo index non-null to avoid complaints of it missing
4663 VkDescriptorImageInfo imageInfo = {};
4664 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4665 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4668 m_errorMonitor->VerifyFound();
4669
Mark Muellerd4914412016-06-13 17:52:06 -06004670 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004671 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004672 vkDestroySampler(m_device->device(), sampler, NULL);
4673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4676}
4677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004679 TEST_DESCRIPTION(
4680 "Attempt to draw with a command buffer that is invalid "
4681 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004682 ASSERT_NO_FATAL_FAILURE(InitState());
4683
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004684 VkBuffer buffer;
4685 VkDeviceMemory mem;
4686 VkMemoryRequirements mem_reqs;
4687
4688 VkBufferCreateInfo buf_info = {};
4689 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004690 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004691 buf_info.size = 256;
4692 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4693 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4694 ASSERT_VK_SUCCESS(err);
4695
4696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4697
4698 VkMemoryAllocateInfo alloc_info = {};
4699 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4700 alloc_info.allocationSize = 256;
4701 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004702 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004703 if (!pass) {
4704 vkDestroyBuffer(m_device->device(), buffer, NULL);
4705 return;
4706 }
4707 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4708 ASSERT_VK_SUCCESS(err);
4709
4710 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4711 ASSERT_VK_SUCCESS(err);
4712
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004714 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004715 m_commandBuffer->EndCommandBuffer();
4716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004718 // Destroy buffer dependency prior to submit to cause ERROR
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720
4721 VkSubmitInfo submit_info = {};
4722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4723 submit_info.commandBufferCount = 1;
4724 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4726
4727 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004728 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004729 vkFreeMemory(m_device->handle(), mem, NULL);
4730}
4731
Tobin Ehlisea413442016-09-28 10:23:59 -06004732TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4733 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4734
4735 ASSERT_NO_FATAL_FAILURE(InitState());
4736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4737
4738 VkDescriptorPoolSize ds_type_count;
4739 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4740 ds_type_count.descriptorCount = 1;
4741
4742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4744 ds_pool_ci.maxSets = 1;
4745 ds_pool_ci.poolSizeCount = 1;
4746 ds_pool_ci.pPoolSizes = &ds_type_count;
4747
4748 VkDescriptorPool ds_pool;
4749 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4750 ASSERT_VK_SUCCESS(err);
4751
4752 VkDescriptorSetLayoutBinding layout_binding;
4753 layout_binding.binding = 0;
4754 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4755 layout_binding.descriptorCount = 1;
4756 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4757 layout_binding.pImmutableSamplers = NULL;
4758
4759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4761 ds_layout_ci.bindingCount = 1;
4762 ds_layout_ci.pBindings = &layout_binding;
4763 VkDescriptorSetLayout ds_layout;
4764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkDescriptorSetAllocateInfo alloc_info = {};
4768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4769 alloc_info.descriptorSetCount = 1;
4770 alloc_info.descriptorPool = ds_pool;
4771 alloc_info.pSetLayouts = &ds_layout;
4772 VkDescriptorSet descriptor_set;
4773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4778 pipeline_layout_ci.pNext = NULL;
4779 pipeline_layout_ci.setLayoutCount = 1;
4780 pipeline_layout_ci.pSetLayouts = &ds_layout;
4781
4782 VkPipelineLayout pipeline_layout;
4783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 VkBuffer buffer;
4787 uint32_t queue_family_index = 0;
4788 VkBufferCreateInfo buffer_create_info = {};
4789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4790 buffer_create_info.size = 1024;
4791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4792 buffer_create_info.queueFamilyIndexCount = 1;
4793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4794
4795 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4796 ASSERT_VK_SUCCESS(err);
4797
4798 VkMemoryRequirements memory_reqs;
4799 VkDeviceMemory buffer_memory;
4800
4801 VkMemoryAllocateInfo memory_info = {};
4802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4803 memory_info.allocationSize = 0;
4804 memory_info.memoryTypeIndex = 0;
4805
4806 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4807 memory_info.allocationSize = memory_reqs.size;
4808 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4809 ASSERT_TRUE(pass);
4810
4811 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4812 ASSERT_VK_SUCCESS(err);
4813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkBufferView view;
4817 VkBufferViewCreateInfo bvci = {};
4818 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4819 bvci.buffer = buffer;
4820 bvci.format = VK_FORMAT_R8_UNORM;
4821 bvci.range = VK_WHOLE_SIZE;
4822
4823 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4824 ASSERT_VK_SUCCESS(err);
4825
4826 VkWriteDescriptorSet descriptor_write = {};
4827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4828 descriptor_write.dstSet = descriptor_set;
4829 descriptor_write.dstBinding = 0;
4830 descriptor_write.descriptorCount = 1;
4831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4832 descriptor_write.pTexelBufferView = &view;
4833
4834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004836 char const *vsSource =
4837 "#version 450\n"
4838 "\n"
4839 "out gl_PerVertex { \n"
4840 " vec4 gl_Position;\n"
4841 "};\n"
4842 "void main(){\n"
4843 " gl_Position = vec4(1);\n"
4844 "}\n";
4845 char const *fsSource =
4846 "#version 450\n"
4847 "\n"
4848 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4849 "layout(location=0) out vec4 x;\n"
4850 "void main(){\n"
4851 " x = imageLoad(s, 0);\n"
4852 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4855 VkPipelineObj pipe(m_device);
4856 pipe.AddShader(&vs);
4857 pipe.AddShader(&fs);
4858 pipe.AddColorAttachment();
4859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4862
Tony Barbour552f6c02016-12-21 14:34:07 -07004863 m_commandBuffer->BeginCommandBuffer();
4864 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4865
Tobin Ehlisea413442016-09-28 10:23:59 -06004866 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4867 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4868 VkRect2D scissor = {{0, 0}, {16, 16}};
4869 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4870 // Bind pipeline to cmd buffer
4871 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4872 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4873 &descriptor_set, 0, nullptr);
4874 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004875 m_commandBuffer->EndRenderPass();
4876 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004877
4878 // Delete BufferView in order to invalidate cmd buffer
4879 vkDestroyBufferView(m_device->device(), view, NULL);
4880 // Now attempt submit of cmd buffer
4881 VkSubmitInfo submit_info = {};
4882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4883 submit_info.commandBufferCount = 1;
4884 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4885 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4886 m_errorMonitor->VerifyFound();
4887
4888 // Clean-up
4889 vkDestroyBuffer(m_device->device(), buffer, NULL);
4890 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4894}
4895
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004897 TEST_DESCRIPTION(
4898 "Attempt to draw with a command buffer that is invalid "
4899 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_NO_FATAL_FAILURE(InitState());
4901
4902 VkImage image;
4903 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4904 VkImageCreateInfo image_create_info = {};
4905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4906 image_create_info.pNext = NULL;
4907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4908 image_create_info.format = tex_format;
4909 image_create_info.extent.width = 32;
4910 image_create_info.extent.height = 32;
4911 image_create_info.extent.depth = 1;
4912 image_create_info.mipLevels = 1;
4913 image_create_info.arrayLayers = 1;
4914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004919 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004920 // Have to bind memory to image before recording cmd in cmd buffer using it
4921 VkMemoryRequirements mem_reqs;
4922 VkDeviceMemory image_mem;
4923 bool pass;
4924 VkMemoryAllocateInfo mem_alloc = {};
4925 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4926 mem_alloc.pNext = NULL;
4927 mem_alloc.memoryTypeIndex = 0;
4928 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4929 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004931 ASSERT_TRUE(pass);
4932 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4935 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004936
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004937 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004938 VkClearColorValue ccv;
4939 ccv.float32[0] = 1.0f;
4940 ccv.float32[1] = 1.0f;
4941 ccv.float32[2] = 1.0f;
4942 ccv.float32[3] = 1.0f;
4943 VkImageSubresourceRange isr = {};
4944 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004945 isr.baseArrayLayer = 0;
4946 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004947 isr.layerCount = 1;
4948 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004950 m_commandBuffer->EndCommandBuffer();
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953 // Destroy image dependency prior to submit to cause ERROR
4954 vkDestroyImage(m_device->device(), image, NULL);
4955
4956 VkSubmitInfo submit_info = {};
4957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4958 submit_info.commandBufferCount = 1;
4959 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4961
4962 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004963 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004964}
4965
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004967 TEST_DESCRIPTION(
4968 "Attempt to draw with a command buffer that is invalid "
4969 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 VkFormatProperties format_properties;
4971 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004972 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4973 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 return;
4975 }
4976
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkImageCreateInfo image_ci = {};
4981 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4982 image_ci.pNext = NULL;
4983 image_ci.imageType = VK_IMAGE_TYPE_2D;
4984 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4985 image_ci.extent.width = 32;
4986 image_ci.extent.height = 32;
4987 image_ci.extent.depth = 1;
4988 image_ci.mipLevels = 1;
4989 image_ci.arrayLayers = 1;
4990 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4991 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004993 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4994 image_ci.flags = 0;
4995 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004997
4998 VkMemoryRequirements memory_reqs;
4999 VkDeviceMemory image_memory;
5000 bool pass;
5001 VkMemoryAllocateInfo memory_info = {};
5002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 memory_info.pNext = NULL;
5004 memory_info.allocationSize = 0;
5005 memory_info.memoryTypeIndex = 0;
5006 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5007 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005009 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 ASSERT_VK_SUCCESS(err);
5012 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 VkImageViewCreateInfo ivci = {
5016 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5017 nullptr,
5018 0,
5019 image,
5020 VK_IMAGE_VIEW_TYPE_2D,
5021 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5024 };
5025 VkImageView view;
5026 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5027 ASSERT_VK_SUCCESS(err);
5028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 VkFramebuffer fb;
5031 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5032 ASSERT_VK_SUCCESS(err);
5033
5034 // Just use default renderpass with our framebuffer
5035 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005036 m_renderPassBeginInfo.renderArea.extent.width = 32;
5037 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005039 m_commandBuffer->BeginCommandBuffer();
5040 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5041 m_commandBuffer->EndRenderPass();
5042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005043 // Destroy image attached to framebuffer to invalidate cmd buffer
5044 vkDestroyImage(m_device->device(), image, NULL);
5045 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005047 QueueCommandBuffer(false);
5048 m_errorMonitor->VerifyFound();
5049
5050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5051 vkDestroyImageView(m_device->device(), view, nullptr);
5052 vkFreeMemory(m_device->device(), image_memory, nullptr);
5053}
5054
Tobin Ehlisb329f992016-10-12 13:20:29 -06005055TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5056 TEST_DESCRIPTION("Delete in-use framebuffer.");
5057 VkFormatProperties format_properties;
5058 VkResult err = VK_SUCCESS;
5059 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5060
5061 ASSERT_NO_FATAL_FAILURE(InitState());
5062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5063
5064 VkImageObj image(m_device);
5065 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5066 ASSERT_TRUE(image.initialized());
5067 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5068
5069 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5070 VkFramebuffer fb;
5071 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5072 ASSERT_VK_SUCCESS(err);
5073
5074 // Just use default renderpass with our framebuffer
5075 m_renderPassBeginInfo.framebuffer = fb;
5076 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005077 m_commandBuffer->BeginCommandBuffer();
5078 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5079 m_commandBuffer->EndRenderPass();
5080 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005081 // Submit cmd buffer to put it in-flight
5082 VkSubmitInfo submit_info = {};
5083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5084 submit_info.commandBufferCount = 1;
5085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5086 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5087 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005089 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5090 m_errorMonitor->VerifyFound();
5091 // Wait for queue to complete so we can safely destroy everything
5092 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005093 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5094 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005095 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5096}
5097
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5099 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5100 VkFormatProperties format_properties;
5101 VkResult err = VK_SUCCESS;
5102 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103
5104 ASSERT_NO_FATAL_FAILURE(InitState());
5105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5106
5107 VkImageCreateInfo image_ci = {};
5108 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5109 image_ci.pNext = NULL;
5110 image_ci.imageType = VK_IMAGE_TYPE_2D;
5111 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5112 image_ci.extent.width = 256;
5113 image_ci.extent.height = 256;
5114 image_ci.extent.depth = 1;
5115 image_ci.mipLevels = 1;
5116 image_ci.arrayLayers = 1;
5117 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5118 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005119 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005120 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5121 image_ci.flags = 0;
5122 VkImage image;
5123 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5124
5125 VkMemoryRequirements memory_reqs;
5126 VkDeviceMemory image_memory;
5127 bool pass;
5128 VkMemoryAllocateInfo memory_info = {};
5129 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5130 memory_info.pNext = NULL;
5131 memory_info.allocationSize = 0;
5132 memory_info.memoryTypeIndex = 0;
5133 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5134 memory_info.allocationSize = memory_reqs.size;
5135 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5136 ASSERT_TRUE(pass);
5137 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5138 ASSERT_VK_SUCCESS(err);
5139 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5140 ASSERT_VK_SUCCESS(err);
5141
5142 VkImageViewCreateInfo ivci = {
5143 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5144 nullptr,
5145 0,
5146 image,
5147 VK_IMAGE_VIEW_TYPE_2D,
5148 VK_FORMAT_B8G8R8A8_UNORM,
5149 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5150 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5151 };
5152 VkImageView view;
5153 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5157 VkFramebuffer fb;
5158 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5159 ASSERT_VK_SUCCESS(err);
5160
5161 // Just use default renderpass with our framebuffer
5162 m_renderPassBeginInfo.framebuffer = fb;
5163 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005164 m_commandBuffer->BeginCommandBuffer();
5165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5166 m_commandBuffer->EndRenderPass();
5167 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005168 // Submit cmd buffer to put it (and attached imageView) in-flight
5169 VkSubmitInfo submit_info = {};
5170 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5171 submit_info.commandBufferCount = 1;
5172 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5173 // Submit cmd buffer to put framebuffer and children in-flight
5174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5175 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005177 vkDestroyImage(m_device->device(), image, NULL);
5178 m_errorMonitor->VerifyFound();
5179 // Wait for queue to complete so we can safely destroy image and other objects
5180 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005181 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5182 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005183 vkDestroyImage(m_device->device(), image, NULL);
5184 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5185 vkDestroyImageView(m_device->device(), view, nullptr);
5186 vkFreeMemory(m_device->device(), image_memory, nullptr);
5187}
5188
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005189TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5190 TEST_DESCRIPTION("Delete in-use renderPass.");
5191
5192 ASSERT_NO_FATAL_FAILURE(InitState());
5193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5194
5195 // Create simple renderpass
5196 VkAttachmentReference attach = {};
5197 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5198 VkSubpassDescription subpass = {};
5199 subpass.pColorAttachments = &attach;
5200 VkRenderPassCreateInfo rpci = {};
5201 rpci.subpassCount = 1;
5202 rpci.pSubpasses = &subpass;
5203 rpci.attachmentCount = 1;
5204 VkAttachmentDescription attach_desc = {};
5205 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5206 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5207 rpci.pAttachments = &attach_desc;
5208 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5209 VkRenderPass rp;
5210 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Create a pipeline that uses the given renderpass
5214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5216
5217 VkPipelineLayout pipeline_layout;
5218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5219 ASSERT_VK_SUCCESS(err);
5220
5221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005224 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005225 vp_state_ci.pViewports = &vp;
5226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005227 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005228 vp_state_ci.pScissors = &scissors;
5229
5230 VkPipelineShaderStageCreateInfo shaderStages[2];
5231 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5232
5233 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005234 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005235 // but add it to be able to run on more devices
5236 shaderStages[0] = vs.GetStageCreateInfo();
5237 shaderStages[1] = fs.GetStageCreateInfo();
5238
5239 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5240 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5241
5242 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5243 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5244 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5245
5246 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5247 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5248 rs_ci.rasterizerDiscardEnable = true;
5249 rs_ci.lineWidth = 1.0f;
5250
5251 VkPipelineColorBlendAttachmentState att = {};
5252 att.blendEnable = VK_FALSE;
5253 att.colorWriteMask = 0xf;
5254
5255 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5256 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5257 cb_ci.attachmentCount = 1;
5258 cb_ci.pAttachments = &att;
5259
5260 VkGraphicsPipelineCreateInfo gp_ci = {};
5261 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5262 gp_ci.stageCount = 2;
5263 gp_ci.pStages = shaderStages;
5264 gp_ci.pVertexInputState = &vi_ci;
5265 gp_ci.pInputAssemblyState = &ia_ci;
5266 gp_ci.pViewportState = &vp_state_ci;
5267 gp_ci.pRasterizationState = &rs_ci;
5268 gp_ci.pColorBlendState = &cb_ci;
5269 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5270 gp_ci.layout = pipeline_layout;
5271 gp_ci.renderPass = rp;
5272
5273 VkPipelineCacheCreateInfo pc_ci = {};
5274 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5275
5276 VkPipeline pipeline;
5277 VkPipelineCache pipe_cache;
5278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5279 ASSERT_VK_SUCCESS(err);
5280
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005281 m_errorMonitor->SetUnexpectedError(
5282 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5283 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005284 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5285 ASSERT_VK_SUCCESS(err);
5286 // Bind pipeline to cmd buffer, will also bind renderpass
5287 m_commandBuffer->BeginCommandBuffer();
5288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5289 m_commandBuffer->EndCommandBuffer();
5290
5291 VkSubmitInfo submit_info = {};
5292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5293 submit_info.commandBufferCount = 1;
5294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5295 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5296
5297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5298 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5299 m_errorMonitor->VerifyFound();
5300
5301 // Wait for queue to complete so we can safely destroy everything
5302 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005303 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5304 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005305 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5306 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5307 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5309}
5310
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005311TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 ASSERT_NO_FATAL_FAILURE(InitState());
5314
5315 VkImage image;
5316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5317 VkImageCreateInfo image_create_info = {};
5318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5319 image_create_info.pNext = NULL;
5320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5321 image_create_info.format = tex_format;
5322 image_create_info.extent.width = 32;
5323 image_create_info.extent.height = 32;
5324 image_create_info.extent.depth = 1;
5325 image_create_info.mipLevels = 1;
5326 image_create_info.arrayLayers = 1;
5327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005329 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005330 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005332 ASSERT_VK_SUCCESS(err);
5333 // Have to bind memory to image before recording cmd in cmd buffer using it
5334 VkMemoryRequirements mem_reqs;
5335 VkDeviceMemory image_mem;
5336 bool pass;
5337 VkMemoryAllocateInfo mem_alloc = {};
5338 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5339 mem_alloc.pNext = NULL;
5340 mem_alloc.memoryTypeIndex = 0;
5341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005344 ASSERT_TRUE(pass);
5345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5346 ASSERT_VK_SUCCESS(err);
5347
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005348 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005350 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005351
5352 m_commandBuffer->BeginCommandBuffer();
5353 VkClearColorValue ccv;
5354 ccv.float32[0] = 1.0f;
5355 ccv.float32[1] = 1.0f;
5356 ccv.float32[2] = 1.0f;
5357 ccv.float32[3] = 1.0f;
5358 VkImageSubresourceRange isr = {};
5359 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5360 isr.baseArrayLayer = 0;
5361 isr.baseMipLevel = 0;
5362 isr.layerCount = 1;
5363 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005364 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005365 m_commandBuffer->EndCommandBuffer();
5366
5367 m_errorMonitor->VerifyFound();
5368 vkDestroyImage(m_device->device(), image, NULL);
5369 vkFreeMemory(m_device->device(), image_mem, nullptr);
5370}
5371
5372TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005374 ASSERT_NO_FATAL_FAILURE(InitState());
5375
5376 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 VK_IMAGE_TILING_OPTIMAL, 0);
5379 ASSERT_TRUE(image.initialized());
5380
5381 VkBuffer buffer;
5382 VkDeviceMemory mem;
5383 VkMemoryRequirements mem_reqs;
5384
5385 VkBufferCreateInfo buf_info = {};
5386 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005387 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005388 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005389 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5390 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5391 ASSERT_VK_SUCCESS(err);
5392
5393 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5394
5395 VkMemoryAllocateInfo alloc_info = {};
5396 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005397 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005398 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005400 if (!pass) {
5401 vkDestroyBuffer(m_device->device(), buffer, NULL);
5402 return;
5403 }
5404 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5405 ASSERT_VK_SUCCESS(err);
5406
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005407 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005409 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005410 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005411 region.bufferRowLength = 16;
5412 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005413 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5414
5415 region.imageSubresource.layerCount = 1;
5416 region.imageExtent.height = 4;
5417 region.imageExtent.width = 4;
5418 region.imageExtent.depth = 1;
5419 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5421 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005422 m_commandBuffer->EndCommandBuffer();
5423
5424 m_errorMonitor->VerifyFound();
5425
5426 vkDestroyBuffer(m_device->device(), buffer, NULL);
5427 vkFreeMemory(m_device->handle(), mem, NULL);
5428}
5429
Tobin Ehlis85940f52016-07-07 16:57:21 -06005430TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005431 TEST_DESCRIPTION(
5432 "Attempt to draw with a command buffer that is invalid "
5433 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005434 ASSERT_NO_FATAL_FAILURE(InitState());
5435
5436 VkEvent event;
5437 VkEventCreateInfo evci = {};
5438 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5439 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5440 ASSERT_VK_SUCCESS(result);
5441
5442 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005443 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005444 m_commandBuffer->EndCommandBuffer();
5445
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005447 // Destroy event dependency prior to submit to cause ERROR
5448 vkDestroyEvent(m_device->device(), event, NULL);
5449
5450 VkSubmitInfo submit_info = {};
5451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5452 submit_info.commandBufferCount = 1;
5453 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5454 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5455
5456 m_errorMonitor->VerifyFound();
5457}
5458
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005459TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005460 TEST_DESCRIPTION(
5461 "Attempt to draw with a command buffer that is invalid "
5462 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005463 ASSERT_NO_FATAL_FAILURE(InitState());
5464
5465 VkQueryPool query_pool;
5466 VkQueryPoolCreateInfo qpci{};
5467 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5468 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5469 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005470 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005471 ASSERT_VK_SUCCESS(result);
5472
5473 m_commandBuffer->BeginCommandBuffer();
5474 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5475 m_commandBuffer->EndCommandBuffer();
5476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005478 // Destroy query pool dependency prior to submit to cause ERROR
5479 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5480
5481 VkSubmitInfo submit_info = {};
5482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5483 submit_info.commandBufferCount = 1;
5484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5486
5487 m_errorMonitor->VerifyFound();
5488}
5489
Tobin Ehlis24130d92016-07-08 15:50:53 -06005490TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005491 TEST_DESCRIPTION(
5492 "Attempt to draw with a command buffer that is invalid "
5493 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
5495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5496
5497 VkResult err;
5498
5499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5501
5502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005504 ASSERT_VK_SUCCESS(err);
5505
5506 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5507 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5508 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005509 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005510 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005512 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005513 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005514
5515 VkPipelineShaderStageCreateInfo shaderStages[2];
5516 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005519 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005520 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005521 shaderStages[0] = vs.GetStageCreateInfo();
5522 shaderStages[1] = fs.GetStageCreateInfo();
5523
5524 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5525 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5526
5527 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5528 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5529 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5530
5531 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5532 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005533 rs_ci.rasterizerDiscardEnable = true;
5534 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005535
5536 VkPipelineColorBlendAttachmentState att = {};
5537 att.blendEnable = VK_FALSE;
5538 att.colorWriteMask = 0xf;
5539
5540 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5541 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5542 cb_ci.attachmentCount = 1;
5543 cb_ci.pAttachments = &att;
5544
5545 VkGraphicsPipelineCreateInfo gp_ci = {};
5546 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5547 gp_ci.stageCount = 2;
5548 gp_ci.pStages = shaderStages;
5549 gp_ci.pVertexInputState = &vi_ci;
5550 gp_ci.pInputAssemblyState = &ia_ci;
5551 gp_ci.pViewportState = &vp_state_ci;
5552 gp_ci.pRasterizationState = &rs_ci;
5553 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005554 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5555 gp_ci.layout = pipeline_layout;
5556 gp_ci.renderPass = renderPass();
5557
5558 VkPipelineCacheCreateInfo pc_ci = {};
5559 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5560
5561 VkPipeline pipeline;
5562 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 ASSERT_VK_SUCCESS(err);
5565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 ASSERT_VK_SUCCESS(err);
5568
5569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005571 m_commandBuffer->EndCommandBuffer();
5572 // Now destroy pipeline in order to cause error when submitting
5573 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005576
5577 VkSubmitInfo submit_info = {};
5578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5579 submit_info.commandBufferCount = 1;
5580 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5582
5583 m_errorMonitor->VerifyFound();
5584 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5586}
5587
Tobin Ehlis31289162016-08-17 14:57:58 -06005588TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005589 TEST_DESCRIPTION(
5590 "Attempt to draw with a command buffer that is invalid "
5591 "due to a bound descriptor set with a buffer dependency "
5592 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005593 ASSERT_NO_FATAL_FAILURE(InitState());
5594 ASSERT_NO_FATAL_FAILURE(InitViewport());
5595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5596
5597 VkDescriptorPoolSize ds_type_count = {};
5598 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5599 ds_type_count.descriptorCount = 1;
5600
5601 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5602 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5603 ds_pool_ci.pNext = NULL;
5604 ds_pool_ci.maxSets = 1;
5605 ds_pool_ci.poolSizeCount = 1;
5606 ds_pool_ci.pPoolSizes = &ds_type_count;
5607
5608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005609 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005610 ASSERT_VK_SUCCESS(err);
5611
5612 VkDescriptorSetLayoutBinding dsl_binding = {};
5613 dsl_binding.binding = 0;
5614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5615 dsl_binding.descriptorCount = 1;
5616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5617 dsl_binding.pImmutableSamplers = NULL;
5618
5619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5621 ds_layout_ci.pNext = NULL;
5622 ds_layout_ci.bindingCount = 1;
5623 ds_layout_ci.pBindings = &dsl_binding;
5624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005626 ASSERT_VK_SUCCESS(err);
5627
5628 VkDescriptorSet descriptorSet;
5629 VkDescriptorSetAllocateInfo alloc_info = {};
5630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5631 alloc_info.descriptorSetCount = 1;
5632 alloc_info.descriptorPool = ds_pool;
5633 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005635 ASSERT_VK_SUCCESS(err);
5636
5637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5639 pipeline_layout_ci.pNext = NULL;
5640 pipeline_layout_ci.setLayoutCount = 1;
5641 pipeline_layout_ci.pSetLayouts = &ds_layout;
5642
5643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005645 ASSERT_VK_SUCCESS(err);
5646
5647 // Create a buffer to update the descriptor with
5648 uint32_t qfi = 0;
5649 VkBufferCreateInfo buffCI = {};
5650 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5651 buffCI.size = 1024;
5652 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5653 buffCI.queueFamilyIndexCount = 1;
5654 buffCI.pQueueFamilyIndices = &qfi;
5655
5656 VkBuffer buffer;
5657 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5658 ASSERT_VK_SUCCESS(err);
5659 // Allocate memory and bind to buffer so we can make it to the appropriate
5660 // error
5661 VkMemoryAllocateInfo mem_alloc = {};
5662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5663 mem_alloc.pNext = NULL;
5664 mem_alloc.allocationSize = 1024;
5665 mem_alloc.memoryTypeIndex = 0;
5666
5667 VkMemoryRequirements memReqs;
5668 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005670 if (!pass) {
5671 vkDestroyBuffer(m_device->device(), buffer, NULL);
5672 return;
5673 }
5674
5675 VkDeviceMemory mem;
5676 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5677 ASSERT_VK_SUCCESS(err);
5678 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5679 ASSERT_VK_SUCCESS(err);
5680 // Correctly update descriptor to avoid "NOT_UPDATED" error
5681 VkDescriptorBufferInfo buffInfo = {};
5682 buffInfo.buffer = buffer;
5683 buffInfo.offset = 0;
5684 buffInfo.range = 1024;
5685
5686 VkWriteDescriptorSet descriptor_write;
5687 memset(&descriptor_write, 0, sizeof(descriptor_write));
5688 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5689 descriptor_write.dstSet = descriptorSet;
5690 descriptor_write.dstBinding = 0;
5691 descriptor_write.descriptorCount = 1;
5692 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5693 descriptor_write.pBufferInfo = &buffInfo;
5694
5695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5696
5697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005698 char const *vsSource =
5699 "#version 450\n"
5700 "\n"
5701 "out gl_PerVertex { \n"
5702 " vec4 gl_Position;\n"
5703 "};\n"
5704 "void main(){\n"
5705 " gl_Position = vec4(1);\n"
5706 "}\n";
5707 char const *fsSource =
5708 "#version 450\n"
5709 "\n"
5710 "layout(location=0) out vec4 x;\n"
5711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5712 "void main(){\n"
5713 " x = vec4(bar.y);\n"
5714 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5717 VkPipelineObj pipe(m_device);
5718 pipe.AddShader(&vs);
5719 pipe.AddShader(&fs);
5720 pipe.AddColorAttachment();
5721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5722
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->BeginCommandBuffer();
5724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5727 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005728
5729 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5730 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5731
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005733 m_commandBuffer->EndRenderPass();
5734 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005736 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5737 vkDestroyBuffer(m_device->device(), buffer, NULL);
5738 // Attempt to submit cmd buffer
5739 VkSubmitInfo submit_info = {};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5743 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5744 m_errorMonitor->VerifyFound();
5745 // Cleanup
5746 vkFreeMemory(m_device->device(), mem, NULL);
5747
5748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5751}
5752
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005754 TEST_DESCRIPTION(
5755 "Attempt to draw with a command buffer that is invalid "
5756 "due to a bound descriptor sets with a combined image "
5757 "sampler having their image, sampler, and descriptor set "
5758 "each respectively destroyed and then attempting to "
5759 "submit associated cmd buffers. Attempt to destroy a "
5760 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005761 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
5765 VkDescriptorPoolSize ds_type_count = {};
5766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5767 ds_type_count.descriptorCount = 1;
5768
5769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5771 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005772 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005773 ds_pool_ci.maxSets = 1;
5774 ds_pool_ci.poolSizeCount = 1;
5775 ds_pool_ci.pPoolSizes = &ds_type_count;
5776
5777 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSetLayoutBinding dsl_binding = {};
5782 dsl_binding.binding = 0;
5783 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5784 dsl_binding.descriptorCount = 1;
5785 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5786 dsl_binding.pImmutableSamplers = NULL;
5787
5788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5790 ds_layout_ci.pNext = NULL;
5791 ds_layout_ci.bindingCount = 1;
5792 ds_layout_ci.pBindings = &dsl_binding;
5793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkDescriptorSet descriptorSet;
5798 VkDescriptorSetAllocateInfo alloc_info = {};
5799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5800 alloc_info.descriptorSetCount = 1;
5801 alloc_info.descriptorPool = ds_pool;
5802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005804 ASSERT_VK_SUCCESS(err);
5805
5806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5808 pipeline_layout_ci.pNext = NULL;
5809 pipeline_layout_ci.setLayoutCount = 1;
5810 pipeline_layout_ci.pSetLayouts = &ds_layout;
5811
5812 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005814 ASSERT_VK_SUCCESS(err);
5815
5816 // Create images to update the descriptor with
5817 VkImage image;
5818 VkImage image2;
5819 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5820 const int32_t tex_width = 32;
5821 const int32_t tex_height = 32;
5822 VkImageCreateInfo image_create_info = {};
5823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5824 image_create_info.pNext = NULL;
5825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5826 image_create_info.format = tex_format;
5827 image_create_info.extent.width = tex_width;
5828 image_create_info.extent.height = tex_height;
5829 image_create_info.extent.depth = 1;
5830 image_create_info.mipLevels = 1;
5831 image_create_info.arrayLayers = 1;
5832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5833 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5835 image_create_info.flags = 0;
5836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5837 ASSERT_VK_SUCCESS(err);
5838 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5839 ASSERT_VK_SUCCESS(err);
5840
5841 VkMemoryRequirements memory_reqs;
5842 VkDeviceMemory image_memory;
5843 bool pass;
5844 VkMemoryAllocateInfo memory_info = {};
5845 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5846 memory_info.pNext = NULL;
5847 memory_info.allocationSize = 0;
5848 memory_info.memoryTypeIndex = 0;
5849 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5850 // Allocate enough memory for both images
5851 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005853 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5857 ASSERT_VK_SUCCESS(err);
5858 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860 ASSERT_VK_SUCCESS(err);
5861
5862 VkImageViewCreateInfo image_view_create_info = {};
5863 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5864 image_view_create_info.image = image;
5865 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5866 image_view_create_info.format = tex_format;
5867 image_view_create_info.subresourceRange.layerCount = 1;
5868 image_view_create_info.subresourceRange.baseMipLevel = 0;
5869 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871
5872 VkImageView view;
5873 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005875 ASSERT_VK_SUCCESS(err);
5876 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005878 ASSERT_VK_SUCCESS(err);
5879 // Create Samplers
5880 VkSamplerCreateInfo sampler_ci = {};
5881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5882 sampler_ci.pNext = NULL;
5883 sampler_ci.magFilter = VK_FILTER_NEAREST;
5884 sampler_ci.minFilter = VK_FILTER_NEAREST;
5885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5889 sampler_ci.mipLodBias = 1.0;
5890 sampler_ci.anisotropyEnable = VK_FALSE;
5891 sampler_ci.maxAnisotropy = 1;
5892 sampler_ci.compareEnable = VK_FALSE;
5893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5894 sampler_ci.minLod = 1.0;
5895 sampler_ci.maxLod = 1.0;
5896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5898 VkSampler sampler;
5899 VkSampler sampler2;
5900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5901 ASSERT_VK_SUCCESS(err);
5902 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5903 ASSERT_VK_SUCCESS(err);
5904 // Update descriptor with image and sampler
5905 VkDescriptorImageInfo img_info = {};
5906 img_info.sampler = sampler;
5907 img_info.imageView = view;
5908 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5909
5910 VkWriteDescriptorSet descriptor_write;
5911 memset(&descriptor_write, 0, sizeof(descriptor_write));
5912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5913 descriptor_write.dstSet = descriptorSet;
5914 descriptor_write.dstBinding = 0;
5915 descriptor_write.descriptorCount = 1;
5916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5917 descriptor_write.pImageInfo = &img_info;
5918
5919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5920
5921 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005922 char const *vsSource =
5923 "#version 450\n"
5924 "\n"
5925 "out gl_PerVertex { \n"
5926 " vec4 gl_Position;\n"
5927 "};\n"
5928 "void main(){\n"
5929 " gl_Position = vec4(1);\n"
5930 "}\n";
5931 char const *fsSource =
5932 "#version 450\n"
5933 "\n"
5934 "layout(set=0, binding=0) uniform sampler2D s;\n"
5935 "layout(location=0) out vec4 x;\n"
5936 "void main(){\n"
5937 " x = texture(s, vec2(1));\n"
5938 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005939 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5940 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5941 VkPipelineObj pipe(m_device);
5942 pipe.AddShader(&vs);
5943 pipe.AddShader(&fs);
5944 pipe.AddColorAttachment();
5945 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5946
5947 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->BeginCommandBuffer();
5950 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5952 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5953 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005954 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5955 VkRect2D scissor = {{0, 0}, {16, 16}};
5956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5957 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005958 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005959 m_commandBuffer->EndRenderPass();
5960 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 // Destroy sampler invalidates the cmd buffer, causing error on submit
5962 vkDestroySampler(m_device->device(), sampler, NULL);
5963 // Attempt to submit cmd buffer
5964 VkSubmitInfo submit_info = {};
5965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5966 submit_info.commandBufferCount = 1;
5967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5969 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005970
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005971 // Now re-update descriptor with valid sampler and delete image
5972 img_info.sampler = sampler2;
5973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005974
5975 VkCommandBufferBeginInfo info = {};
5976 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5977 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005980 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005981 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5983 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5984 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005987 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005988 m_commandBuffer->EndRenderPass();
5989 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005990 // Destroy image invalidates the cmd buffer, causing error on submit
5991 vkDestroyImage(m_device->device(), image, NULL);
5992 // Attempt to submit cmd buffer
5993 submit_info = {};
5994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5995 submit_info.commandBufferCount = 1;
5996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5998 m_errorMonitor->VerifyFound();
5999 // Now update descriptor to be valid, but then free descriptor
6000 img_info.imageView = view2;
6001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006002 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6008 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006010 m_commandBuffer->EndRenderPass();
6011 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006013
6014 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006016 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006017 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006018
6019 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006020 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006021 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006022 m_errorMonitor->SetUnexpectedError(
6023 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6024 "either be a valid handle or VK_NULL_HANDLE");
6025 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006026 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6027
6028 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006029 submit_info = {};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6035 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006037 // Cleanup
6038 vkFreeMemory(m_device->device(), image_memory, NULL);
6039 vkDestroySampler(m_device->device(), sampler2, NULL);
6040 vkDestroyImage(m_device->device(), image2, NULL);
6041 vkDestroyImageView(m_device->device(), view, NULL);
6042 vkDestroyImageView(m_device->device(), view2, NULL);
6043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6046}
6047
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006048TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6049 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6050 ASSERT_NO_FATAL_FAILURE(InitState());
6051 ASSERT_NO_FATAL_FAILURE(InitViewport());
6052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6053
6054 VkDescriptorPoolSize ds_type_count = {};
6055 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6056 ds_type_count.descriptorCount = 1;
6057
6058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6060 ds_pool_ci.pNext = NULL;
6061 ds_pool_ci.maxSets = 1;
6062 ds_pool_ci.poolSizeCount = 1;
6063 ds_pool_ci.pPoolSizes = &ds_type_count;
6064
6065 VkDescriptorPool ds_pool;
6066 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6067 ASSERT_VK_SUCCESS(err);
6068
6069 VkDescriptorSetLayoutBinding dsl_binding = {};
6070 dsl_binding.binding = 0;
6071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6072 dsl_binding.descriptorCount = 1;
6073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6074 dsl_binding.pImmutableSamplers = NULL;
6075
6076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6078 ds_layout_ci.pNext = NULL;
6079 ds_layout_ci.bindingCount = 1;
6080 ds_layout_ci.pBindings = &dsl_binding;
6081 VkDescriptorSetLayout ds_layout;
6082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6083 ASSERT_VK_SUCCESS(err);
6084
6085 VkDescriptorSet descriptor_set;
6086 VkDescriptorSetAllocateInfo alloc_info = {};
6087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6088 alloc_info.descriptorSetCount = 1;
6089 alloc_info.descriptorPool = ds_pool;
6090 alloc_info.pSetLayouts = &ds_layout;
6091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6092 ASSERT_VK_SUCCESS(err);
6093
6094 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6095 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6096 pipeline_layout_ci.pNext = NULL;
6097 pipeline_layout_ci.setLayoutCount = 1;
6098 pipeline_layout_ci.pSetLayouts = &ds_layout;
6099
6100 VkPipelineLayout pipeline_layout;
6101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6102 ASSERT_VK_SUCCESS(err);
6103
6104 // Create image to update the descriptor with
6105 VkImageObj image(m_device);
6106 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6107 ASSERT_TRUE(image.initialized());
6108
6109 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6110 // Create Sampler
6111 VkSamplerCreateInfo sampler_ci = {};
6112 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6113 sampler_ci.pNext = NULL;
6114 sampler_ci.magFilter = VK_FILTER_NEAREST;
6115 sampler_ci.minFilter = VK_FILTER_NEAREST;
6116 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6117 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6118 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6119 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6120 sampler_ci.mipLodBias = 1.0;
6121 sampler_ci.anisotropyEnable = VK_FALSE;
6122 sampler_ci.maxAnisotropy = 1;
6123 sampler_ci.compareEnable = VK_FALSE;
6124 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6125 sampler_ci.minLod = 1.0;
6126 sampler_ci.maxLod = 1.0;
6127 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6128 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6129 VkSampler sampler;
6130 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6131 ASSERT_VK_SUCCESS(err);
6132 // Update descriptor with image and sampler
6133 VkDescriptorImageInfo img_info = {};
6134 img_info.sampler = sampler;
6135 img_info.imageView = view;
6136 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6137
6138 VkWriteDescriptorSet descriptor_write;
6139 memset(&descriptor_write, 0, sizeof(descriptor_write));
6140 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6141 descriptor_write.dstSet = descriptor_set;
6142 descriptor_write.dstBinding = 0;
6143 descriptor_write.descriptorCount = 1;
6144 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6145 descriptor_write.pImageInfo = &img_info;
6146
6147 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6148
6149 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006150 char const *vsSource =
6151 "#version 450\n"
6152 "\n"
6153 "out gl_PerVertex { \n"
6154 " vec4 gl_Position;\n"
6155 "};\n"
6156 "void main(){\n"
6157 " gl_Position = vec4(1);\n"
6158 "}\n";
6159 char const *fsSource =
6160 "#version 450\n"
6161 "\n"
6162 "layout(set=0, binding=0) uniform sampler2D s;\n"
6163 "layout(location=0) out vec4 x;\n"
6164 "void main(){\n"
6165 " x = texture(s, vec2(1));\n"
6166 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6169 VkPipelineObj pipe(m_device);
6170 pipe.AddShader(&vs);
6171 pipe.AddShader(&fs);
6172 pipe.AddColorAttachment();
6173 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6174
Tony Barbour552f6c02016-12-21 14:34:07 -07006175 m_commandBuffer->BeginCommandBuffer();
6176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006177 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6178 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6179 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006180
6181 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6182 VkRect2D scissor = {{0, 0}, {16, 16}};
6183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6184 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6185
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006186 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006187 m_commandBuffer->EndRenderPass();
6188 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189 // Submit cmd buffer to put pool in-flight
6190 VkSubmitInfo submit_info = {};
6191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6192 submit_info.commandBufferCount = 1;
6193 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6194 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6195 // Destroy pool while in-flight, causing error
6196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6198 m_errorMonitor->VerifyFound();
6199 vkQueueWaitIdle(m_device->m_queue);
6200 // Cleanup
6201 vkDestroySampler(m_device->device(), sampler, NULL);
6202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006204 m_errorMonitor->SetUnexpectedError(
6205 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6206 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006208 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006209}
6210
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006211TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6212 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6213 ASSERT_NO_FATAL_FAILURE(InitState());
6214 ASSERT_NO_FATAL_FAILURE(InitViewport());
6215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6216
6217 VkDescriptorPoolSize ds_type_count = {};
6218 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6219 ds_type_count.descriptorCount = 1;
6220
6221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6223 ds_pool_ci.pNext = NULL;
6224 ds_pool_ci.maxSets = 1;
6225 ds_pool_ci.poolSizeCount = 1;
6226 ds_pool_ci.pPoolSizes = &ds_type_count;
6227
6228 VkDescriptorPool ds_pool;
6229 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6230 ASSERT_VK_SUCCESS(err);
6231
6232 VkDescriptorSetLayoutBinding dsl_binding = {};
6233 dsl_binding.binding = 0;
6234 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6235 dsl_binding.descriptorCount = 1;
6236 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6237 dsl_binding.pImmutableSamplers = NULL;
6238
6239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6241 ds_layout_ci.pNext = NULL;
6242 ds_layout_ci.bindingCount = 1;
6243 ds_layout_ci.pBindings = &dsl_binding;
6244 VkDescriptorSetLayout ds_layout;
6245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6246 ASSERT_VK_SUCCESS(err);
6247
6248 VkDescriptorSet descriptorSet;
6249 VkDescriptorSetAllocateInfo alloc_info = {};
6250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6251 alloc_info.descriptorSetCount = 1;
6252 alloc_info.descriptorPool = ds_pool;
6253 alloc_info.pSetLayouts = &ds_layout;
6254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6255 ASSERT_VK_SUCCESS(err);
6256
6257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6259 pipeline_layout_ci.pNext = NULL;
6260 pipeline_layout_ci.setLayoutCount = 1;
6261 pipeline_layout_ci.pSetLayouts = &ds_layout;
6262
6263 VkPipelineLayout pipeline_layout;
6264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6265 ASSERT_VK_SUCCESS(err);
6266
6267 // Create images to update the descriptor with
6268 VkImage image;
6269 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6270 const int32_t tex_width = 32;
6271 const int32_t tex_height = 32;
6272 VkImageCreateInfo image_create_info = {};
6273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6274 image_create_info.pNext = NULL;
6275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6276 image_create_info.format = tex_format;
6277 image_create_info.extent.width = tex_width;
6278 image_create_info.extent.height = tex_height;
6279 image_create_info.extent.depth = 1;
6280 image_create_info.mipLevels = 1;
6281 image_create_info.arrayLayers = 1;
6282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6284 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6285 image_create_info.flags = 0;
6286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6287 ASSERT_VK_SUCCESS(err);
6288 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6289 VkMemoryRequirements memory_reqs;
6290 VkDeviceMemory image_memory;
6291 bool pass;
6292 VkMemoryAllocateInfo memory_info = {};
6293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6294 memory_info.pNext = NULL;
6295 memory_info.allocationSize = 0;
6296 memory_info.memoryTypeIndex = 0;
6297 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6298 // Allocate enough memory for image
6299 memory_info.allocationSize = memory_reqs.size;
6300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6301 ASSERT_TRUE(pass);
6302 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6303 ASSERT_VK_SUCCESS(err);
6304 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6305 ASSERT_VK_SUCCESS(err);
6306
6307 VkImageViewCreateInfo image_view_create_info = {};
6308 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6309 image_view_create_info.image = image;
6310 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6311 image_view_create_info.format = tex_format;
6312 image_view_create_info.subresourceRange.layerCount = 1;
6313 image_view_create_info.subresourceRange.baseMipLevel = 0;
6314 image_view_create_info.subresourceRange.levelCount = 1;
6315 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6316
6317 VkImageView view;
6318 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6319 ASSERT_VK_SUCCESS(err);
6320 // Create Samplers
6321 VkSamplerCreateInfo sampler_ci = {};
6322 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6323 sampler_ci.pNext = NULL;
6324 sampler_ci.magFilter = VK_FILTER_NEAREST;
6325 sampler_ci.minFilter = VK_FILTER_NEAREST;
6326 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6327 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6328 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6329 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6330 sampler_ci.mipLodBias = 1.0;
6331 sampler_ci.anisotropyEnable = VK_FALSE;
6332 sampler_ci.maxAnisotropy = 1;
6333 sampler_ci.compareEnable = VK_FALSE;
6334 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6335 sampler_ci.minLod = 1.0;
6336 sampler_ci.maxLod = 1.0;
6337 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6338 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6339 VkSampler sampler;
6340 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6341 ASSERT_VK_SUCCESS(err);
6342 // Update descriptor with image and sampler
6343 VkDescriptorImageInfo img_info = {};
6344 img_info.sampler = sampler;
6345 img_info.imageView = view;
6346 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6347
6348 VkWriteDescriptorSet descriptor_write;
6349 memset(&descriptor_write, 0, sizeof(descriptor_write));
6350 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6351 descriptor_write.dstSet = descriptorSet;
6352 descriptor_write.dstBinding = 0;
6353 descriptor_write.descriptorCount = 1;
6354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6355 descriptor_write.pImageInfo = &img_info;
6356 // Break memory binding and attempt update
6357 vkFreeMemory(m_device->device(), image_memory, nullptr);
6358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006359 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6361 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6363 m_errorMonitor->VerifyFound();
6364 // Cleanup
6365 vkDestroyImage(m_device->device(), image, NULL);
6366 vkDestroySampler(m_device->device(), sampler, NULL);
6367 vkDestroyImageView(m_device->device(), view, NULL);
6368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6371}
6372
Karl Schultz6addd812016-02-02 17:17:23 -07006373TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006374 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6375 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006376 // Create a valid cmd buffer
6377 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006378 uint64_t fake_pipeline_handle = 0xbaad6001;
6379 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006380 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6382
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006384 m_commandBuffer->BeginCommandBuffer();
6385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006387 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006388
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006389 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006391 Draw(1, 0, 0, 0);
6392 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006393
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006394 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006396 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006397 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6398 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006399}
6400
Karl Schultz6addd812016-02-02 17:17:23 -07006401TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006402 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006403 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006406
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006407 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006408 ASSERT_NO_FATAL_FAILURE(InitViewport());
6409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006410 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6412 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006413
6414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6416 ds_pool_ci.pNext = NULL;
6417 ds_pool_ci.maxSets = 1;
6418 ds_pool_ci.poolSizeCount = 1;
6419 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006420
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006423 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006424
Tony Barboureb254902015-07-15 12:50:33 -06006425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 dsl_binding.binding = 0;
6427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6428 dsl_binding.descriptorCount = 1;
6429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006431
Tony Barboureb254902015-07-15 12:50:33 -06006432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6434 ds_layout_ci.pNext = NULL;
6435 ds_layout_ci.bindingCount = 1;
6436 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006437 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006439 ASSERT_VK_SUCCESS(err);
6440
6441 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006442 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006444 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006445 alloc_info.descriptorPool = ds_pool;
6446 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006448 ASSERT_VK_SUCCESS(err);
6449
Tony Barboureb254902015-07-15 12:50:33 -06006450 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6452 pipeline_layout_ci.pNext = NULL;
6453 pipeline_layout_ci.setLayoutCount = 1;
6454 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
6456 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006458 ASSERT_VK_SUCCESS(err);
6459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006461 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006462 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006464
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006465 VkPipelineObj pipe(m_device);
6466 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006467 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006468 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006469 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006470
Tony Barbour552f6c02016-12-21 14:34:07 -07006471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6474 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006475
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006476 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477
Chia-I Wuf7458c52015-10-26 21:10:41 +08006478 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006481}
6482
Karl Schultz6addd812016-02-02 17:17:23 -07006483TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006484 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006486
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006488
6489 ASSERT_NO_FATAL_FAILURE(InitState());
6490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6492 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493
6494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6496 ds_pool_ci.pNext = NULL;
6497 ds_pool_ci.maxSets = 1;
6498 ds_pool_ci.poolSizeCount = 1;
6499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006500
6501 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006503 ASSERT_VK_SUCCESS(err);
6504
6505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 dsl_binding.binding = 0;
6507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6508 dsl_binding.descriptorCount = 1;
6509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6510 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511
6512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6514 ds_layout_ci.pNext = NULL;
6515 ds_layout_ci.bindingCount = 1;
6516 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006517 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006519 ASSERT_VK_SUCCESS(err);
6520
6521 VkDescriptorSet descriptorSet;
6522 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006525 alloc_info.descriptorPool = ds_pool;
6526 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006528 ASSERT_VK_SUCCESS(err);
6529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006530 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006531 VkWriteDescriptorSet descriptor_write;
6532 memset(&descriptor_write, 0, sizeof(descriptor_write));
6533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6534 descriptor_write.dstSet = descriptorSet;
6535 descriptor_write.dstBinding = 0;
6536 descriptor_write.descriptorCount = 1;
6537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6538 descriptor_write.pTexelBufferView = &view;
6539
6540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006543
6544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6546}
6547
Mark Youngd339ba32016-05-30 13:28:35 -06006548TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006549 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06006550
6551 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006553 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006554
6555 ASSERT_NO_FATAL_FAILURE(InitState());
6556
6557 // Create a buffer with no bound memory and then attempt to create
6558 // a buffer view.
6559 VkBufferCreateInfo buff_ci = {};
6560 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006561 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006562 buff_ci.size = 256;
6563 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6564 VkBuffer buffer;
6565 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6566 ASSERT_VK_SUCCESS(err);
6567
6568 VkBufferViewCreateInfo buff_view_ci = {};
6569 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6570 buff_view_ci.buffer = buffer;
6571 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6572 buff_view_ci.range = VK_WHOLE_SIZE;
6573 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006575
6576 m_errorMonitor->VerifyFound();
6577 vkDestroyBuffer(m_device->device(), buffer, NULL);
6578 // If last error is success, it still created the view, so delete it.
6579 if (err == VK_SUCCESS) {
6580 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6581 }
6582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6585 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6586 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006587 // 1. No dynamicOffset supplied
6588 // 2. Too many dynamicOffsets supplied
6589 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006590 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6592 " requires 1 dynamicOffsets, but only "
6593 "0 dynamicOffsets are left in "
6594 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006595
6596 ASSERT_NO_FATAL_FAILURE(InitState());
6597 ASSERT_NO_FATAL_FAILURE(InitViewport());
6598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6599
6600 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6602 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006603
6604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6606 ds_pool_ci.pNext = NULL;
6607 ds_pool_ci.maxSets = 1;
6608 ds_pool_ci.poolSizeCount = 1;
6609 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006613 ASSERT_VK_SUCCESS(err);
6614
6615 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006616 dsl_binding.binding = 0;
6617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 dsl_binding.descriptorCount = 1;
6619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6620 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006621
6622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6624 ds_layout_ci.pNext = NULL;
6625 ds_layout_ci.bindingCount = 1;
6626 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006627 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006629 ASSERT_VK_SUCCESS(err);
6630
6631 VkDescriptorSet descriptorSet;
6632 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006633 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006634 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006635 alloc_info.descriptorPool = ds_pool;
6636 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638 ASSERT_VK_SUCCESS(err);
6639
6640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6642 pipeline_layout_ci.pNext = NULL;
6643 pipeline_layout_ci.setLayoutCount = 1;
6644 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006645
6646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006648 ASSERT_VK_SUCCESS(err);
6649
6650 // Create a buffer to update the descriptor with
6651 uint32_t qfi = 0;
6652 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006653 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6654 buffCI.size = 1024;
6655 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6656 buffCI.queueFamilyIndexCount = 1;
6657 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006658
6659 VkBuffer dyub;
6660 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6661 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006662 // Allocate memory and bind to buffer so we can make it to the appropriate
6663 // error
6664 VkMemoryAllocateInfo mem_alloc = {};
6665 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6666 mem_alloc.pNext = NULL;
6667 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006668 mem_alloc.memoryTypeIndex = 0;
6669
6670 VkMemoryRequirements memReqs;
6671 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006673 if (!pass) {
6674 vkDestroyBuffer(m_device->device(), dyub, NULL);
6675 return;
6676 }
6677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 VkDeviceMemory mem;
6679 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6680 ASSERT_VK_SUCCESS(err);
6681 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6682 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 // Correctly update descriptor to avoid "NOT_UPDATED" error
6684 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 buffInfo.buffer = dyub;
6686 buffInfo.offset = 0;
6687 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006688
6689 VkWriteDescriptorSet descriptor_write;
6690 memset(&descriptor_write, 0, sizeof(descriptor_write));
6691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6692 descriptor_write.dstSet = descriptorSet;
6693 descriptor_write.dstBinding = 0;
6694 descriptor_write.descriptorCount = 1;
6695 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6696 descriptor_write.pBufferInfo = &buffInfo;
6697
6698 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6699
Tony Barbour552f6c02016-12-21 14:34:07 -07006700 m_commandBuffer->BeginCommandBuffer();
6701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6703 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006704 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006705 uint32_t pDynOff[2] = {512, 756};
6706 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6708 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6710 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006711 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006712 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6714 " dynamic offset 512 combined with "
6715 "offset 0 and range 1024 that "
6716 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006717 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006718 char const *vsSource =
6719 "#version 450\n"
6720 "\n"
6721 "out gl_PerVertex { \n"
6722 " vec4 gl_Position;\n"
6723 "};\n"
6724 "void main(){\n"
6725 " gl_Position = vec4(1);\n"
6726 "}\n";
6727 char const *fsSource =
6728 "#version 450\n"
6729 "\n"
6730 "layout(location=0) out vec4 x;\n"
6731 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6732 "void main(){\n"
6733 " x = vec4(bar.y);\n"
6734 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006735 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6736 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6737 VkPipelineObj pipe(m_device);
6738 pipe.AddShader(&vs);
6739 pipe.AddShader(&fs);
6740 pipe.AddColorAttachment();
6741 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6742
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006743 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6744 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6745 VkRect2D scissor = {{0, 0}, {16, 16}};
6746 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // This update should succeed, but offset size of 512 will overstep buffer
6750 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6752 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006753 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006755
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006756 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006757 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006758
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6762}
6763
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006764TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006765 TEST_DESCRIPTION(
6766 "Attempt to update a descriptor with a non-sparse buffer "
6767 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006768 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006770 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6772 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
6775 ASSERT_NO_FATAL_FAILURE(InitViewport());
6776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6777
6778 VkDescriptorPoolSize ds_type_count = {};
6779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6780 ds_type_count.descriptorCount = 1;
6781
6782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6784 ds_pool_ci.pNext = NULL;
6785 ds_pool_ci.maxSets = 1;
6786 ds_pool_ci.poolSizeCount = 1;
6787 ds_pool_ci.pPoolSizes = &ds_type_count;
6788
6789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006791 ASSERT_VK_SUCCESS(err);
6792
6793 VkDescriptorSetLayoutBinding dsl_binding = {};
6794 dsl_binding.binding = 0;
6795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6796 dsl_binding.descriptorCount = 1;
6797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6798 dsl_binding.pImmutableSamplers = NULL;
6799
6800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6802 ds_layout_ci.pNext = NULL;
6803 ds_layout_ci.bindingCount = 1;
6804 ds_layout_ci.pBindings = &dsl_binding;
6805 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006807 ASSERT_VK_SUCCESS(err);
6808
6809 VkDescriptorSet descriptorSet;
6810 VkDescriptorSetAllocateInfo alloc_info = {};
6811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6812 alloc_info.descriptorSetCount = 1;
6813 alloc_info.descriptorPool = ds_pool;
6814 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006816 ASSERT_VK_SUCCESS(err);
6817
6818 // Create a buffer to update the descriptor with
6819 uint32_t qfi = 0;
6820 VkBufferCreateInfo buffCI = {};
6821 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6822 buffCI.size = 1024;
6823 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6824 buffCI.queueFamilyIndexCount = 1;
6825 buffCI.pQueueFamilyIndices = &qfi;
6826
6827 VkBuffer dyub;
6828 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6829 ASSERT_VK_SUCCESS(err);
6830
6831 // Attempt to update descriptor without binding memory to it
6832 VkDescriptorBufferInfo buffInfo = {};
6833 buffInfo.buffer = dyub;
6834 buffInfo.offset = 0;
6835 buffInfo.range = 1024;
6836
6837 VkWriteDescriptorSet descriptor_write;
6838 memset(&descriptor_write, 0, sizeof(descriptor_write));
6839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6840 descriptor_write.dstSet = descriptorSet;
6841 descriptor_write.dstBinding = 0;
6842 descriptor_write.descriptorCount = 1;
6843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6844 descriptor_write.pBufferInfo = &buffInfo;
6845
6846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6847 m_errorMonitor->VerifyFound();
6848
6849 vkDestroyBuffer(m_device->device(), dyub, NULL);
6850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6852}
6853
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006855 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006856 ASSERT_NO_FATAL_FAILURE(InitState());
6857 ASSERT_NO_FATAL_FAILURE(InitViewport());
6858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6859
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006861 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.pushConstantRangeCount = 1;
6865 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6866
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006867 //
6868 // Check for invalid push constant ranges in pipeline layouts.
6869 //
6870 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006872 char const *msg;
6873 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006874
Karl Schultzc81037d2016-05-12 08:11:23 -06006875 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6876 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6877 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6878 "vkCreatePipelineLayout() call has push constants index 0 with "
6879 "size 0."},
6880 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6881 "vkCreatePipelineLayout() call has push constants index 0 with "
6882 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006883 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006884 "vkCreatePipelineLayout() call has push constants index 0 with "
6885 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006886 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006887 "vkCreatePipelineLayout() call has push constants index 0 with "
6888 "size 0."},
6889 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6890 "vkCreatePipelineLayout() call has push constants index 0 with "
6891 "offset 1. Offset must"},
6892 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6893 "vkCreatePipelineLayout() call has push constants index 0 "
6894 "with offset "},
6895 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6896 "vkCreatePipelineLayout() call has push constants "
6897 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006898 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006899 "vkCreatePipelineLayout() call has push constants index 0 "
6900 "with offset "},
6901 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6902 "vkCreatePipelineLayout() call has push "
6903 "constants index 0 with offset "},
6904 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6905 "vkCreatePipelineLayout() call has push "
6906 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006907 }};
6908
6909 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006910 for (const auto &iter : range_tests) {
6911 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914 m_errorMonitor->VerifyFound();
6915 if (VK_SUCCESS == err) {
6916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6917 }
6918 }
6919
6920 // Check for invalid stage flag
6921 pc_range.offset = 0;
6922 pc_range.size = 16;
6923 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006924 m_errorMonitor->SetDesiredFailureMsg(
6925 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6926 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006928 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929 if (VK_SUCCESS == err) {
6930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6931 }
6932
Karl Schultzc59b72d2017-02-24 15:45:05 -07006933 // Check for duplicate stage flags in a list of push constant ranges.
6934 // A shader can only have one push constant block and that block is mapped
6935 // to the push constant range that has that shader's stage flag set.
6936 // The shader's stage flag can only appear once in all the ranges, so the
6937 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006938 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006939 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006941 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006943 // Overlapping ranges are OK, but a stage flag can appear only once.
6944 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6945 {
6946 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6948 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6949 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006950 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006951 {
6952 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6953 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6954 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6955 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6956 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6957 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6961 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6962 }},
6963 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6964 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6965 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6966 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6967 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6968 {
6969 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6970 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6971 }},
6972 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6973 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6974 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6975 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6976 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6977 {
6978 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6979 }},
6980 },
6981 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006982
Karl Schultzc59b72d2017-02-24 15:45:05 -07006983 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006985 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988 m_errorMonitor->VerifyFound();
6989 if (VK_SUCCESS == err) {
6990 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6991 }
6992 }
6993
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006994 //
6995 // CmdPushConstants tests
6996 //
6997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006999 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007000 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007003 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007005 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007006
7007 const uint8_t dummy_values[100] = {};
7008
7009 m_commandBuffer->BeginCommandBuffer();
7010 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007011
7012 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007013 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007016 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007017
Karl Schultzc59b72d2017-02-24 15:45:05 -07007018 m_errorMonitor->ExpectSuccess();
7019 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7020 m_errorMonitor->VerifyNotFound();
7021 m_errorMonitor->ExpectSuccess();
7022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7023 m_errorMonitor->VerifyNotFound();
7024 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7025 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7026 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7027 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7028 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7029 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7030 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007031 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007032 for (const auto &iter : cmd_range_tests) {
7033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7034 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7035 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 m_errorMonitor->VerifyFound();
7037 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007038
Tony Barbour552f6c02016-12-21 14:34:07 -07007039 m_commandBuffer->EndRenderPass();
7040 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007041 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007042}
7043
Karl Schultz6addd812016-02-02 17:17:23 -07007044TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007046 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 ASSERT_NO_FATAL_FAILURE(InitState());
7049 ASSERT_NO_FATAL_FAILURE(InitViewport());
7050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7051
7052 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7053 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007054 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7055 ds_type_count[0].descriptorCount = 10;
7056 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7057 ds_type_count[1].descriptorCount = 2;
7058 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7059 ds_type_count[2].descriptorCount = 2;
7060 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7061 ds_type_count[3].descriptorCount = 5;
7062 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7063 // type
7064 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7065 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7066 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007067
7068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7070 ds_pool_ci.pNext = NULL;
7071 ds_pool_ci.maxSets = 5;
7072 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7073 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007074
7075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007077 ASSERT_VK_SUCCESS(err);
7078
7079 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7080 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 dsl_binding[0].binding = 0;
7082 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7083 dsl_binding[0].descriptorCount = 5;
7084 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7085 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 // Create layout identical to set0 layout but w/ different stageFlags
7088 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007089 dsl_fs_stage_only.binding = 0;
7090 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007092 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7093 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7097 ds_layout_ci.pNext = NULL;
7098 ds_layout_ci.bindingCount = 1;
7099 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 static const uint32_t NUM_LAYOUTS = 4;
7101 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007103 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7104 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007106 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007107 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 dsl_binding[0].binding = 0;
7111 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007112 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007113 dsl_binding[1].binding = 1;
7114 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7115 dsl_binding[1].descriptorCount = 2;
7116 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7117 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007118 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
7122 dsl_binding[0].binding = 0;
7123 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 ASSERT_VK_SUCCESS(err);
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 ASSERT_VK_SUCCESS(err);
7132
7133 static const uint32_t NUM_SETS = 4;
7134 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7135 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007137 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138 alloc_info.descriptorPool = ds_pool;
7139 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007141 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007142 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007143 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007147
7148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7150 pipeline_layout_ci.pNext = NULL;
7151 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7152 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007153
7154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007156 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007157 // Create pipelineLayout with only one setLayout
7158 pipeline_layout_ci.setLayoutCount = 1;
7159 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 ASSERT_VK_SUCCESS(err);
7162 // Create pipelineLayout with 2 descriptor setLayout at index 0
7163 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7164 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7169 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with UB type, but stageFlags for FS only
7173 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7174 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7178 VkDescriptorSetLayout pl_bad_s0[2] = {};
7179 pl_bad_s0[0] = ds_layout_fs_only;
7180 pl_bad_s0[1] = ds_layout[1];
7181 pipeline_layout_ci.setLayoutCount = 2;
7182 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7183 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007186
Tobin Ehlis88452832015-12-03 09:40:56 -07007187 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007188 char const *vsSource =
7189 "#version 450\n"
7190 "\n"
7191 "out gl_PerVertex {\n"
7192 " vec4 gl_Position;\n"
7193 "};\n"
7194 "void main(){\n"
7195 " gl_Position = vec4(1);\n"
7196 "}\n";
7197 char const *fsSource =
7198 "#version 450\n"
7199 "\n"
7200 "layout(location=0) out vec4 x;\n"
7201 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7202 "void main(){\n"
7203 " x = vec4(bar.y);\n"
7204 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007207 VkPipelineObj pipe(m_device);
7208 pipe.AddShader(&vs);
7209 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 pipe.AddColorAttachment();
7211 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212
Tony Barbour552f6c02016-12-21 14:34:07 -07007213 m_commandBuffer->BeginCommandBuffer();
7214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007216 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007217 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7218 // of PSO
7219 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7220 // cmd_pipeline.c
7221 // due to the fact that cmd_alloc_dset_data() has not been called in
7222 // cmd_bind_graphics_pipeline()
7223 // TODO : Want to cause various binding incompatibility issues here to test
7224 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 // First cause various verify_layout_compatibility() fails
7226 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007227 // verify_set_layout_compatibility fail cases:
7228 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7231 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007232 m_errorMonitor->VerifyFound();
7233
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007234 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7237 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007238 m_errorMonitor->VerifyFound();
7239
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007240 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007241 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7242 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7245 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
7247
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007248 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7249 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7252 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007253 m_errorMonitor->VerifyFound();
7254
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7256 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7258 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Cause INFO messages due to disturbing previously bound Sets
7264 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7266 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007267 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7270 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
7272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7274 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007275 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7277 " newly bound as set #0 so set #1 and "
7278 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7280 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis10fad692016-07-07 12:00:36 -06007283 // Now that we're done actively using the pipelineLayout that gfx pipeline
7284 // was created with, we should be able to delete it. Do that now to verify
7285 // that validation obeys pipelineLayout lifetime
7286 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7287
Tobin Ehlis88452832015-12-03 09:40:56 -07007288 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007289 // 1. Error due to not binding required set (we actually use same code as
7290 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7292 &descriptorSet[0], 0, NULL);
7293 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7294 &descriptorSet[1], 0, NULL);
7295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007296
7297 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7298 VkRect2D scissor = {{0, 0}, {16, 16}};
7299 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7300 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7301
Tobin Ehlis88452832015-12-03 09:40:56 -07007302 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007303 m_errorMonitor->VerifyFound();
7304
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007305 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007306 // 2. Error due to bound set not being compatible with PSO's
7307 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007308 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7309 &descriptorSet[0], 0, NULL);
7310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007311 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
7313
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007314 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007315 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7317 }
7318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7321}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007322
Karl Schultz6addd812016-02-02 17:17:23 -07007323TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7325 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007326
7327 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007329 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007332 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007333}
7334
Karl Schultz6addd812016-02-02 17:17:23 -07007335TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7336 VkResult err;
7337 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007338
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007344 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007345 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 cmd.commandPool = m_commandPool;
7347 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007348 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007351 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007352
7353 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007354 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007355 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7356
7357 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007358 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007359 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007361 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007362
7363 // The error should be caught by validation of the BeginCommandBuffer call
7364 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007366 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007367 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007368}
7369
Karl Schultz6addd812016-02-02 17:17:23 -07007370TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007371 // Cause error due to Begin while recording CB
7372 // Then cause 2 errors for attempting to reset CB w/o having
7373 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7374 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376
7377 ASSERT_NO_FATAL_FAILURE(InitState());
7378
7379 // Calls AllocateCommandBuffers
7380 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007382 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007383 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007384 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7385 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007386 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7387 cmd_buf_info.pNext = NULL;
7388 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007389 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007390
7391 // Begin CB to transition to recording state
7392 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7393 // Can't re-begin. This should trigger error
7394 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007395 m_errorMonitor->VerifyFound();
7396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007398 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007399 // Reset attempt will trigger error due to incorrect CommandPool state
7400 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007401 m_errorMonitor->VerifyFound();
7402
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Transition CB to RECORDED state
7405 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7406 // Now attempting to Begin will implicitly reset, which triggers error
7407 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409}
7410
Karl Schultz6addd812016-02-02 17:17:23 -07007411TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007413 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7416 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007417
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007420
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007421 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7423 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007424
7425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7427 ds_pool_ci.pNext = NULL;
7428 ds_pool_ci.maxSets = 1;
7429 ds_pool_ci.poolSizeCount = 1;
7430 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007431
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007432 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007434 ASSERT_VK_SUCCESS(err);
7435
Tony Barboureb254902015-07-15 12:50:33 -06007436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007437 dsl_binding.binding = 0;
7438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7439 dsl_binding.descriptorCount = 1;
7440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007442
Tony Barboureb254902015-07-15 12:50:33 -06007443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7445 ds_layout_ci.pNext = NULL;
7446 ds_layout_ci.bindingCount = 1;
7447 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
7453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007457 alloc_info.descriptorPool = ds_pool;
7458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007460 ASSERT_VK_SUCCESS(err);
7461
Tony Barboureb254902015-07-15 12:50:33 -06007462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7464 pipeline_layout_ci.setLayoutCount = 1;
7465 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007466
7467 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007469 ASSERT_VK_SUCCESS(err);
7470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007471 VkViewport vp = {}; // Just need dummy vp to point to
7472 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007475 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7476 vp_state_ci.scissorCount = 1;
7477 vp_state_ci.pScissors = &sc;
7478 vp_state_ci.viewportCount = 1;
7479 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007481 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7482 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7483 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7484 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7485 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7486 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007487 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 rs_state_ci.lineWidth = 1.0f;
7490
7491 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7492 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7493 vi_ci.pNext = nullptr;
7494 vi_ci.vertexBindingDescriptionCount = 0;
7495 vi_ci.pVertexBindingDescriptions = nullptr;
7496 vi_ci.vertexAttributeDescriptionCount = 0;
7497 vi_ci.pVertexAttributeDescriptions = nullptr;
7498
7499 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7500 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7501 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7502
7503 VkPipelineShaderStageCreateInfo shaderStages[2];
7504 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7505
7506 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7507 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007508 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007509 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007510
Tony Barboureb254902015-07-15 12:50:33 -06007511 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7513 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007514 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7516 gp_ci.layout = pipeline_layout;
7517 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007518 gp_ci.pVertexInputState = &vi_ci;
7519 gp_ci.pInputAssemblyState = &ia_ci;
7520
7521 gp_ci.stageCount = 1;
7522 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007523
7524 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7526 pc_ci.initialDataSize = 0;
7527 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007530 VkPipelineCache pipelineCache;
7531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007533 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007536
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007541}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007542
Tobin Ehlis912df022015-09-17 08:46:18 -06007543/*// TODO : This test should be good, but needs Tess support in compiler to run
7544TEST_F(VkLayerTest, InvalidPatchControlPoints)
7545{
7546 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007548
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007550 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7551primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007552
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 ASSERT_NO_FATAL_FAILURE(InitState());
7554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007555
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007556 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007558 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559
7560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7562 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007563 ds_pool_ci.poolSizeCount = 1;
7564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007565
7566 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007567 err = vkCreateDescriptorPool(m_device->device(),
7568VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007569 ASSERT_VK_SUCCESS(err);
7570
7571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007572 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007574 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7576 dsl_binding.pImmutableSamplers = NULL;
7577
7578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007579 ds_layout_ci.sType =
7580VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007581 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007582 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007583 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007584
7585 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7587&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007588 ASSERT_VK_SUCCESS(err);
7589
7590 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7592VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007596 pipeline_layout_ci.sType =
7597VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007599 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007600 pipeline_layout_ci.pSetLayouts = &ds_layout;
7601
7602 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7604&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkPipelineShaderStageCreateInfo shaderStages[3];
7608 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7609
Karl Schultz6addd812016-02-02 17:17:23 -07007610 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7611this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007612 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007613 VkShaderObj
7614tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7615this);
7616 VkShaderObj
7617te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7618this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007619
Karl Schultz6addd812016-02-02 17:17:23 -07007620 shaderStages[0].sType =
7621VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007622 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007623 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007624 shaderStages[1].sType =
7625VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007626 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007627 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007628 shaderStages[2].sType =
7629VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007630 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007631 shaderStages[2].shader = te.handle();
7632
7633 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007634 iaCI.sType =
7635VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007636 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007637
7638 VkPipelineTessellationStateCreateInfo tsCI = {};
7639 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7640 tsCI.patchControlPoints = 0; // This will cause an error
7641
7642 VkGraphicsPipelineCreateInfo gp_ci = {};
7643 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7644 gp_ci.pNext = NULL;
7645 gp_ci.stageCount = 3;
7646 gp_ci.pStages = shaderStages;
7647 gp_ci.pVertexInputState = NULL;
7648 gp_ci.pInputAssemblyState = &iaCI;
7649 gp_ci.pTessellationState = &tsCI;
7650 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007651 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007652 gp_ci.pMultisampleState = NULL;
7653 gp_ci.pDepthStencilState = NULL;
7654 gp_ci.pColorBlendState = NULL;
7655 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7656 gp_ci.layout = pipeline_layout;
7657 gp_ci.renderPass = renderPass();
7658
7659 VkPipelineCacheCreateInfo pc_ci = {};
7660 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7661 pc_ci.pNext = NULL;
7662 pc_ci.initialSize = 0;
7663 pc_ci.initialData = 0;
7664 pc_ci.maxSize = 0;
7665
7666 VkPipeline pipeline;
7667 VkPipelineCache pipelineCache;
7668
Karl Schultz6addd812016-02-02 17:17:23 -07007669 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7670&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007671 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7673&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007674
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007675 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007676
Chia-I Wuf7458c52015-10-26 21:10:41 +08007677 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007681}
7682*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007683
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007684TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007685 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007687 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689 ASSERT_NO_FATAL_FAILURE(InitState());
7690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7694 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695
7696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7698 ds_pool_ci.maxSets = 1;
7699 ds_pool_ci.poolSizeCount = 1;
7700 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007701
7702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 dsl_binding.binding = 0;
7708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7709 dsl_binding.descriptorCount = 1;
7710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007711
7712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7714 ds_layout_ci.bindingCount = 1;
7715 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007724 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007725 alloc_info.descriptorPool = ds_pool;
7726 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728 ASSERT_VK_SUCCESS(err);
7729
7730 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7732 pipeline_layout_ci.setLayoutCount = 1;
7733 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734
7735 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007737 ASSERT_VK_SUCCESS(err);
7738
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007739 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007740 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007741 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007742 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007743 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007744 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007746 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7747 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7748 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7749 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7750 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7751 rs_state_ci.depthClampEnable = VK_FALSE;
7752 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7753 rs_state_ci.depthBiasEnable = VK_FALSE;
7754
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007755 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7756 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7757 vi_ci.pNext = nullptr;
7758 vi_ci.vertexBindingDescriptionCount = 0;
7759 vi_ci.pVertexBindingDescriptions = nullptr;
7760 vi_ci.vertexAttributeDescriptionCount = 0;
7761 vi_ci.pVertexAttributeDescriptions = nullptr;
7762
7763 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7764 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7765 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7766
7767 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7768 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7769 pipe_ms_state_ci.pNext = NULL;
7770 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7771 pipe_ms_state_ci.sampleShadingEnable = 0;
7772 pipe_ms_state_ci.minSampleShading = 1.0;
7773 pipe_ms_state_ci.pSampleMask = NULL;
7774
Cody Northropeb3a6c12015-10-05 14:44:45 -06007775 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007776 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007779 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007780 shaderStages[0] = vs.GetStageCreateInfo();
7781 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
7783 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007784 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7785 gp_ci.stageCount = 2;
7786 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007787 gp_ci.pVertexInputState = &vi_ci;
7788 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007790 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007791 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007792 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7793 gp_ci.layout = pipeline_layout;
7794 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007795
7796 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007797 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007798
7799 VkPipeline pipeline;
7800 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007802 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007804 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007805 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806
7807 // Check case where multiViewport is disabled and viewport count is not 1
7808 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7811 vp_state_ci.scissorCount = 0;
7812 vp_state_ci.viewportCount = 0;
7813 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7814 m_errorMonitor->VerifyFound();
7815 } else {
7816 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007817 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007818 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007819 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007820
7821 // Check is that viewportcount and scissorcount match
7822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7823 vp_state_ci.scissorCount = 1;
7824 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7825 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7826 m_errorMonitor->VerifyFound();
7827
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007828 // Check case where multiViewport is enabled and viewport count is greater than max
7829 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7832 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7833 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7834 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7835 m_errorMonitor->VerifyFound();
7836 }
7837 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
Chia-I Wuf7458c52015-10-26 21:10:41 +08007839 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007844
7845// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7846// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007848 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007850 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7851
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007853
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007857 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7859 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860
7861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
7867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007869 ASSERT_VK_SUCCESS(err);
7870
7871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007876
7877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7879 ds_layout_ci.bindingCount = 1;
7880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007884 ASSERT_VK_SUCCESS(err);
7885
7886 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007887 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007889 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007890 alloc_info.descriptorPool = ds_pool;
7891 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 ASSERT_VK_SUCCESS(err);
7894
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007895 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7896 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7897 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7898
7899 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7900 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7901 vi_ci.pNext = nullptr;
7902 vi_ci.vertexBindingDescriptionCount = 0;
7903 vi_ci.pVertexBindingDescriptions = nullptr;
7904 vi_ci.vertexAttributeDescriptionCount = 0;
7905 vi_ci.pVertexAttributeDescriptions = nullptr;
7906
7907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7909 pipe_ms_state_ci.pNext = NULL;
7910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7911 pipe_ms_state_ci.sampleShadingEnable = 0;
7912 pipe_ms_state_ci.minSampleShading = 1.0;
7913 pipe_ms_state_ci.pSampleMask = NULL;
7914
Tobin Ehlise68360f2015-10-01 11:15:13 -06007915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7917 pipeline_layout_ci.setLayoutCount = 1;
7918 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
7920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922 ASSERT_VK_SUCCESS(err);
7923
7924 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7925 // Set scissor as dynamic to avoid second error
7926 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7928 dyn_state_ci.dynamicStateCount = 1;
7929 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007930
Cody Northropeb3a6c12015-10-05 14:44:45 -06007931 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007932 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7936 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007937 shaderStages[0] = vs.GetStageCreateInfo();
7938 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007940 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7941 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7942 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7943 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7944 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7945 rs_state_ci.depthClampEnable = VK_FALSE;
7946 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7947 rs_state_ci.depthBiasEnable = VK_FALSE;
7948
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007950 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7951 gp_ci.stageCount = 2;
7952 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007953 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007954 // Not setting VP state w/o dynamic vp state should cause validation error
7955 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007956 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007957 gp_ci.pVertexInputState = &vi_ci;
7958 gp_ci.pInputAssemblyState = &ia_ci;
7959 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007960 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7961 gp_ci.layout = pipeline_layout;
7962 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
7964 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007965 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
7967 VkPipeline pipeline;
7968 VkPipelineCache pipelineCache;
7969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007974 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wuf7458c52015-10-26 21:10:41 +08007976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007981
7982// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7983// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007984TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7985 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007988
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007990
7991 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007992 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007993 return;
7994 }
7995
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007998 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8000 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8004 ds_pool_ci.maxSets = 1;
8005 ds_pool_ci.poolSizeCount = 1;
8006 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007
8008 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008010 ASSERT_VK_SUCCESS(err);
8011
8012 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008013 dsl_binding.binding = 0;
8014 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8015 dsl_binding.descriptorCount = 1;
8016 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008017
8018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8020 ds_layout_ci.bindingCount = 1;
8021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_VK_SUCCESS(err);
8026
8027 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008028 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008030 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008031 alloc_info.descriptorPool = ds_pool;
8032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034 ASSERT_VK_SUCCESS(err);
8035
8036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8038 pipeline_layout_ci.setLayoutCount = 1;
8039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008040
8041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008043 ASSERT_VK_SUCCESS(err);
8044
8045 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008046 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8047 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008048 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008051
8052 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8053 // Set scissor as dynamic to avoid that error
8054 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008055 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8056 dyn_state_ci.dynamicStateCount = 1;
8057 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008059 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8060 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8061 pipe_ms_state_ci.pNext = NULL;
8062 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8063 pipe_ms_state_ci.sampleShadingEnable = 0;
8064 pipe_ms_state_ci.minSampleShading = 1.0;
8065 pipe_ms_state_ci.pSampleMask = NULL;
8066
Cody Northropeb3a6c12015-10-05 14:44:45 -06008067 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8072 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008073 shaderStages[0] = vs.GetStageCreateInfo();
8074 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
Cody Northropf6622dc2015-10-06 10:33:21 -06008076 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8077 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8078 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008079 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008081 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 vi_ci.pVertexAttributeDescriptions = nullptr;
8083
8084 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8085 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8086 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008088 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008089 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008090 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008091 rs_ci.pNext = nullptr;
8092
Mark Youngc89c6312016-03-31 16:03:20 -06008093 VkPipelineColorBlendAttachmentState att = {};
8094 att.blendEnable = VK_FALSE;
8095 att.colorWriteMask = 0xf;
8096
Cody Northropf6622dc2015-10-06 10:33:21 -06008097 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8098 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8099 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008100 cb_ci.attachmentCount = 1;
8101 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008102
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8105 gp_ci.stageCount = 2;
8106 gp_ci.pStages = shaderStages;
8107 gp_ci.pVertexInputState = &vi_ci;
8108 gp_ci.pInputAssemblyState = &ia_ci;
8109 gp_ci.pViewportState = &vp_state_ci;
8110 gp_ci.pRasterizationState = &rs_ci;
8111 gp_ci.pColorBlendState = &cb_ci;
8112 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008113 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008114 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8115 gp_ci.layout = pipeline_layout;
8116 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008117
8118 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120
8121 VkPipeline pipeline;
8122 VkPipelineCache pipelineCache;
8123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008128 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008129
Tobin Ehlisd332f282015-10-02 11:00:56 -06008130 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008131 // First need to successfully create the PSO from above by setting
8132 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07008134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008135 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008136 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008138 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008139 m_commandBuffer->BeginCommandBuffer();
8140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008142 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008143 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008145 Draw(1, 0, 0, 0);
8146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008147 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008148
8149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008153 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008154}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008155
8156// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008157// viewportCount
8158TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8159 VkResult err;
8160
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008162
8163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008164
8165 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008166 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008167 return;
8168 }
8169
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8171
8172 VkDescriptorPoolSize ds_type_count = {};
8173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8174 ds_type_count.descriptorCount = 1;
8175
8176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8178 ds_pool_ci.maxSets = 1;
8179 ds_pool_ci.poolSizeCount = 1;
8180 ds_pool_ci.pPoolSizes = &ds_type_count;
8181
8182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008184 ASSERT_VK_SUCCESS(err);
8185
8186 VkDescriptorSetLayoutBinding dsl_binding = {};
8187 dsl_binding.binding = 0;
8188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8189 dsl_binding.descriptorCount = 1;
8190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8191
8192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8194 ds_layout_ci.bindingCount = 1;
8195 ds_layout_ci.pBindings = &dsl_binding;
8196
8197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ASSERT_VK_SUCCESS(err);
8200
8201 VkDescriptorSet descriptorSet;
8202 VkDescriptorSetAllocateInfo alloc_info = {};
8203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8204 alloc_info.descriptorSetCount = 1;
8205 alloc_info.descriptorPool = ds_pool;
8206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008208 ASSERT_VK_SUCCESS(err);
8209
8210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8212 pipeline_layout_ci.setLayoutCount = 1;
8213 pipeline_layout_ci.pSetLayouts = &ds_layout;
8214
8215 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008217 ASSERT_VK_SUCCESS(err);
8218
8219 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8220 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8221 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008222 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225
8226 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8227 // Set scissor as dynamic to avoid that error
8228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8230 dyn_state_ci.dynamicStateCount = 1;
8231 dyn_state_ci.pDynamicStates = &vp_state;
8232
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008233 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8234 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8235 pipe_ms_state_ci.pNext = NULL;
8236 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8237 pipe_ms_state_ci.sampleShadingEnable = 0;
8238 pipe_ms_state_ci.minSampleShading = 1.0;
8239 pipe_ms_state_ci.pSampleMask = NULL;
8240
Karl Schultz6addd812016-02-02 17:17:23 -07008241 VkPipelineShaderStageCreateInfo shaderStages[2];
8242 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8246 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07008247 shaderStages[0] = vs.GetStageCreateInfo();
8248 shaderStages[1] = fs.GetStageCreateInfo();
8249
8250 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8251 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8252 vi_ci.pNext = nullptr;
8253 vi_ci.vertexBindingDescriptionCount = 0;
8254 vi_ci.pVertexBindingDescriptions = nullptr;
8255 vi_ci.vertexAttributeDescriptionCount = 0;
8256 vi_ci.pVertexAttributeDescriptions = nullptr;
8257
8258 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8259 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8260 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8261
8262 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8263 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008264 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008265 rs_ci.pNext = nullptr;
8266
Mark Youngc89c6312016-03-31 16:03:20 -06008267 VkPipelineColorBlendAttachmentState att = {};
8268 att.blendEnable = VK_FALSE;
8269 att.colorWriteMask = 0xf;
8270
Karl Schultz6addd812016-02-02 17:17:23 -07008271 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8272 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8273 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008274 cb_ci.attachmentCount = 1;
8275 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008276
8277 VkGraphicsPipelineCreateInfo gp_ci = {};
8278 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8279 gp_ci.stageCount = 2;
8280 gp_ci.pStages = shaderStages;
8281 gp_ci.pVertexInputState = &vi_ci;
8282 gp_ci.pInputAssemblyState = &ia_ci;
8283 gp_ci.pViewportState = &vp_state_ci;
8284 gp_ci.pRasterizationState = &rs_ci;
8285 gp_ci.pColorBlendState = &cb_ci;
8286 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008287 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008288 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8289 gp_ci.layout = pipeline_layout;
8290 gp_ci.renderPass = renderPass();
8291
8292 VkPipelineCacheCreateInfo pc_ci = {};
8293 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8294
8295 VkPipeline pipeline;
8296 VkPipelineCache pipelineCache;
8297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008299 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008303
8304 // Now hit second fail case where we set scissor w/ different count than PSO
8305 // First need to successfully create the PSO from above by setting
8306 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8308 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008310 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008314 m_commandBuffer->BeginCommandBuffer();
8315 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008317 VkViewport viewports[1] = {};
8318 viewports[0].width = 8;
8319 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008320 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008321 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008322 Draw(1, 0, 0, 0);
8323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008324 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
Chia-I Wuf7458c52015-10-26 21:10:41 +08008326 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008330 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008331}
8332
Mark Young7394fdd2016-03-31 14:56:43 -06008333TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8334 VkResult err;
8335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008337
8338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8340
8341 VkDescriptorPoolSize ds_type_count = {};
8342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8343 ds_type_count.descriptorCount = 1;
8344
8345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8347 ds_pool_ci.maxSets = 1;
8348 ds_pool_ci.poolSizeCount = 1;
8349 ds_pool_ci.pPoolSizes = &ds_type_count;
8350
8351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008353 ASSERT_VK_SUCCESS(err);
8354
8355 VkDescriptorSetLayoutBinding dsl_binding = {};
8356 dsl_binding.binding = 0;
8357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8358 dsl_binding.descriptorCount = 1;
8359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8360
8361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8363 ds_layout_ci.bindingCount = 1;
8364 ds_layout_ci.pBindings = &dsl_binding;
8365
8366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkDescriptorSet descriptorSet;
8371 VkDescriptorSetAllocateInfo alloc_info = {};
8372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8373 alloc_info.descriptorSetCount = 1;
8374 alloc_info.descriptorPool = ds_pool;
8375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008377 ASSERT_VK_SUCCESS(err);
8378
8379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8381 pipeline_layout_ci.setLayoutCount = 1;
8382 pipeline_layout_ci.pSetLayouts = &ds_layout;
8383
8384 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008386 ASSERT_VK_SUCCESS(err);
8387
8388 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8389 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8390 vp_state_ci.scissorCount = 1;
8391 vp_state_ci.pScissors = NULL;
8392 vp_state_ci.viewportCount = 1;
8393 vp_state_ci.pViewports = NULL;
8394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008396 // Set scissor as dynamic to avoid that error
8397 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8398 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8399 dyn_state_ci.dynamicStateCount = 2;
8400 dyn_state_ci.pDynamicStates = dynamic_states;
8401
8402 VkPipelineShaderStageCreateInfo shaderStages[2];
8403 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8406 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008407 this); // TODO - We shouldn't need a fragment shader
8408 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008409 shaderStages[0] = vs.GetStageCreateInfo();
8410 shaderStages[1] = fs.GetStageCreateInfo();
8411
8412 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8413 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8414 vi_ci.pNext = nullptr;
8415 vi_ci.vertexBindingDescriptionCount = 0;
8416 vi_ci.pVertexBindingDescriptions = nullptr;
8417 vi_ci.vertexAttributeDescriptionCount = 0;
8418 vi_ci.pVertexAttributeDescriptions = nullptr;
8419
8420 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8421 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8422 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8423
8424 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8425 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8426 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008427 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008428
Mark Young47107952016-05-02 15:59:55 -06008429 // Check too low (line width of -1.0f).
8430 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008431
8432 VkPipelineColorBlendAttachmentState att = {};
8433 att.blendEnable = VK_FALSE;
8434 att.colorWriteMask = 0xf;
8435
8436 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8437 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8438 cb_ci.pNext = nullptr;
8439 cb_ci.attachmentCount = 1;
8440 cb_ci.pAttachments = &att;
8441
8442 VkGraphicsPipelineCreateInfo gp_ci = {};
8443 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8444 gp_ci.stageCount = 2;
8445 gp_ci.pStages = shaderStages;
8446 gp_ci.pVertexInputState = &vi_ci;
8447 gp_ci.pInputAssemblyState = &ia_ci;
8448 gp_ci.pViewportState = &vp_state_ci;
8449 gp_ci.pRasterizationState = &rs_ci;
8450 gp_ci.pColorBlendState = &cb_ci;
8451 gp_ci.pDynamicState = &dyn_state_ci;
8452 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8453 gp_ci.layout = pipeline_layout;
8454 gp_ci.renderPass = renderPass();
8455
8456 VkPipelineCacheCreateInfo pc_ci = {};
8457 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8458
8459 VkPipeline pipeline;
8460 VkPipelineCache pipelineCache;
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008463 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008465
8466 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008467 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too high (line width of 65536.0f).
8472 rs_ci.lineWidth = 65536.0f;
8473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008477
8478 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008479 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 dyn_state_ci.dynamicStateCount = 3;
8484
8485 rs_ci.lineWidth = 1.0f;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008490 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008492
8493 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008494 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008495 m_errorMonitor->VerifyFound();
8496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008498
8499 // Check too high with dynamic setting.
8500 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8501 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008502 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8505 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8506 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8507 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008508 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008509}
8510
Karl Schultz6addd812016-02-02 17:17:23 -07008511TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008512 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008514 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008515
8516 ASSERT_NO_FATAL_FAILURE(InitState());
8517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008518
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008520 // Don't care about RenderPass handle b/c error should be flagged before
8521 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008524 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008525}
8526
Karl Schultz6addd812016-02-02 17:17:23 -07008527TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008528 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8530 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008531
8532 ASSERT_NO_FATAL_FAILURE(InitState());
8533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008534
Tony Barbour552f6c02016-12-21 14:34:07 -07008535 m_commandBuffer->BeginCommandBuffer();
8536 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008537 // Just create a dummy Renderpass that's non-NULL so we can get to the
8538 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008541 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008542}
8543
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008544TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008545 TEST_DESCRIPTION(
8546 "Begin a renderPass where clearValueCount is less than"
8547 "the number of renderPass attachments that use loadOp"
8548 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8552
8553 // Create a renderPass with a single attachment that uses loadOp CLEAR
8554 VkAttachmentReference attach = {};
8555 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8556 VkSubpassDescription subpass = {};
8557 subpass.inputAttachmentCount = 1;
8558 subpass.pInputAttachments = &attach;
8559 VkRenderPassCreateInfo rpci = {};
8560 rpci.subpassCount = 1;
8561 rpci.pSubpasses = &subpass;
8562 rpci.attachmentCount = 1;
8563 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008564 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008565 // Set loadOp to CLEAR
8566 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8567 rpci.pAttachments = &attach_desc;
8568 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8569 VkRenderPass rp;
8570 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8571
8572 VkCommandBufferInheritanceInfo hinfo = {};
8573 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8574 hinfo.renderPass = VK_NULL_HANDLE;
8575 hinfo.subpass = 0;
8576 hinfo.framebuffer = VK_NULL_HANDLE;
8577 hinfo.occlusionQueryEnable = VK_FALSE;
8578 hinfo.queryFlags = 0;
8579 hinfo.pipelineStatistics = 0;
8580 VkCommandBufferBeginInfo info = {};
8581 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8582 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8583 info.pInheritanceInfo = &hinfo;
8584
8585 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8586 VkRenderPassBeginInfo rp_begin = {};
8587 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8588 rp_begin.pNext = NULL;
8589 rp_begin.renderPass = renderPass();
8590 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008591 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008592
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008596
8597 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008598
8599 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008600}
8601
Slawomir Cygan0808f392016-11-28 17:53:23 +01008602TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 TEST_DESCRIPTION(
8604 "Begin a renderPass where clearValueCount is greater than"
8605 "the number of renderPass attachments that use loadOp"
8606 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607
8608 ASSERT_NO_FATAL_FAILURE(InitState());
8609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8610
8611 // Create a renderPass with a single attachment that uses loadOp CLEAR
8612 VkAttachmentReference attach = {};
8613 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8614 VkSubpassDescription subpass = {};
8615 subpass.inputAttachmentCount = 1;
8616 subpass.pInputAttachments = &attach;
8617 VkRenderPassCreateInfo rpci = {};
8618 rpci.subpassCount = 1;
8619 rpci.pSubpasses = &subpass;
8620 rpci.attachmentCount = 1;
8621 VkAttachmentDescription attach_desc = {};
8622 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8623 // Set loadOp to CLEAR
8624 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8625 rpci.pAttachments = &attach_desc;
8626 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8627 VkRenderPass rp;
8628 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8629
8630 VkCommandBufferBeginInfo info = {};
8631 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8632 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8633
8634 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8635 VkRenderPassBeginInfo rp_begin = {};
8636 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8637 rp_begin.pNext = NULL;
8638 rp_begin.renderPass = renderPass();
8639 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008640 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8643 " has a clearValueCount of"
8644 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008645
8646 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8647
8648 m_errorMonitor->VerifyFound();
8649
8650 vkDestroyRenderPass(m_device->device(), rp, NULL);
8651}
8652
Cody Northrop3bb4d962016-05-09 16:15:57 -06008653TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008654 TEST_DESCRIPTION("End a command buffer with an active render pass");
8655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8657 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658
8659 ASSERT_NO_FATAL_FAILURE(InitState());
8660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8661
Tony Barbour552f6c02016-12-21 14:34:07 -07008662 m_commandBuffer->BeginCommandBuffer();
8663 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8664 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008665
8666 m_errorMonitor->VerifyFound();
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8669 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008687 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008689 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690}
8691
Karl Schultz6addd812016-02-02 17:17:23 -07008692TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8695 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
8697 ASSERT_NO_FATAL_FAILURE(InitState());
8698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
Tony Barbour552f6c02016-12-21 14:34:07 -07008700 m_commandBuffer->BeginCommandBuffer();
8701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
8703 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vk_testing::Buffer dstBuffer;
8705 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008706
Karl Schultz6addd812016-02-02 17:17:23 -07008707 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008708 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8709 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8710 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713}
8714
Karl Schultz6addd812016-02-02 17:17:23 -07008715TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8718 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008719
8720 ASSERT_NO_FATAL_FAILURE(InitState());
8721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008722
Tony Barbour552f6c02016-12-21 14:34:07 -07008723 m_commandBuffer->BeginCommandBuffer();
8724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Michael Lentine0a369f62016-02-03 16:51:46 -06008726 VkClearColorValue clear_color;
8727 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008728 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8730 const int32_t tex_width = 32;
8731 const int32_t tex_height = 32;
8732 VkImageCreateInfo image_create_info = {};
8733 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8734 image_create_info.pNext = NULL;
8735 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8736 image_create_info.format = tex_format;
8737 image_create_info.extent.width = tex_width;
8738 image_create_info.extent.height = tex_height;
8739 image_create_info.extent.depth = 1;
8740 image_create_info.mipLevels = 1;
8741 image_create_info.arrayLayers = 1;
8742 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8743 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008744 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008753 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008754}
8755
Karl Schultz6addd812016-02-02 17:17:23 -07008756TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8759 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
8761 ASSERT_NO_FATAL_FAILURE(InitState());
8762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Tony Barbourf887b162017-03-09 10:06:46 -07008764 auto depth_format = find_depth_stencil_format(m_device);
8765 if (!depth_format) {
8766 printf(" No Depth + Stencil format found. Skipped.\n");
8767 return;
8768 }
8769
Tony Barbour552f6c02016-12-21 14:34:07 -07008770 m_commandBuffer->BeginCommandBuffer();
8771 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
8773 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008774 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008775 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008777 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008778 image_create_info.extent.width = 64;
8779 image_create_info.extent.height = 64;
8780 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8781 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008783 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008788 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8789 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008791 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792}
8793
Karl Schultz6addd812016-02-02 17:17:23 -07008794TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008795 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008796 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "vkCmdClearAttachments(): This call "
8800 "must be issued inside an active "
8801 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803 ASSERT_NO_FATAL_FAILURE(InitState());
8804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
8806 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008807 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_VK_SUCCESS(err);
8809
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008810 VkClearAttachment color_attachment;
8811 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 color_attachment.clearValue.color.float32[0] = 0;
8813 color_attachment.clearValue.color.float32[1] = 0;
8814 color_attachment.clearValue.color.float32[2] = 0;
8815 color_attachment.clearValue.color.float32[3] = 0;
8816 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008817 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821}
8822
Chris Forbes3b97e932016-09-07 11:29:24 +12008823TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 TEST_DESCRIPTION(
8825 "Test that an error is produced when CmdNextSubpass is "
8826 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8829 "vkCmdNextSubpass(): Attempted to advance "
8830 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008831
8832 ASSERT_NO_FATAL_FAILURE(InitState());
8833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8834
Tony Barbour552f6c02016-12-21 14:34:07 -07008835 m_commandBuffer->BeginCommandBuffer();
8836 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008837
8838 // error here.
8839 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8840 m_errorMonitor->VerifyFound();
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->EndRenderPass();
8843 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008844}
8845
Chris Forbes6d624702016-09-07 13:57:05 +12008846TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008847 TEST_DESCRIPTION(
8848 "Test that an error is produced when CmdEndRenderPass is "
8849 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8852 "vkCmdEndRenderPass(): Called before reaching "
8853 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008854
8855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8857 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008860
8861 VkRenderPass rp;
8862 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8863 ASSERT_VK_SUCCESS(err);
8864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 VkFramebuffer fb;
8868 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8869 ASSERT_VK_SUCCESS(err);
8870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008874
8875 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8876
8877 // Error here.
8878 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8879 m_errorMonitor->VerifyFound();
8880
8881 // Clean up.
8882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8884}
8885
Karl Schultz9e66a292016-04-21 15:57:51 -06008886TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8887 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008892 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008893
8894 VkBufferMemoryBarrier buf_barrier = {};
8895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8896 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8897 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8898 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8899 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8900 buf_barrier.buffer = VK_NULL_HANDLE;
8901 buf_barrier.offset = 0;
8902 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8904 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 m_errorMonitor->VerifyFound();
8907}
8908
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008909TEST_F(VkLayerTest, InvalidBarriers) {
8910 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008913
8914 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008915 auto depth_format = find_depth_stencil_format(m_device);
8916 if (!depth_format) {
8917 printf(" No Depth + Stencil format found. Skipped.\n");
8918 return;
8919 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8921
8922 VkMemoryBarrier mem_barrier = {};
8923 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8924 mem_barrier.pNext = NULL;
8925 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8926 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008927 m_commandBuffer->BeginCommandBuffer();
8928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008929 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008931 &mem_barrier, 0, nullptr, 0, nullptr);
8932 m_errorMonitor->VerifyFound();
8933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008935 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008937 ASSERT_TRUE(image.initialized());
8938 VkImageMemoryBarrier img_barrier = {};
8939 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8940 img_barrier.pNext = NULL;
8941 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8942 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8943 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8944 // New layout can't be UNDEFINED
8945 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8946 img_barrier.image = image.handle();
8947 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8948 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8949 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8950 img_barrier.subresourceRange.baseArrayLayer = 0;
8951 img_barrier.subresourceRange.baseMipLevel = 0;
8952 img_barrier.subresourceRange.layerCount = 1;
8953 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8955 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008956 m_errorMonitor->VerifyFound();
8957 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8960 "Subresource must have the sum of the "
8961 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008962 // baseArrayLayer + layerCount must be <= image's arrayLayers
8963 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8965 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008966 m_errorMonitor->VerifyFound();
8967 img_barrier.subresourceRange.baseArrayLayer = 0;
8968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008970 // baseMipLevel + levelCount must be <= image's mipLevels
8971 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8973 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008974 m_errorMonitor->VerifyFound();
8975 img_barrier.subresourceRange.baseMipLevel = 0;
8976
Mike Weiblen7053aa32017-01-25 15:21:10 -07008977 // levelCount must be non-zero.
8978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8979 img_barrier.subresourceRange.levelCount = 0;
8980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8981 nullptr, 0, nullptr, 1, &img_barrier);
8982 m_errorMonitor->VerifyFound();
8983 img_barrier.subresourceRange.levelCount = 1;
8984
8985 // layerCount must be non-zero.
8986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8987 img_barrier.subresourceRange.layerCount = 0;
8988 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8989 nullptr, 0, nullptr, 1, &img_barrier);
8990 m_errorMonitor->VerifyFound();
8991 img_barrier.subresourceRange.layerCount = 1;
8992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008994 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008995 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8996 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997 VkBufferMemoryBarrier buf_barrier = {};
8998 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8999 buf_barrier.pNext = NULL;
9000 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9001 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9002 buf_barrier.buffer = buffer.handle();
9003 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9004 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9005 buf_barrier.offset = 0;
9006 buf_barrier.size = VK_WHOLE_SIZE;
9007 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9009 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009010 m_errorMonitor->VerifyFound();
9011 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009014 buf_barrier.offset = 257;
9015 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9017 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009018 m_errorMonitor->VerifyFound();
9019 buf_barrier.offset = 0;
9020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022 buf_barrier.size = 257;
9023 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9025 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009026 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009029 m_errorMonitor->SetDesiredFailureMsg(
9030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009031 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009032 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009033 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009034 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009035 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9036 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009037 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009038
9039 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009040 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9042 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009043 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009044
9045 // Having anything other than DEPTH or STENCIL is an error
9046 m_errorMonitor->SetDesiredFailureMsg(
9047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9048 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9049 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9051 nullptr, 0, nullptr, 1, &img_barrier);
9052 m_errorMonitor->VerifyFound();
9053
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009054 // Now test depth-only
9055 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9057 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 VkDepthStencilObj d_image(m_device);
9059 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9060 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009063 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009064
9065 // DEPTH bit must be set
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9067 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009069 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9070 0, nullptr, 0, nullptr, 1, &img_barrier);
9071 m_errorMonitor->VerifyFound();
9072
9073 // No bits other than DEPTH may be set
9074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9075 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9076 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009077 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9078 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009079 m_errorMonitor->VerifyFound();
9080 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009081
9082 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9084 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009085 VkDepthStencilObj s_image(m_device);
9086 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9087 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009089 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009091 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9096 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009097 m_errorMonitor->VerifyFound();
9098 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009099
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009100 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009101 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009103 ASSERT_TRUE(c_image.initialized());
9104 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9105 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9106 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009107
9108 // COLOR bit must be set
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9110 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9113 nullptr, 0, nullptr, 1, &img_barrier);
9114 m_errorMonitor->VerifyFound();
9115
9116 // No bits other than COLOR may be set
9117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9118 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9119 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009120 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9121 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009122 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009123
Mike Weiblene6e01172017-03-07 22:18:40 -07009124 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9125 {
9126 VkImageObj img_color(m_device);
9127 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9128 ASSERT_TRUE(img_color.initialized());
9129
9130 VkImageObj img_ds(m_device);
9131 img_ds.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9132 ASSERT_TRUE(img_ds.initialized());
9133
9134 VkImageObj img_xfer_src(m_device);
9135 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
9136 ASSERT_TRUE(img_xfer_src.initialized());
9137
9138 VkImageObj img_xfer_dst(m_device);
9139 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9140 ASSERT_TRUE(img_xfer_dst.initialized());
9141
9142 VkImageObj img_sampled(m_device);
9143 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
9144 ASSERT_TRUE(img_sampled.initialized());
9145
9146 VkImageObj img_input(m_device);
9147 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9148 ASSERT_TRUE(img_input.initialized());
9149
9150 const struct {
9151 VkImageObj &image_obj;
9152 VkImageLayout bad_layout;
9153 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9154 } bad_buffer_layouts[] = {
9155 // clang-format off
9156 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9157 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9158 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9159 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9160 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9161 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9162 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9163 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9164 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9165 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9166 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9167 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9168 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9169 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9170 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9171 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9172 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9173 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9174 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9175 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9176 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9177 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9178 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9179 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9180 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9181 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9182 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9183 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9184 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9185 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9186 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9187 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9188 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9189 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9190 // clang-format on
9191 };
9192 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9193
9194 for (uint32_t i = 0; i < layout_count; ++i) {
9195 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9196 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9197 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9198 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9199 : VK_IMAGE_ASPECT_COLOR_BIT;
9200
9201 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9202 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9204 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9205 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9206 m_errorMonitor->VerifyFound();
9207
9208 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9209 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9212 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9213 m_errorMonitor->VerifyFound();
9214 }
9215
9216 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9217 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9218 }
9219
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009220 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9221
9222 // Create command pool with incompatible queueflags
9223 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9224 uint32_t queue_family_index = UINT32_MAX;
9225 for (uint32_t i = 0; i < queue_props.size(); i++) {
9226 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9227 queue_family_index = i;
9228 break;
9229 }
9230 }
9231 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009232 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009233 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009234 }
9235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9236
9237 VkCommandPool command_pool;
9238 VkCommandPoolCreateInfo pool_create_info{};
9239 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9240 pool_create_info.queueFamilyIndex = queue_family_index;
9241 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9242 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9243
9244 // Allocate a command buffer
9245 VkCommandBuffer bad_command_buffer;
9246 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9247 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9248 command_buffer_allocate_info.commandPool = command_pool;
9249 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9250 command_buffer_allocate_info.commandBufferCount = 1;
9251 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9252
9253 VkCommandBufferBeginInfo cbbi = {};
9254 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9255 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9256 buf_barrier.offset = 0;
9257 buf_barrier.size = VK_WHOLE_SIZE;
9258 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9259 &buf_barrier, 0, nullptr);
9260 m_errorMonitor->VerifyFound();
9261
9262 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9263 vkEndCommandBuffer(bad_command_buffer);
9264 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009265 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009266 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009267 }
9268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9269 VkEvent event;
9270 VkEventCreateInfo event_create_info{};
9271 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9272 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9273 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9274 nullptr, 0, nullptr);
9275 m_errorMonitor->VerifyFound();
9276
9277 vkEndCommandBuffer(bad_command_buffer);
9278 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009279}
9280
Tony Barbour18ba25c2016-09-29 13:42:40 -06009281TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9282 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9283
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009285 ASSERT_NO_FATAL_FAILURE(InitState());
9286 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -07009287 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
9288 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009289 ASSERT_TRUE(image.initialized());
9290
9291 VkImageMemoryBarrier barrier = {};
9292 VkImageSubresourceRange range;
9293 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9294 barrier.srcAccessMask = 0;
9295 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9296 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9297 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9298 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9299 barrier.image = image.handle();
9300 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9301 range.baseMipLevel = 0;
9302 range.levelCount = 1;
9303 range.baseArrayLayer = 0;
9304 range.layerCount = 1;
9305 barrier.subresourceRange = range;
9306 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9307 cmdbuf.BeginCommandBuffer();
9308 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9309 &barrier);
9310 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9311 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9312 barrier.srcAccessMask = 0;
9313 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9314 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9315 &barrier);
9316
9317 m_errorMonitor->VerifyFound();
9318}
9319
Karl Schultz6addd812016-02-02 17:17:23 -07009320TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009321 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009322 ASSERT_NO_FATAL_FAILURE(InitState());
9323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009324
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009325 uint32_t const indices[] = {0};
9326 VkBufferCreateInfo buf_info = {};
9327 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9328 buf_info.size = 1024;
9329 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9330 buf_info.queueFamilyIndexCount = 1;
9331 buf_info.pQueueFamilyIndices = indices;
9332
9333 VkBuffer buffer;
9334 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9335 ASSERT_VK_SUCCESS(err);
9336
9337 VkMemoryRequirements requirements;
9338 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9339
9340 VkMemoryAllocateInfo alloc_info{};
9341 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9342 alloc_info.pNext = NULL;
9343 alloc_info.memoryTypeIndex = 0;
9344 alloc_info.allocationSize = requirements.size;
9345 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9346 ASSERT_TRUE(pass);
9347
9348 VkDeviceMemory memory;
9349 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9350 ASSERT_VK_SUCCESS(err);
9351
9352 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009353 ASSERT_VK_SUCCESS(err);
9354
Tony Barbour552f6c02016-12-21 14:34:07 -07009355 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009356 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009357
Karl Schultz6addd812016-02-02 17:17:23 -07009358 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9359 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009360 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9362 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009363 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009364
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009365 vkFreeMemory(m_device->device(), memory, NULL);
9366 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009367}
9368
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009369TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9370 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009371 ASSERT_NO_FATAL_FAILURE(InitState());
9372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9373 VkBufferCreateInfo buffCI = {};
9374 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9375 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009376 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009377 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009378 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009379 uint32_t qfi[2];
9380 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009381 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009382
9383 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009384 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009385
9386 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9389 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009390 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009391 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009392
9393 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009394 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9396
9397 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9398 buffCI.queueFamilyIndexCount = 2;
9399 qfi[0] = 1;
9400 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009401 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009402 VkDeviceMemory mem;
9403 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009404 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009405
9406 VkMemoryAllocateInfo alloc_info = {};
9407 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9408 alloc_info.allocationSize = 1024;
9409 bool pass = false;
9410 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9411 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009412 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009413 return;
9414 }
9415 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009416 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009417
9418 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009419 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009420 m_commandBuffer->end();
9421 QueueCommandBuffer(false);
9422 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009423 vkDestroyBuffer(m_device->device(), ib2, NULL);
9424 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009425 }
9426
Tony Barbourdf4c0042016-06-01 15:55:43 -06009427 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009428}
9429
Karl Schultz6addd812016-02-02 17:17:23 -07009430TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009431 TEST_DESCRIPTION(
9432 "Attempt vkCmdExecuteCommands with a primary command buffer"
9433 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009434
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009435 ASSERT_NO_FATAL_FAILURE(InitState());
9436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009437
Chris Forbesf29a84f2016-10-06 18:39:28 +13009438 // An empty primary command buffer
9439 VkCommandBufferObj cb(m_device, m_commandPool);
9440 cb.BeginCommandBuffer();
9441 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009442
Chris Forbesf29a84f2016-10-06 18:39:28 +13009443 m_commandBuffer->BeginCommandBuffer();
9444 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9445 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009446
Chris Forbesf29a84f2016-10-06 18:39:28 +13009447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9448 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009449 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009450
9451 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009452}
9453
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009454TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009455 TEST_DESCRIPTION(
9456 "Attempt to update descriptor sets for images and buffers "
9457 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009458 VkResult err;
9459
9460 ASSERT_NO_FATAL_FAILURE(InitState());
9461 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9462 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9463 ds_type_count[i].type = VkDescriptorType(i);
9464 ds_type_count[i].descriptorCount = 1;
9465 }
9466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9468 ds_pool_ci.pNext = NULL;
9469 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9470 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9471 ds_pool_ci.pPoolSizes = ds_type_count;
9472
9473 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 ASSERT_VK_SUCCESS(err);
9476
9477 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009479 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9480 dsl_binding[i].binding = 0;
9481 dsl_binding[i].descriptorType = VkDescriptorType(i);
9482 dsl_binding[i].descriptorCount = 1;
9483 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9484 dsl_binding[i].pImmutableSamplers = NULL;
9485 }
9486
9487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9489 ds_layout_ci.pNext = NULL;
9490 ds_layout_ci.bindingCount = 1;
9491 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9492 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9493 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 ASSERT_VK_SUCCESS(err);
9496 }
9497 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9498 VkDescriptorSetAllocateInfo alloc_info = {};
9499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9500 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9501 alloc_info.descriptorPool = ds_pool;
9502 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009504 ASSERT_VK_SUCCESS(err);
9505
9506 // Create a buffer & bufferView to be used for invalid updates
9507 VkBufferCreateInfo buff_ci = {};
9508 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009509 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 buff_ci.size = 256;
9511 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009512 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9514 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009515
9516 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9517 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9518 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9519 ASSERT_VK_SUCCESS(err);
9520
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009521 VkMemoryRequirements mem_reqs;
9522 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9523 VkMemoryAllocateInfo mem_alloc_info = {};
9524 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9525 mem_alloc_info.pNext = NULL;
9526 mem_alloc_info.memoryTypeIndex = 0;
9527 mem_alloc_info.allocationSize = mem_reqs.size;
9528 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9529 if (!pass) {
9530 vkDestroyBuffer(m_device->device(), buffer, NULL);
9531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9532 return;
9533 }
9534 VkDeviceMemory mem;
9535 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9536 ASSERT_VK_SUCCESS(err);
9537 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9538 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009539
9540 VkBufferViewCreateInfo buff_view_ci = {};
9541 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9542 buff_view_ci.buffer = buffer;
9543 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9544 buff_view_ci.range = VK_WHOLE_SIZE;
9545 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009547 ASSERT_VK_SUCCESS(err);
9548
Tony Barbour415497c2017-01-24 10:06:09 -07009549 // Now get resources / view for storage_texel_buffer
9550 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9551 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9552 if (!pass) {
9553 vkDestroyBuffer(m_device->device(), buffer, NULL);
9554 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9555 vkFreeMemory(m_device->device(), mem, NULL);
9556 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9558 return;
9559 }
9560 VkDeviceMemory storage_texel_buffer_mem;
9561 VkBufferView storage_texel_buffer_view;
9562 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9563 ASSERT_VK_SUCCESS(err);
9564 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9565 ASSERT_VK_SUCCESS(err);
9566 buff_view_ci.buffer = storage_texel_buffer;
9567 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9568 ASSERT_VK_SUCCESS(err);
9569
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009570 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009571 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009572 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009573 image_ci.format = VK_FORMAT_UNDEFINED;
9574 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9575 VkFormat format = static_cast<VkFormat>(f);
9576 VkFormatProperties fProps = m_device->format_properties(format);
9577 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9578 image_ci.format = format;
9579 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9580 break;
9581 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9582 image_ci.format = format;
9583 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9584 break;
9585 }
9586 }
9587 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9588 return;
9589 }
9590
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009591 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9592 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009593 image_ci.extent.width = 64;
9594 image_ci.extent.height = 64;
9595 image_ci.extent.depth = 1;
9596 image_ci.mipLevels = 1;
9597 image_ci.arrayLayers = 1;
9598 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009599 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009600 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009601 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9602 VkImage image;
9603 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9604 ASSERT_VK_SUCCESS(err);
9605 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009606 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009607
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009608 VkMemoryAllocateInfo mem_alloc = {};
9609 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9610 mem_alloc.pNext = NULL;
9611 mem_alloc.allocationSize = 0;
9612 mem_alloc.memoryTypeIndex = 0;
9613 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9614 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009616 ASSERT_TRUE(pass);
9617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9618 ASSERT_VK_SUCCESS(err);
9619 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9620 ASSERT_VK_SUCCESS(err);
9621 // Now create view for image
9622 VkImageViewCreateInfo image_view_ci = {};
9623 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9624 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009625 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009626 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9627 image_view_ci.subresourceRange.layerCount = 1;
9628 image_view_ci.subresourceRange.baseArrayLayer = 0;
9629 image_view_ci.subresourceRange.levelCount = 1;
9630 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9631 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009633 ASSERT_VK_SUCCESS(err);
9634
9635 VkDescriptorBufferInfo buff_info = {};
9636 buff_info.buffer = buffer;
9637 VkDescriptorImageInfo img_info = {};
9638 img_info.imageView = image_view;
9639 VkWriteDescriptorSet descriptor_write = {};
9640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9641 descriptor_write.dstBinding = 0;
9642 descriptor_write.descriptorCount = 1;
9643 descriptor_write.pTexelBufferView = &buff_view;
9644 descriptor_write.pBufferInfo = &buff_info;
9645 descriptor_write.pImageInfo = &img_info;
9646
9647 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009648 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009649 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9650 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9651 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9652 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9653 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9654 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9655 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9656 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9657 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9658 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9659 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009660 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009661 // Start loop at 1 as SAMPLER desc type has no usage bit error
9662 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009663 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9664 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9665 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9666 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009667 descriptor_write.descriptorType = VkDescriptorType(i);
9668 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009672
9673 m_errorMonitor->VerifyFound();
9674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009675 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9676 descriptor_write.pTexelBufferView = &buff_view;
9677 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009678 }
Tony Barbour415497c2017-01-24 10:06:09 -07009679
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009680 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9681 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009682 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009683 vkDestroyImageView(m_device->device(), image_view, NULL);
9684 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009685 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009686 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009687 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009688 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009689 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9691}
9692
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009693TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009694 TEST_DESCRIPTION(
9695 "Attempt to update buffer descriptor set that has incorrect "
9696 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009697 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009698 "2. range value of 0\n"
9699 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009700 VkResult err;
9701
9702 ASSERT_NO_FATAL_FAILURE(InitState());
9703 VkDescriptorPoolSize ds_type_count = {};
9704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9705 ds_type_count.descriptorCount = 1;
9706
9707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9709 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009710 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009711 ds_pool_ci.maxSets = 1;
9712 ds_pool_ci.poolSizeCount = 1;
9713 ds_pool_ci.pPoolSizes = &ds_type_count;
9714
9715 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009717 ASSERT_VK_SUCCESS(err);
9718
9719 // Create layout with single uniform buffer descriptor
9720 VkDescriptorSetLayoutBinding dsl_binding = {};
9721 dsl_binding.binding = 0;
9722 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9723 dsl_binding.descriptorCount = 1;
9724 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9725 dsl_binding.pImmutableSamplers = NULL;
9726
9727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9729 ds_layout_ci.pNext = NULL;
9730 ds_layout_ci.bindingCount = 1;
9731 ds_layout_ci.pBindings = &dsl_binding;
9732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkDescriptorSet descriptor_set = {};
9737 VkDescriptorSetAllocateInfo alloc_info = {};
9738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9739 alloc_info.descriptorSetCount = 1;
9740 alloc_info.descriptorPool = ds_pool;
9741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 // Create a buffer to be used for invalid updates
9746 VkBufferCreateInfo buff_ci = {};
9747 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9748 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009749 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009750 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9751 VkBuffer buffer;
9752 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9753 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009754
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009755 // Have to bind memory to buffer before descriptor update
9756 VkMemoryAllocateInfo mem_alloc = {};
9757 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9758 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009759 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009760 mem_alloc.memoryTypeIndex = 0;
9761
9762 VkMemoryRequirements mem_reqs;
9763 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009765 if (!pass) {
9766 vkDestroyBuffer(m_device->device(), buffer, NULL);
9767 return;
9768 }
9769
9770 VkDeviceMemory mem;
9771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9772 ASSERT_VK_SUCCESS(err);
9773 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9774 ASSERT_VK_SUCCESS(err);
9775
9776 VkDescriptorBufferInfo buff_info = {};
9777 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009778 // Cause error due to offset out of range
9779 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009780 buff_info.range = VK_WHOLE_SIZE;
9781 VkWriteDescriptorSet descriptor_write = {};
9782 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9783 descriptor_write.dstBinding = 0;
9784 descriptor_write.descriptorCount = 1;
9785 descriptor_write.pTexelBufferView = nullptr;
9786 descriptor_write.pBufferInfo = &buff_info;
9787 descriptor_write.pImageInfo = nullptr;
9788
9789 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9790 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009792
9793 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9794
9795 m_errorMonitor->VerifyFound();
9796 // Now cause error due to range of 0
9797 buff_info.offset = 0;
9798 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009800
9801 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9802
9803 m_errorMonitor->VerifyFound();
9804 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009805 buff_info.offset = 0;
9806 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009808
9809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9810
9811 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009812 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9814 vkDestroyBuffer(m_device->device(), buffer, NULL);
9815 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9817}
9818
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819TEST_F(VkLayerTest, DSBufferLimitErrors) {
9820 TEST_DESCRIPTION(
9821 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9822 "Test cases include:\n"
9823 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9824 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9825 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9826 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9827 VkResult err;
9828
9829 ASSERT_NO_FATAL_FAILURE(InitState());
9830 VkDescriptorPoolSize ds_type_count[2] = {};
9831 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9832 ds_type_count[0].descriptorCount = 1;
9833 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9834 ds_type_count[1].descriptorCount = 1;
9835
9836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9838 ds_pool_ci.pNext = NULL;
9839 ds_pool_ci.maxSets = 1;
9840 ds_pool_ci.poolSizeCount = 2;
9841 ds_pool_ci.pPoolSizes = ds_type_count;
9842
9843 VkDescriptorPool ds_pool;
9844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9845 ASSERT_VK_SUCCESS(err);
9846
9847 // Create layout with single uniform buffer & single storage buffer descriptor
9848 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9849 dsl_binding[0].binding = 0;
9850 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9851 dsl_binding[0].descriptorCount = 1;
9852 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9853 dsl_binding[0].pImmutableSamplers = NULL;
9854 dsl_binding[1].binding = 1;
9855 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9856 dsl_binding[1].descriptorCount = 1;
9857 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding[1].pImmutableSamplers = NULL;
9859
9860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9862 ds_layout_ci.pNext = NULL;
9863 ds_layout_ci.bindingCount = 2;
9864 ds_layout_ci.pBindings = dsl_binding;
9865 VkDescriptorSetLayout ds_layout;
9866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9867 ASSERT_VK_SUCCESS(err);
9868
9869 VkDescriptorSet descriptor_set = {};
9870 VkDescriptorSetAllocateInfo alloc_info = {};
9871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9872 alloc_info.descriptorSetCount = 1;
9873 alloc_info.descriptorPool = ds_pool;
9874 alloc_info.pSetLayouts = &ds_layout;
9875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9876 ASSERT_VK_SUCCESS(err);
9877
9878 // Create a buffer to be used for invalid updates
9879 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9880 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9881 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9882 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9883 VkBufferCreateInfo ub_ci = {};
9884 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9885 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9886 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9887 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9888 VkBuffer uniform_buffer;
9889 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9890 ASSERT_VK_SUCCESS(err);
9891 VkBufferCreateInfo sb_ci = {};
9892 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9893 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9894 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9895 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9896 VkBuffer storage_buffer;
9897 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9898 ASSERT_VK_SUCCESS(err);
9899 // Have to bind memory to buffer before descriptor update
9900 VkMemoryAllocateInfo mem_alloc = {};
9901 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9902 mem_alloc.pNext = NULL;
9903 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9904 mem_alloc.memoryTypeIndex = 0;
9905
Cort Stratton77a0d592017-02-17 13:14:13 -08009906 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9907 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9908 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9909 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9910 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009911 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009913 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009914 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009916 return;
9917 }
9918
9919 VkDeviceMemory mem;
9920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009921 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009922 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9924 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9925 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9927 return;
9928 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009929 ASSERT_VK_SUCCESS(err);
9930 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9931 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009932 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009933 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9934 ASSERT_VK_SUCCESS(err);
9935
9936 VkDescriptorBufferInfo buff_info = {};
9937 buff_info.buffer = uniform_buffer;
9938 buff_info.range = ub_ci.size; // This will exceed limit
9939 VkWriteDescriptorSet descriptor_write = {};
9940 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9941 descriptor_write.dstBinding = 0;
9942 descriptor_write.descriptorCount = 1;
9943 descriptor_write.pTexelBufferView = nullptr;
9944 descriptor_write.pBufferInfo = &buff_info;
9945 descriptor_write.pImageInfo = nullptr;
9946
9947 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9948 descriptor_write.dstSet = descriptor_set;
9949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9950 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9951 m_errorMonitor->VerifyFound();
9952
9953 // Reduce size of range to acceptable limit & cause offset error
9954 buff_info.range = max_ub_range;
9955 buff_info.offset = min_ub_align - 1;
9956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9958 m_errorMonitor->VerifyFound();
9959
9960 // Now break storage updates
9961 buff_info.buffer = storage_buffer;
9962 buff_info.range = sb_ci.size; // This will exceed limit
9963 buff_info.offset = 0; // Reset offset for this update
9964
9965 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9966 descriptor_write.dstBinding = 1;
9967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9969 m_errorMonitor->VerifyFound();
9970
9971 // Reduce size of range to acceptable limit & cause offset error
9972 buff_info.range = max_sb_range;
9973 buff_info.offset = min_sb_align - 1;
9974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9975 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9976 m_errorMonitor->VerifyFound();
9977
9978 vkFreeMemory(m_device->device(), mem, NULL);
9979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9980 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9981 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9983}
9984
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009985TEST_F(VkLayerTest, DSAspectBitsErrors) {
9986 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9987 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009988 TEST_DESCRIPTION(
9989 "Attempt to update descriptor sets for images "
9990 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009991 VkResult err;
9992
9993 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009994 auto depth_format = find_depth_stencil_format(m_device);
9995 if (!depth_format) {
9996 printf(" No Depth + Stencil format found. Skipped.\n");
9997 return;
9998 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009999 VkDescriptorPoolSize ds_type_count = {};
10000 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10001 ds_type_count.descriptorCount = 1;
10002
10003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10005 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010006 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010007 ds_pool_ci.maxSets = 5;
10008 ds_pool_ci.poolSizeCount = 1;
10009 ds_pool_ci.pPoolSizes = &ds_type_count;
10010
10011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010013 ASSERT_VK_SUCCESS(err);
10014
10015 VkDescriptorSetLayoutBinding dsl_binding = {};
10016 dsl_binding.binding = 0;
10017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10018 dsl_binding.descriptorCount = 1;
10019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10020 dsl_binding.pImmutableSamplers = NULL;
10021
10022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10024 ds_layout_ci.pNext = NULL;
10025 ds_layout_ci.bindingCount = 1;
10026 ds_layout_ci.pBindings = &dsl_binding;
10027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010029 ASSERT_VK_SUCCESS(err);
10030
10031 VkDescriptorSet descriptor_set = {};
10032 VkDescriptorSetAllocateInfo alloc_info = {};
10033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10034 alloc_info.descriptorSetCount = 1;
10035 alloc_info.descriptorPool = ds_pool;
10036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010038 ASSERT_VK_SUCCESS(err);
10039
10040 // Create an image to be used for invalid updates
10041 VkImageCreateInfo image_ci = {};
10042 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10043 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010044 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010045 image_ci.extent.width = 64;
10046 image_ci.extent.height = 64;
10047 image_ci.extent.depth = 1;
10048 image_ci.mipLevels = 1;
10049 image_ci.arrayLayers = 1;
10050 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010051 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010052 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10053 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10054 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10055 VkImage image;
10056 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10057 ASSERT_VK_SUCCESS(err);
10058 // Bind memory to image
10059 VkMemoryRequirements mem_reqs;
10060 VkDeviceMemory image_mem;
10061 bool pass;
10062 VkMemoryAllocateInfo mem_alloc = {};
10063 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10064 mem_alloc.pNext = NULL;
10065 mem_alloc.allocationSize = 0;
10066 mem_alloc.memoryTypeIndex = 0;
10067 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10068 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010070 ASSERT_TRUE(pass);
10071 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10072 ASSERT_VK_SUCCESS(err);
10073 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10074 ASSERT_VK_SUCCESS(err);
10075 // Now create view for image
10076 VkImageViewCreateInfo image_view_ci = {};
10077 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10078 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010079 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010080 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10081 image_view_ci.subresourceRange.layerCount = 1;
10082 image_view_ci.subresourceRange.baseArrayLayer = 0;
10083 image_view_ci.subresourceRange.levelCount = 1;
10084 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010086
10087 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010089 ASSERT_VK_SUCCESS(err);
10090
10091 VkDescriptorImageInfo img_info = {};
10092 img_info.imageView = image_view;
10093 VkWriteDescriptorSet descriptor_write = {};
10094 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10095 descriptor_write.dstBinding = 0;
10096 descriptor_write.descriptorCount = 1;
10097 descriptor_write.pTexelBufferView = NULL;
10098 descriptor_write.pBufferInfo = NULL;
10099 descriptor_write.pImageInfo = &img_info;
10100 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10101 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010102 const char *error_msg =
10103 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10104 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010106
10107 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10108
10109 m_errorMonitor->VerifyFound();
10110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10111 vkDestroyImage(m_device->device(), image, NULL);
10112 vkFreeMemory(m_device->device(), image_mem, NULL);
10113 vkDestroyImageView(m_device->device(), image_view, NULL);
10114 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10116}
10117
Karl Schultz6addd812016-02-02 17:17:23 -070010118TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010119 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010120 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10123 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10124 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010125
Tobin Ehlis3b780662015-05-28 12:11:26 -060010126 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010127 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10130 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010131
10132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10134 ds_pool_ci.pNext = NULL;
10135 ds_pool_ci.maxSets = 1;
10136 ds_pool_ci.poolSizeCount = 1;
10137 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010138
Tobin Ehlis3b780662015-05-28 12:11:26 -060010139 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010141 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010142 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010143 dsl_binding.binding = 0;
10144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10145 dsl_binding.descriptorCount = 1;
10146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10147 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148
Tony Barboureb254902015-07-15 12:50:33 -060010149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10151 ds_layout_ci.pNext = NULL;
10152 ds_layout_ci.bindingCount = 1;
10153 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010154
Tobin Ehlis3b780662015-05-28 12:11:26 -060010155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010157 ASSERT_VK_SUCCESS(err);
10158
10159 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010160 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010162 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010163 alloc_info.descriptorPool = ds_pool;
10164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010168 VkSamplerCreateInfo sampler_ci = {};
10169 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10170 sampler_ci.pNext = NULL;
10171 sampler_ci.magFilter = VK_FILTER_NEAREST;
10172 sampler_ci.minFilter = VK_FILTER_NEAREST;
10173 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10174 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10175 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10176 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10177 sampler_ci.mipLodBias = 1.0;
10178 sampler_ci.anisotropyEnable = VK_FALSE;
10179 sampler_ci.maxAnisotropy = 1;
10180 sampler_ci.compareEnable = VK_FALSE;
10181 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10182 sampler_ci.minLod = 1.0;
10183 sampler_ci.maxLod = 1.0;
10184 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10185 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10186 VkSampler sampler;
10187 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10188 ASSERT_VK_SUCCESS(err);
10189
10190 VkDescriptorImageInfo info = {};
10191 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010192
10193 VkWriteDescriptorSet descriptor_write;
10194 memset(&descriptor_write, 0, sizeof(descriptor_write));
10195 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010196 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010197 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010198 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010199 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010200 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010201
10202 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010204 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010205
Chia-I Wuf7458c52015-10-26 21:10:41 +080010206 vkDestroySampler(m_device->device(), sampler, NULL);
10207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010209}
10210
Karl Schultz6addd812016-02-02 17:17:23 -070010211TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010212 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010213 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010214
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010216
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010218 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010219 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010220 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10221 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010222
10223 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010224 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10225 ds_pool_ci.pNext = NULL;
10226 ds_pool_ci.maxSets = 1;
10227 ds_pool_ci.poolSizeCount = 1;
10228 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010229
Tobin Ehlis3b780662015-05-28 12:11:26 -060010230 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010232 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010233
Tony Barboureb254902015-07-15 12:50:33 -060010234 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010235 dsl_binding.binding = 0;
10236 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10237 dsl_binding.descriptorCount = 1;
10238 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10239 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010240
10241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10243 ds_layout_ci.pNext = NULL;
10244 ds_layout_ci.bindingCount = 1;
10245 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010246
Tobin Ehlis3b780662015-05-28 12:11:26 -060010247 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010249 ASSERT_VK_SUCCESS(err);
10250
10251 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010252 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010253 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010254 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010255 alloc_info.descriptorPool = ds_pool;
10256 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010258 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010259
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010260 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10261
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010262 // Correctly update descriptor to avoid "NOT_UPDATED" error
10263 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010264 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010265 buff_info.offset = 0;
10266 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010267
10268 VkWriteDescriptorSet descriptor_write;
10269 memset(&descriptor_write, 0, sizeof(descriptor_write));
10270 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010271 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010273 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010274 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10275 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010276
10277 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010280
Chia-I Wuf7458c52015-10-26 21:10:41 +080010281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010283}
10284
Karl Schultz6addd812016-02-02 17:17:23 -070010285TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010286 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010287 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010288
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010290
Tobin Ehlis3b780662015-05-28 12:11:26 -060010291 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010292 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010293 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10295 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010296
10297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10299 ds_pool_ci.pNext = NULL;
10300 ds_pool_ci.maxSets = 1;
10301 ds_pool_ci.poolSizeCount = 1;
10302 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010303
Tobin Ehlis3b780662015-05-28 12:11:26 -060010304 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010305 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010306 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010307
Tony Barboureb254902015-07-15 12:50:33 -060010308 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010309 dsl_binding.binding = 0;
10310 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10311 dsl_binding.descriptorCount = 1;
10312 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10313 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010314
10315 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010316 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10317 ds_layout_ci.pNext = NULL;
10318 ds_layout_ci.bindingCount = 1;
10319 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010320 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010322 ASSERT_VK_SUCCESS(err);
10323
10324 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010325 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010327 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010328 alloc_info.descriptorPool = ds_pool;
10329 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010332
Tony Barboureb254902015-07-15 12:50:33 -060010333 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010334 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10335 sampler_ci.pNext = NULL;
10336 sampler_ci.magFilter = VK_FILTER_NEAREST;
10337 sampler_ci.minFilter = VK_FILTER_NEAREST;
10338 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10339 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10340 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10341 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10342 sampler_ci.mipLodBias = 1.0;
10343 sampler_ci.anisotropyEnable = VK_FALSE;
10344 sampler_ci.maxAnisotropy = 1;
10345 sampler_ci.compareEnable = VK_FALSE;
10346 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10347 sampler_ci.minLod = 1.0;
10348 sampler_ci.maxLod = 1.0;
10349 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10350 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010351
Tobin Ehlis3b780662015-05-28 12:11:26 -060010352 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010353 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010355
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010356 VkDescriptorImageInfo info = {};
10357 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010358
10359 VkWriteDescriptorSet descriptor_write;
10360 memset(&descriptor_write, 0, sizeof(descriptor_write));
10361 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010362 descriptor_write.dstSet = descriptorSet;
10363 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010364 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010365 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010366 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010367 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010368
10369 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10370
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010371 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010372
Chia-I Wuf7458c52015-10-26 21:10:41 +080010373 vkDestroySampler(m_device->device(), sampler, NULL);
10374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010376}
10377
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010378TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10379 // Create layout w/ empty binding and attempt to update it
10380 VkResult err;
10381
10382 ASSERT_NO_FATAL_FAILURE(InitState());
10383
10384 VkDescriptorPoolSize ds_type_count = {};
10385 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10386 ds_type_count.descriptorCount = 1;
10387
10388 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10389 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10390 ds_pool_ci.pNext = NULL;
10391 ds_pool_ci.maxSets = 1;
10392 ds_pool_ci.poolSizeCount = 1;
10393 ds_pool_ci.pPoolSizes = &ds_type_count;
10394
10395 VkDescriptorPool ds_pool;
10396 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10397 ASSERT_VK_SUCCESS(err);
10398
10399 VkDescriptorSetLayoutBinding dsl_binding = {};
10400 dsl_binding.binding = 0;
10401 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10402 dsl_binding.descriptorCount = 0;
10403 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10404 dsl_binding.pImmutableSamplers = NULL;
10405
10406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10408 ds_layout_ci.pNext = NULL;
10409 ds_layout_ci.bindingCount = 1;
10410 ds_layout_ci.pBindings = &dsl_binding;
10411 VkDescriptorSetLayout ds_layout;
10412 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10413 ASSERT_VK_SUCCESS(err);
10414
10415 VkDescriptorSet descriptor_set;
10416 VkDescriptorSetAllocateInfo alloc_info = {};
10417 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10418 alloc_info.descriptorSetCount = 1;
10419 alloc_info.descriptorPool = ds_pool;
10420 alloc_info.pSetLayouts = &ds_layout;
10421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10422 ASSERT_VK_SUCCESS(err);
10423
10424 VkSamplerCreateInfo sampler_ci = {};
10425 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10426 sampler_ci.magFilter = VK_FILTER_NEAREST;
10427 sampler_ci.minFilter = VK_FILTER_NEAREST;
10428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10432 sampler_ci.mipLodBias = 1.0;
10433 sampler_ci.maxAnisotropy = 1;
10434 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10435 sampler_ci.minLod = 1.0;
10436 sampler_ci.maxLod = 1.0;
10437 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10438
10439 VkSampler sampler;
10440 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10441 ASSERT_VK_SUCCESS(err);
10442
10443 VkDescriptorImageInfo info = {};
10444 info.sampler = sampler;
10445
10446 VkWriteDescriptorSet descriptor_write;
10447 memset(&descriptor_write, 0, sizeof(descriptor_write));
10448 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10449 descriptor_write.dstSet = descriptor_set;
10450 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010451 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010452 // This is the wrong type, but empty binding error will be flagged first
10453 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10454 descriptor_write.pImageInfo = &info;
10455
10456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10458 m_errorMonitor->VerifyFound();
10459
10460 vkDestroySampler(m_device->device(), sampler, NULL);
10461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10463}
10464
Karl Schultz6addd812016-02-02 17:17:23 -070010465TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10466 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10467 // types
10468 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010471
Tobin Ehlis3b780662015-05-28 12:11:26 -060010472 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010473
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010474 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010475 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10476 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010477
10478 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010479 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10480 ds_pool_ci.pNext = NULL;
10481 ds_pool_ci.maxSets = 1;
10482 ds_pool_ci.poolSizeCount = 1;
10483 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010484
Tobin Ehlis3b780662015-05-28 12:11:26 -060010485 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010487 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010489 dsl_binding.binding = 0;
10490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10491 dsl_binding.descriptorCount = 1;
10492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010494
Tony Barboureb254902015-07-15 12:50:33 -060010495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10497 ds_layout_ci.pNext = NULL;
10498 ds_layout_ci.bindingCount = 1;
10499 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010500
Tobin Ehlis3b780662015-05-28 12:11:26 -060010501 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010503 ASSERT_VK_SUCCESS(err);
10504
10505 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010508 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010509 alloc_info.descriptorPool = ds_pool;
10510 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010512 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010513
Tony Barboureb254902015-07-15 12:50:33 -060010514 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10516 sampler_ci.pNext = NULL;
10517 sampler_ci.magFilter = VK_FILTER_NEAREST;
10518 sampler_ci.minFilter = VK_FILTER_NEAREST;
10519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10523 sampler_ci.mipLodBias = 1.0;
10524 sampler_ci.anisotropyEnable = VK_FALSE;
10525 sampler_ci.maxAnisotropy = 1;
10526 sampler_ci.compareEnable = VK_FALSE;
10527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10528 sampler_ci.minLod = 1.0;
10529 sampler_ci.maxLod = 1.0;
10530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010532 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010533 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010534 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010535
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010536 VkDescriptorImageInfo info = {};
10537 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010538
10539 VkWriteDescriptorSet descriptor_write;
10540 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010542 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010543 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010544 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010546 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010547
10548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010550 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010551
Chia-I Wuf7458c52015-10-26 21:10:41 +080010552 vkDestroySampler(m_device->device(), sampler, NULL);
10553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010555}
10556
Karl Schultz6addd812016-02-02 17:17:23 -070010557TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010559 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010560
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010562
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010563 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010564 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10565 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010566 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010567 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10568 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010569
10570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10572 ds_pool_ci.pNext = NULL;
10573 ds_pool_ci.maxSets = 1;
10574 ds_pool_ci.poolSizeCount = 1;
10575 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010576
10577 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579 ASSERT_VK_SUCCESS(err);
10580
10581 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010582 dsl_binding.binding = 0;
10583 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10584 dsl_binding.descriptorCount = 1;
10585 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10586 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010587
10588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10590 ds_layout_ci.pNext = NULL;
10591 ds_layout_ci.bindingCount = 1;
10592 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010595 ASSERT_VK_SUCCESS(err);
10596
10597 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010598 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010600 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010601 alloc_info.descriptorPool = ds_pool;
10602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604 ASSERT_VK_SUCCESS(err);
10605
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010606 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010607
10608 VkDescriptorImageInfo descriptor_info;
10609 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10610 descriptor_info.sampler = sampler;
10611
10612 VkWriteDescriptorSet descriptor_write;
10613 memset(&descriptor_write, 0, sizeof(descriptor_write));
10614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010615 descriptor_write.dstSet = descriptorSet;
10616 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010617 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10619 descriptor_write.pImageInfo = &descriptor_info;
10620
10621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010623 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010624
Chia-I Wuf7458c52015-10-26 21:10:41 +080010625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010627}
10628
Karl Schultz6addd812016-02-02 17:17:23 -070010629TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10630 // Create a single combined Image/Sampler descriptor and send it an invalid
10631 // imageView
10632 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010633
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010635
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010636 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010637 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010638 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10639 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010640
10641 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010642 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10643 ds_pool_ci.pNext = NULL;
10644 ds_pool_ci.maxSets = 1;
10645 ds_pool_ci.poolSizeCount = 1;
10646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010647
10648 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010650 ASSERT_VK_SUCCESS(err);
10651
10652 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010653 dsl_binding.binding = 0;
10654 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10655 dsl_binding.descriptorCount = 1;
10656 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10657 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010658
10659 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010660 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10661 ds_layout_ci.pNext = NULL;
10662 ds_layout_ci.bindingCount = 1;
10663 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010664 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010666 ASSERT_VK_SUCCESS(err);
10667
10668 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010669 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010670 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010671 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010672 alloc_info.descriptorPool = ds_pool;
10673 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010675 ASSERT_VK_SUCCESS(err);
10676
10677 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010678 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10679 sampler_ci.pNext = NULL;
10680 sampler_ci.magFilter = VK_FILTER_NEAREST;
10681 sampler_ci.minFilter = VK_FILTER_NEAREST;
10682 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10683 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10684 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10685 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10686 sampler_ci.mipLodBias = 1.0;
10687 sampler_ci.anisotropyEnable = VK_FALSE;
10688 sampler_ci.maxAnisotropy = 1;
10689 sampler_ci.compareEnable = VK_FALSE;
10690 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10691 sampler_ci.minLod = 1.0;
10692 sampler_ci.maxLod = 1.0;
10693 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10694 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010695
10696 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010697 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010698 ASSERT_VK_SUCCESS(err);
10699
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010701
10702 VkDescriptorImageInfo descriptor_info;
10703 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10704 descriptor_info.sampler = sampler;
10705 descriptor_info.imageView = view;
10706
10707 VkWriteDescriptorSet descriptor_write;
10708 memset(&descriptor_write, 0, sizeof(descriptor_write));
10709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010710 descriptor_write.dstSet = descriptorSet;
10711 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010712 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10714 descriptor_write.pImageInfo = &descriptor_info;
10715
10716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010718 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010719
Chia-I Wuf7458c52015-10-26 21:10:41 +080010720 vkDestroySampler(m_device->device(), sampler, NULL);
10721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010723}
10724
Karl Schultz6addd812016-02-02 17:17:23 -070010725TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10726 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10727 // into the other
10728 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010729
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10731 " binding #1 with type "
10732 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10733 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010734
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010736 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010737 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010738 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10739 ds_type_count[0].descriptorCount = 1;
10740 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10741 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010742
10743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10745 ds_pool_ci.pNext = NULL;
10746 ds_pool_ci.maxSets = 1;
10747 ds_pool_ci.poolSizeCount = 2;
10748 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010749
10750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010752 ASSERT_VK_SUCCESS(err);
10753 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010754 dsl_binding[0].binding = 0;
10755 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10756 dsl_binding[0].descriptorCount = 1;
10757 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10758 dsl_binding[0].pImmutableSamplers = NULL;
10759 dsl_binding[1].binding = 1;
10760 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10761 dsl_binding[1].descriptorCount = 1;
10762 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10763 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010764
10765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10767 ds_layout_ci.pNext = NULL;
10768 ds_layout_ci.bindingCount = 2;
10769 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010770
10771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010773 ASSERT_VK_SUCCESS(err);
10774
10775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010778 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010779 alloc_info.descriptorPool = ds_pool;
10780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010782 ASSERT_VK_SUCCESS(err);
10783
10784 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010785 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10786 sampler_ci.pNext = NULL;
10787 sampler_ci.magFilter = VK_FILTER_NEAREST;
10788 sampler_ci.minFilter = VK_FILTER_NEAREST;
10789 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10790 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10791 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10792 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10793 sampler_ci.mipLodBias = 1.0;
10794 sampler_ci.anisotropyEnable = VK_FALSE;
10795 sampler_ci.maxAnisotropy = 1;
10796 sampler_ci.compareEnable = VK_FALSE;
10797 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10798 sampler_ci.minLod = 1.0;
10799 sampler_ci.maxLod = 1.0;
10800 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10801 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010802
10803 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010804 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010805 ASSERT_VK_SUCCESS(err);
10806
10807 VkDescriptorImageInfo info = {};
10808 info.sampler = sampler;
10809
10810 VkWriteDescriptorSet descriptor_write;
10811 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010814 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010815 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10817 descriptor_write.pImageInfo = &info;
10818 // This write update should succeed
10819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10820 // Now perform a copy update that fails due to type mismatch
10821 VkCopyDescriptorSet copy_ds_update;
10822 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10823 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10824 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010825 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010826 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010827 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10828 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010829 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010831 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010832 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060010834 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10835 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10836 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010837 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010838 copy_ds_update.dstSet = descriptorSet;
10839 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010840 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010841 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10842
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010843 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010844
Tobin Ehlis04356f92015-10-27 16:35:27 -060010845 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10847 " binding#1 with offset index of 1 plus "
10848 "update array offset of 0 and update of "
10849 "5 descriptors oversteps total number "
10850 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010851
Tobin Ehlis04356f92015-10-27 16:35:27 -060010852 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10853 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10854 copy_ds_update.srcSet = descriptorSet;
10855 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010856 copy_ds_update.dstSet = descriptorSet;
10857 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010858 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010859 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010861 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010862
Chia-I Wuf7458c52015-10-26 21:10:41 +080010863 vkDestroySampler(m_device->device(), sampler, NULL);
10864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10865 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010866}
10867
Karl Schultz6addd812016-02-02 17:17:23 -070010868TEST_F(VkLayerTest, NumSamplesMismatch) {
10869 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10870 // sampleCount
10871 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010874
Tobin Ehlis3b780662015-05-28 12:11:26 -060010875 ASSERT_NO_FATAL_FAILURE(InitState());
10876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010877 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010878 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010879 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010880
10881 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010882 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10883 ds_pool_ci.pNext = NULL;
10884 ds_pool_ci.maxSets = 1;
10885 ds_pool_ci.poolSizeCount = 1;
10886 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010887
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010890 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010891
Tony Barboureb254902015-07-15 12:50:33 -060010892 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010893 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010894 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010895 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010896 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10897 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010898
Tony Barboureb254902015-07-15 12:50:33 -060010899 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10900 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10901 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010902 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010903 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010904
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010907 ASSERT_VK_SUCCESS(err);
10908
10909 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010910 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010911 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010912 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010913 alloc_info.descriptorPool = ds_pool;
10914 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010916 ASSERT_VK_SUCCESS(err);
10917
Tony Barboureb254902015-07-15 12:50:33 -060010918 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010920 pipe_ms_state_ci.pNext = NULL;
10921 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10922 pipe_ms_state_ci.sampleShadingEnable = 0;
10923 pipe_ms_state_ci.minSampleShading = 1.0;
10924 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010925
Tony Barboureb254902015-07-15 12:50:33 -060010926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10928 pipeline_layout_ci.pNext = NULL;
10929 pipeline_layout_ci.setLayoutCount = 1;
10930 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010931
10932 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010934 ASSERT_VK_SUCCESS(err);
10935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010937 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010939 VkPipelineObj pipe(m_device);
10940 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010941 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010942 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010943 pipe.SetMSAA(&pipe_ms_state_ci);
10944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010945
Tony Barbour552f6c02016-12-21 14:34:07 -070010946 m_commandBuffer->BeginCommandBuffer();
10947 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010948 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010949
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10952 VkRect2D scissor = {{0, 0}, {16, 16}};
10953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10954
Mark Young29927482016-05-04 14:38:51 -060010955 // Render triangle (the error should trigger on the attempt to draw).
10956 Draw(3, 1, 0, 0);
10957
10958 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010959 m_commandBuffer->EndRenderPass();
10960 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010961
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010962 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010963
Chia-I Wuf7458c52015-10-26 21:10:41 +080010964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010967}
Mark Young29927482016-05-04 14:38:51 -060010968
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010969TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010970 TEST_DESCRIPTION(
10971 "Hit RenderPass incompatible cases. "
10972 "Initial case is drawing with an active renderpass that's "
10973 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010974 VkResult err;
10975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
10979 VkDescriptorSetLayoutBinding dsl_binding = {};
10980 dsl_binding.binding = 0;
10981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10982 dsl_binding.descriptorCount = 1;
10983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10984 dsl_binding.pImmutableSamplers = NULL;
10985
10986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10988 ds_layout_ci.pNext = NULL;
10989 ds_layout_ci.bindingCount = 1;
10990 ds_layout_ci.pBindings = &dsl_binding;
10991
10992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010994 ASSERT_VK_SUCCESS(err);
10995
10996 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10997 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10998 pipeline_layout_ci.pNext = NULL;
10999 pipeline_layout_ci.setLayoutCount = 1;
11000 pipeline_layout_ci.pSetLayouts = &ds_layout;
11001
11002 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011004 ASSERT_VK_SUCCESS(err);
11005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011007 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011009 // Create a renderpass that will be incompatible with default renderpass
11010 VkAttachmentReference attach = {};
11011 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11012 VkAttachmentReference color_att = {};
11013 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11014 VkSubpassDescription subpass = {};
11015 subpass.inputAttachmentCount = 1;
11016 subpass.pInputAttachments = &attach;
11017 subpass.colorAttachmentCount = 1;
11018 subpass.pColorAttachments = &color_att;
11019 VkRenderPassCreateInfo rpci = {};
11020 rpci.subpassCount = 1;
11021 rpci.pSubpasses = &subpass;
11022 rpci.attachmentCount = 1;
11023 VkAttachmentDescription attach_desc = {};
11024 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011025 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11026 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011027 rpci.pAttachments = &attach_desc;
11028 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11029 VkRenderPass rp;
11030 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11031 VkPipelineObj pipe(m_device);
11032 pipe.AddShader(&vs);
11033 pipe.AddShader(&fs);
11034 pipe.AddColorAttachment();
11035 VkViewport view_port = {};
11036 m_viewports.push_back(view_port);
11037 pipe.SetViewport(m_viewports);
11038 VkRect2D rect = {};
11039 m_scissors.push_back(rect);
11040 pipe.SetScissor(m_scissors);
11041 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11042
11043 VkCommandBufferInheritanceInfo cbii = {};
11044 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11045 cbii.renderPass = rp;
11046 cbii.subpass = 0;
11047 VkCommandBufferBeginInfo cbbi = {};
11048 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11049 cbbi.pInheritanceInfo = &cbii;
11050 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11051 VkRenderPassBeginInfo rpbi = {};
11052 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11053 rpbi.framebuffer = m_framebuffer;
11054 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11056 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011059 // Render triangle (the error should trigger on the attempt to draw).
11060 Draw(3, 1, 0, 0);
11061
11062 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011063 m_commandBuffer->EndRenderPass();
11064 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011065
11066 m_errorMonitor->VerifyFound();
11067
11068 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11070 vkDestroyRenderPass(m_device->device(), rp, NULL);
11071}
11072
Mark Youngc89c6312016-03-31 16:03:20 -060011073TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11074 // Create Pipeline where the number of blend attachments doesn't match the
11075 // number of color attachments. In this case, we don't add any color
11076 // blend attachments even though we have a color attachment.
11077 VkResult err;
11078
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011080
11081 ASSERT_NO_FATAL_FAILURE(InitState());
11082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11083 VkDescriptorPoolSize ds_type_count = {};
11084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11085 ds_type_count.descriptorCount = 1;
11086
11087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11089 ds_pool_ci.pNext = NULL;
11090 ds_pool_ci.maxSets = 1;
11091 ds_pool_ci.poolSizeCount = 1;
11092 ds_pool_ci.pPoolSizes = &ds_type_count;
11093
11094 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011096 ASSERT_VK_SUCCESS(err);
11097
11098 VkDescriptorSetLayoutBinding dsl_binding = {};
11099 dsl_binding.binding = 0;
11100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11101 dsl_binding.descriptorCount = 1;
11102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11103 dsl_binding.pImmutableSamplers = NULL;
11104
11105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11107 ds_layout_ci.pNext = NULL;
11108 ds_layout_ci.bindingCount = 1;
11109 ds_layout_ci.pBindings = &dsl_binding;
11110
11111 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011113 ASSERT_VK_SUCCESS(err);
11114
11115 VkDescriptorSet descriptorSet;
11116 VkDescriptorSetAllocateInfo alloc_info = {};
11117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11118 alloc_info.descriptorSetCount = 1;
11119 alloc_info.descriptorPool = ds_pool;
11120 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011122 ASSERT_VK_SUCCESS(err);
11123
11124 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011126 pipe_ms_state_ci.pNext = NULL;
11127 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11128 pipe_ms_state_ci.sampleShadingEnable = 0;
11129 pipe_ms_state_ci.minSampleShading = 1.0;
11130 pipe_ms_state_ci.pSampleMask = NULL;
11131
11132 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11133 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11134 pipeline_layout_ci.pNext = NULL;
11135 pipeline_layout_ci.setLayoutCount = 1;
11136 pipeline_layout_ci.pSetLayouts = &ds_layout;
11137
11138 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011140 ASSERT_VK_SUCCESS(err);
11141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011142 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011143 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011145 VkPipelineObj pipe(m_device);
11146 pipe.AddShader(&vs);
11147 pipe.AddShader(&fs);
11148 pipe.SetMSAA(&pipe_ms_state_ci);
11149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011150 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011151
11152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11155}
Mark Young29927482016-05-04 14:38:51 -060011156
Mark Muellerd4914412016-06-13 17:52:06 -060011157TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011158 TEST_DESCRIPTION(
11159 "Points to a wrong colorAttachment index in a VkClearAttachment "
11160 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011161 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011163
11164 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11165 m_errorMonitor->VerifyFound();
11166}
11167
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011168TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011169 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11170 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011171
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011172 ASSERT_NO_FATAL_FAILURE(InitState());
11173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011174
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11177 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011178
11179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11181 ds_pool_ci.pNext = NULL;
11182 ds_pool_ci.maxSets = 1;
11183 ds_pool_ci.poolSizeCount = 1;
11184 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011185
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011186 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011188 ASSERT_VK_SUCCESS(err);
11189
Tony Barboureb254902015-07-15 12:50:33 -060011190 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011191 dsl_binding.binding = 0;
11192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11193 dsl_binding.descriptorCount = 1;
11194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11195 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011196
Tony Barboureb254902015-07-15 12:50:33 -060011197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11199 ds_layout_ci.pNext = NULL;
11200 ds_layout_ci.bindingCount = 1;
11201 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011202
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011203 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011205 ASSERT_VK_SUCCESS(err);
11206
11207 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011208 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011210 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011211 alloc_info.descriptorPool = ds_pool;
11212 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011214 ASSERT_VK_SUCCESS(err);
11215
Tony Barboureb254902015-07-15 12:50:33 -060011216 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011218 pipe_ms_state_ci.pNext = NULL;
11219 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11220 pipe_ms_state_ci.sampleShadingEnable = 0;
11221 pipe_ms_state_ci.minSampleShading = 1.0;
11222 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011223
Tony Barboureb254902015-07-15 12:50:33 -060011224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11226 pipeline_layout_ci.pNext = NULL;
11227 pipeline_layout_ci.setLayoutCount = 1;
11228 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011229
11230 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011232 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011235 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011236 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011238
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011239 VkPipelineObj pipe(m_device);
11240 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011241 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011242 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011243 pipe.SetMSAA(&pipe_ms_state_ci);
11244 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011245
Tony Barbour552f6c02016-12-21 14:34:07 -070011246 m_commandBuffer->BeginCommandBuffer();
11247 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011248
Karl Schultz6addd812016-02-02 17:17:23 -070011249 // Main thing we care about for this test is that the VkImage obj we're
11250 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011251 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011252 VkClearAttachment color_attachment;
11253 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11254 color_attachment.clearValue.color.float32[0] = 1.0;
11255 color_attachment.clearValue.color.float32[1] = 1.0;
11256 color_attachment.clearValue.color.float32[2] = 1.0;
11257 color_attachment.clearValue.color.float32[3] = 1.0;
11258 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011260
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011261 // Call for full-sized FB Color attachment prior to issuing a Draw
11262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011263 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011265 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011266
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011267 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11268 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11270 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11271 m_errorMonitor->VerifyFound();
11272
11273 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11274 clear_rect.layerCount = 2;
11275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11276 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011278
Chia-I Wuf7458c52015-10-26 21:10:41 +080011279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011282}
11283
Karl Schultz6addd812016-02-02 17:17:23 -070011284TEST_F(VkLayerTest, VtxBufferBadIndex) {
11285 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11288 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011289
Tobin Ehlis502480b2015-06-24 15:53:07 -060011290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011291 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011293
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011295 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11296 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011297
11298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11300 ds_pool_ci.pNext = NULL;
11301 ds_pool_ci.maxSets = 1;
11302 ds_pool_ci.poolSizeCount = 1;
11303 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011304
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011305 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011307 ASSERT_VK_SUCCESS(err);
11308
Tony Barboureb254902015-07-15 12:50:33 -060011309 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 dsl_binding.binding = 0;
11311 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11312 dsl_binding.descriptorCount = 1;
11313 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11314 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011315
Tony Barboureb254902015-07-15 12:50:33 -060011316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11318 ds_layout_ci.pNext = NULL;
11319 ds_layout_ci.bindingCount = 1;
11320 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011321
Tobin Ehlis502480b2015-06-24 15:53:07 -060011322 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011324 ASSERT_VK_SUCCESS(err);
11325
11326 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011327 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011328 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011329 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011330 alloc_info.descriptorPool = ds_pool;
11331 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011333 ASSERT_VK_SUCCESS(err);
11334
Tony Barboureb254902015-07-15 12:50:33 -060011335 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011337 pipe_ms_state_ci.pNext = NULL;
11338 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11339 pipe_ms_state_ci.sampleShadingEnable = 0;
11340 pipe_ms_state_ci.minSampleShading = 1.0;
11341 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011342
Tony Barboureb254902015-07-15 12:50:33 -060011343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11345 pipeline_layout_ci.pNext = NULL;
11346 pipeline_layout_ci.setLayoutCount = 1;
11347 pipeline_layout_ci.pSetLayouts = &ds_layout;
11348 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011351 ASSERT_VK_SUCCESS(err);
11352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011353 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011354 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011355 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011356 VkPipelineObj pipe(m_device);
11357 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011358 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011359 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011360 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011361 pipe.SetViewport(m_viewports);
11362 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011363 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011364
Tony Barbour552f6c02016-12-21 14:34:07 -070011365 m_commandBuffer->BeginCommandBuffer();
11366 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011368 // Don't care about actual data, just need to get to draw to flag error
11369 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011371 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011372 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011374 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011375
Chia-I Wuf7458c52015-10-26 21:10:41 +080011376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11377 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11378 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011379}
Mark Muellerdfe37552016-07-07 14:47:42 -060011380
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011382 TEST_DESCRIPTION(
11383 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11384 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011385 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011386
Mark Mueller880fce52016-08-17 15:23:23 -060011387 // The following test fails with recent NVidia drivers.
11388 // By the time core_validation is reached, the NVidia
11389 // driver has sanitized the invalid condition and core_validation
11390 // is not introduced to the failure condition. This is not the case
11391 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 // uint32_t count = static_cast<uint32_t>(~0);
11393 // VkPhysicalDevice physical_device;
11394 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11395 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011396
Mark Mueller2ee294f2016-08-04 12:59:48 -060011397 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011398 VkDeviceQueueCreateInfo queue_create_info = {};
11399 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11400 queue_create_info.queueCount = 1;
11401 queue_create_info.pQueuePriorities = &queue_priority;
11402 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11403
11404 VkPhysicalDeviceFeatures features = m_device->phy().features();
11405 VkDevice testDevice;
11406 VkDeviceCreateInfo device_create_info = {};
11407 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11408 device_create_info.queueCreateInfoCount = 1;
11409 device_create_info.pQueueCreateInfos = &queue_create_info;
11410 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011411
11412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11413 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex ");
11414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011415 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11416 m_errorMonitor->VerifyFound();
11417
11418 queue_create_info.queueFamilyIndex = 1;
11419
11420 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11421 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11422 for (unsigned i = 0; i < feature_count; i++) {
11423 if (VK_FALSE == feature_array[i]) {
11424 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011425 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11427 "While calling vkCreateDevice(), requesting feature #");
11428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
11429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11430 "You requested features that are unavailable on this device. You should first "
11431 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011432 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11433 m_errorMonitor->VerifyFound();
11434 break;
11435 }
11436 }
11437}
11438
Tobin Ehlis16edf082016-11-21 12:33:49 -070011439TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11440 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11441
11442 ASSERT_NO_FATAL_FAILURE(InitState());
11443
11444 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11445 std::vector<VkDeviceQueueCreateInfo> queue_info;
11446 queue_info.reserve(queue_props.size());
11447 std::vector<std::vector<float>> queue_priorities;
11448 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11449 VkDeviceQueueCreateInfo qi{};
11450 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11451 qi.queueFamilyIndex = i;
11452 qi.queueCount = queue_props[i].queueCount;
11453 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11454 qi.pQueuePriorities = queue_priorities[i].data();
11455 queue_info.push_back(qi);
11456 }
11457
11458 std::vector<const char *> device_extension_names;
11459
11460 VkDevice local_device;
11461 VkDeviceCreateInfo device_create_info = {};
11462 auto features = m_device->phy().features();
11463 // Intentionally disable pipeline stats
11464 features.pipelineStatisticsQuery = VK_FALSE;
11465 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11466 device_create_info.pNext = NULL;
11467 device_create_info.queueCreateInfoCount = queue_info.size();
11468 device_create_info.pQueueCreateInfos = queue_info.data();
11469 device_create_info.enabledLayerCount = 0;
11470 device_create_info.ppEnabledLayerNames = NULL;
11471 device_create_info.pEnabledFeatures = &features;
11472 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11473 ASSERT_VK_SUCCESS(err);
11474
11475 VkQueryPoolCreateInfo qpci{};
11476 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11477 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11478 qpci.queryCount = 1;
11479 VkQueryPool query_pool;
11480
11481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11482 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11483 m_errorMonitor->VerifyFound();
11484
11485 vkDestroyDevice(local_device, nullptr);
11486}
11487
Mark Mueller2ee294f2016-08-04 12:59:48 -060011488TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011489 TEST_DESCRIPTION(
11490 "Use an invalid queue index in a vkCmdWaitEvents call."
11491 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011492
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011493 const char *invalid_queue_index =
11494 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11495 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11496 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011498 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011501
11502 ASSERT_NO_FATAL_FAILURE(InitState());
11503
11504 VkEvent event;
11505 VkEventCreateInfo event_create_info{};
11506 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11507 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11508
Mark Mueller2ee294f2016-08-04 12:59:48 -060011509 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011510 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011511
Tony Barbour552f6c02016-12-21 14:34:07 -070011512 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011513
11514 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011515 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011516 ASSERT_TRUE(image.initialized());
11517 VkImageMemoryBarrier img_barrier = {};
11518 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11519 img_barrier.pNext = NULL;
11520 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11521 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11522 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11523 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11524 img_barrier.image = image.handle();
11525 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011526
11527 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11528 // that layer validation catches the case when it is not.
11529 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011530 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11531 img_barrier.subresourceRange.baseArrayLayer = 0;
11532 img_barrier.subresourceRange.baseMipLevel = 0;
11533 img_barrier.subresourceRange.layerCount = 1;
11534 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11536 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011537 m_errorMonitor->VerifyFound();
11538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011540
11541 VkQueryPool query_pool;
11542 VkQueryPoolCreateInfo query_pool_create_info = {};
11543 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11544 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11545 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011546 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011548 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011549 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11550
11551 vkEndCommandBuffer(m_commandBuffer->handle());
11552 m_errorMonitor->VerifyFound();
11553
11554 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11555 vkDestroyEvent(m_device->device(), event, nullptr);
11556}
11557
Mark Muellerdfe37552016-07-07 14:47:42 -060011558TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011559 TEST_DESCRIPTION(
11560 "Submit a command buffer using deleted vertex buffer, "
11561 "delete a buffer twice, use an invalid offset for each "
11562 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011563
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011564 const char *deleted_buffer_in_command_buffer =
11565 "Cannot submit cmd buffer "
11566 "using deleted buffer ";
11567 const char *invalid_offset_message =
11568 "vkBindBufferMemory(): "
11569 "memoryOffset is 0x";
11570 const char *invalid_storage_buffer_offset_message =
11571 "vkBindBufferMemory(): "
11572 "storage memoryOffset "
11573 "is 0x";
11574 const char *invalid_texel_buffer_offset_message =
11575 "vkBindBufferMemory(): "
11576 "texel memoryOffset "
11577 "is 0x";
11578 const char *invalid_uniform_buffer_offset_message =
11579 "vkBindBufferMemory(): "
11580 "uniform memoryOffset "
11581 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011582
11583 ASSERT_NO_FATAL_FAILURE(InitState());
11584 ASSERT_NO_FATAL_FAILURE(InitViewport());
11585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11586
11587 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011589 pipe_ms_state_ci.pNext = NULL;
11590 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11591 pipe_ms_state_ci.sampleShadingEnable = 0;
11592 pipe_ms_state_ci.minSampleShading = 1.0;
11593 pipe_ms_state_ci.pSampleMask = nullptr;
11594
11595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11597 VkPipelineLayout pipeline_layout;
11598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011600 ASSERT_VK_SUCCESS(err);
11601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011602 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11603 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011604 VkPipelineObj pipe(m_device);
11605 pipe.AddShader(&vs);
11606 pipe.AddShader(&fs);
11607 pipe.AddColorAttachment();
11608 pipe.SetMSAA(&pipe_ms_state_ci);
11609 pipe.SetViewport(m_viewports);
11610 pipe.SetScissor(m_scissors);
11611 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11612
Tony Barbour552f6c02016-12-21 14:34:07 -070011613 m_commandBuffer->BeginCommandBuffer();
11614 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011616
11617 {
11618 // Create and bind a vertex buffer in a reduced scope, which will cause
11619 // it to be deleted upon leaving this scope
11620 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011621 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011622 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11623 draw_verticies.AddVertexInputToPipe(pipe);
11624 }
11625
11626 Draw(1, 0, 0, 0);
11627
Tony Barbour552f6c02016-12-21 14:34:07 -070011628 m_commandBuffer->EndRenderPass();
11629 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011632 QueueCommandBuffer(false);
11633 m_errorMonitor->VerifyFound();
11634
11635 {
11636 // Create and bind a vertex buffer in a reduced scope, and delete it
11637 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011638 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011640 buffer_test.TestDoubleDestroy();
11641 }
11642 m_errorMonitor->VerifyFound();
11643
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011644 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011646 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011648 m_errorMonitor->SetUnexpectedError(
11649 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11650 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011651 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11652 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011653 m_errorMonitor->VerifyFound();
11654 }
11655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11657 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011658 // Create and bind a memory buffer with an invalid offset again,
11659 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011661 m_errorMonitor->SetUnexpectedError(
11662 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11663 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011664 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11665 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011666 m_errorMonitor->VerifyFound();
11667 }
11668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011669 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011670 // Create and bind a memory buffer with an invalid offset again, but
11671 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011673 m_errorMonitor->SetUnexpectedError(
11674 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11675 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011676 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11677 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011678 m_errorMonitor->VerifyFound();
11679 }
11680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011681 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011682 // Create and bind a memory buffer with an invalid offset again, but
11683 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011685 m_errorMonitor->SetUnexpectedError(
11686 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11687 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11689 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011690 m_errorMonitor->VerifyFound();
11691 }
11692
11693 {
11694 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011696 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11697 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11699 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011700 m_errorMonitor->VerifyFound();
11701 }
11702
11703 {
11704 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11707 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011708 }
11709 m_errorMonitor->VerifyFound();
11710
11711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11712}
11713
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011714// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11715TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011716 TEST_DESCRIPTION(
11717 "Hit all possible validation checks associated with the "
11718 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11719 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011720 // 3 in ValidateCmdBufImageLayouts
11721 // * -1 Attempt to submit cmd buf w/ deleted image
11722 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11723 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011724
11725 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011726 auto depth_format = find_depth_stencil_format(m_device);
11727 if (!depth_format) {
11728 printf(" No Depth + Stencil format found. Skipped.\n");
11729 return;
11730 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011731 // Create src & dst images to use for copy operations
11732 VkImage src_image;
11733 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011734 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011735
11736 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11737 const int32_t tex_width = 32;
11738 const int32_t tex_height = 32;
11739
11740 VkImageCreateInfo image_create_info = {};
11741 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11742 image_create_info.pNext = NULL;
11743 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11744 image_create_info.format = tex_format;
11745 image_create_info.extent.width = tex_width;
11746 image_create_info.extent.height = tex_height;
11747 image_create_info.extent.depth = 1;
11748 image_create_info.mipLevels = 1;
11749 image_create_info.arrayLayers = 4;
11750 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11751 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11752 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011753 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011754 image_create_info.flags = 0;
11755
11756 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11757 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011758 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11760 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011761 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11762 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11764 ASSERT_VK_SUCCESS(err);
11765
11766 // Allocate memory
11767 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011768 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011769 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011770 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11771 mem_alloc.pNext = NULL;
11772 mem_alloc.allocationSize = 0;
11773 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011774
11775 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011776 mem_alloc.allocationSize = img_mem_reqs.size;
11777 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011778 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011779 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011780 ASSERT_VK_SUCCESS(err);
11781
11782 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011783 mem_alloc.allocationSize = img_mem_reqs.size;
11784 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011785 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011786 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011787 ASSERT_VK_SUCCESS(err);
11788
11789 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011790 mem_alloc.allocationSize = img_mem_reqs.size;
11791 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011792 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011793 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011794 ASSERT_VK_SUCCESS(err);
11795
11796 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11797 ASSERT_VK_SUCCESS(err);
11798 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11799 ASSERT_VK_SUCCESS(err);
11800 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11801 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011802
Tony Barbour552f6c02016-12-21 14:34:07 -070011803 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011804 VkImageCopy copy_region;
11805 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11806 copy_region.srcSubresource.mipLevel = 0;
11807 copy_region.srcSubresource.baseArrayLayer = 0;
11808 copy_region.srcSubresource.layerCount = 1;
11809 copy_region.srcOffset.x = 0;
11810 copy_region.srcOffset.y = 0;
11811 copy_region.srcOffset.z = 0;
11812 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11813 copy_region.dstSubresource.mipLevel = 0;
11814 copy_region.dstSubresource.baseArrayLayer = 0;
11815 copy_region.dstSubresource.layerCount = 1;
11816 copy_region.dstOffset.x = 0;
11817 copy_region.dstOffset.y = 0;
11818 copy_region.dstOffset.z = 0;
11819 copy_region.extent.width = 1;
11820 copy_region.extent.height = 1;
11821 copy_region.extent.depth = 1;
11822
11823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11824 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011825 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011826 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011827 m_errorMonitor->VerifyFound();
11828 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11830 "Cannot copy from an image whose source layout is "
11831 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11832 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011833 m_errorMonitor->SetUnexpectedError(
11834 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011835 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011836 m_errorMonitor->VerifyFound();
11837 // Final src error is due to bad layout type
11838 m_errorMonitor->SetDesiredFailureMsg(
11839 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11840 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011841 m_errorMonitor->SetUnexpectedError(
11842 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11843 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011844 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011845 m_errorMonitor->VerifyFound();
11846 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11848 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011849 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011850 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011851 m_errorMonitor->VerifyFound();
11852 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11854 "Cannot copy from an image whose dest layout is "
11855 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11856 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011857 m_errorMonitor->SetUnexpectedError(
11858 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011859 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011860 m_errorMonitor->VerifyFound();
11861 m_errorMonitor->SetDesiredFailureMsg(
11862 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11863 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011864 m_errorMonitor->SetUnexpectedError(
11865 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11866 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011867 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011868 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011869
Cort3b021012016-12-07 12:00:57 -080011870 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11871 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11872 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11873 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11874 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11875 transfer_dst_image_barrier[0].srcAccessMask = 0;
11876 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11877 transfer_dst_image_barrier[0].image = dst_image;
11878 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11879 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11880 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11881 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11882 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11883 transfer_dst_image_barrier[0].image = depth_image;
11884 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11885 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11886 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11887
11888 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011889 VkClearColorValue color_clear_value = {};
11890 VkImageSubresourceRange clear_range;
11891 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11892 clear_range.baseMipLevel = 0;
11893 clear_range.baseArrayLayer = 0;
11894 clear_range.layerCount = 1;
11895 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011896
Cort3b021012016-12-07 12:00:57 -080011897 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11898 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011901 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011902 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011903 // Fail due to provided layout not matching actual current layout for color clear.
11904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011905 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011906 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011907
Cort530cf382016-12-08 09:59:47 -080011908 VkClearDepthStencilValue depth_clear_value = {};
11909 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011910
11911 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11912 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011915 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011916 m_errorMonitor->VerifyFound();
11917 // Fail due to provided layout not matching actual current layout for depth clear.
11918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011919 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011920 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011921
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011922 // Now cause error due to bad image layout transition in PipelineBarrier
11923 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011924 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011925 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011926 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011927 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011928 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11929 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011930 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11932 "You cannot transition the layout of aspect 1 from "
11933 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11934 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070011935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011936 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11937 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011938 m_errorMonitor->VerifyFound();
11939
11940 // Finally some layout errors at RenderPass create time
11941 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11942 VkAttachmentReference attach = {};
11943 // perf warning for GENERAL layout w/ non-DS input attachment
11944 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11945 VkSubpassDescription subpass = {};
11946 subpass.inputAttachmentCount = 1;
11947 subpass.pInputAttachments = &attach;
11948 VkRenderPassCreateInfo rpci = {};
11949 rpci.subpassCount = 1;
11950 rpci.pSubpasses = &subpass;
11951 rpci.attachmentCount = 1;
11952 VkAttachmentDescription attach_desc = {};
11953 attach_desc.format = VK_FORMAT_UNDEFINED;
11954 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011955 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011956 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11958 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011959 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11960 m_errorMonitor->VerifyFound();
11961 // error w/ non-general layout
11962 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11963
11964 m_errorMonitor->SetDesiredFailureMsg(
11965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11966 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11967 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11968 m_errorMonitor->VerifyFound();
11969 subpass.inputAttachmentCount = 0;
11970 subpass.colorAttachmentCount = 1;
11971 subpass.pColorAttachments = &attach;
11972 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11973 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11975 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011976 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11977 m_errorMonitor->VerifyFound();
11978 // error w/ non-color opt or GENERAL layout for color attachment
11979 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11980 m_errorMonitor->SetDesiredFailureMsg(
11981 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11982 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11983 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11984 m_errorMonitor->VerifyFound();
11985 subpass.colorAttachmentCount = 0;
11986 subpass.pDepthStencilAttachment = &attach;
11987 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11988 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11990 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011991 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11992 m_errorMonitor->VerifyFound();
11993 // error w/ non-ds opt or GENERAL layout for color attachment
11994 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11996 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11997 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011998 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11999 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012000 // For this error we need a valid renderpass so create default one
12001 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12002 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012003 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012004 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12005 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12006 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12007 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12008 // Can't do a CLEAR load on READ_ONLY initialLayout
12009 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12010 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12011 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12013 " with invalid first layout "
12014 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12015 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012016 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12017 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012018
Cort3b021012016-12-07 12:00:57 -080012019 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12020 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12021 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012022 vkDestroyImage(m_device->device(), src_image, NULL);
12023 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012024 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012025}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012026
Tobin Ehlise0936662016-10-11 08:10:51 -060012027TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12028 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12029 VkResult err;
12030
12031 ASSERT_NO_FATAL_FAILURE(InitState());
12032
12033 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12034 VkImageTiling tiling;
12035 VkFormatProperties format_properties;
12036 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12037 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12038 tiling = VK_IMAGE_TILING_LINEAR;
12039 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12040 tiling = VK_IMAGE_TILING_OPTIMAL;
12041 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012042 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012043 return;
12044 }
12045
12046 VkDescriptorPoolSize ds_type = {};
12047 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12048 ds_type.descriptorCount = 1;
12049
12050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12052 ds_pool_ci.maxSets = 1;
12053 ds_pool_ci.poolSizeCount = 1;
12054 ds_pool_ci.pPoolSizes = &ds_type;
12055 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12056
12057 VkDescriptorPool ds_pool;
12058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12059 ASSERT_VK_SUCCESS(err);
12060
12061 VkDescriptorSetLayoutBinding dsl_binding = {};
12062 dsl_binding.binding = 0;
12063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12064 dsl_binding.descriptorCount = 1;
12065 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12066 dsl_binding.pImmutableSamplers = NULL;
12067
12068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12070 ds_layout_ci.pNext = NULL;
12071 ds_layout_ci.bindingCount = 1;
12072 ds_layout_ci.pBindings = &dsl_binding;
12073
12074 VkDescriptorSetLayout ds_layout;
12075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12076 ASSERT_VK_SUCCESS(err);
12077
12078 VkDescriptorSetAllocateInfo alloc_info = {};
12079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12080 alloc_info.descriptorSetCount = 1;
12081 alloc_info.descriptorPool = ds_pool;
12082 alloc_info.pSetLayouts = &ds_layout;
12083 VkDescriptorSet descriptor_set;
12084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12085 ASSERT_VK_SUCCESS(err);
12086
12087 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12088 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12089 pipeline_layout_ci.pNext = NULL;
12090 pipeline_layout_ci.setLayoutCount = 1;
12091 pipeline_layout_ci.pSetLayouts = &ds_layout;
12092 VkPipelineLayout pipeline_layout;
12093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12094 ASSERT_VK_SUCCESS(err);
12095
12096 VkImageObj image(m_device);
12097 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12098 ASSERT_TRUE(image.initialized());
12099 VkImageView view = image.targetView(tex_format);
12100
12101 VkDescriptorImageInfo image_info = {};
12102 image_info.imageView = view;
12103 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12104
12105 VkWriteDescriptorSet descriptor_write = {};
12106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12107 descriptor_write.dstSet = descriptor_set;
12108 descriptor_write.dstBinding = 0;
12109 descriptor_write.descriptorCount = 1;
12110 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12111 descriptor_write.pImageInfo = &image_info;
12112
12113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12114 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12115 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12117 m_errorMonitor->VerifyFound();
12118
12119 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12121 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12123}
12124
Mark Mueller93b938f2016-08-18 10:27:40 -060012125TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012126 TEST_DESCRIPTION(
12127 "Use vkCmdExecuteCommands with invalid state "
12128 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012129
12130 ASSERT_NO_FATAL_FAILURE(InitState());
12131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12132
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012133 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012134 const char *simultaneous_use_message2 =
12135 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12136 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012137
12138 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012140 command_buffer_allocate_info.commandPool = m_commandPool;
12141 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12142 command_buffer_allocate_info.commandBufferCount = 1;
12143
12144 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012146 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12147 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012149 command_buffer_inheritance_info.renderPass = m_renderPass;
12150 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012151
Mark Mueller93b938f2016-08-18 10:27:40 -060012152 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 command_buffer_begin_info.flags =
12154 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012155 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12156
12157 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12158 vkEndCommandBuffer(secondary_command_buffer);
12159
Mark Mueller93b938f2016-08-18 10:27:40 -060012160 VkSubmitInfo submit_info = {};
12161 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12162 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012164
Mark Mueller4042b652016-09-05 22:52:21 -060012165 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012166 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12168 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012169 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012170 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012171 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12172 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012173
Dave Houltonfbf52152017-01-06 12:55:29 -070012174 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012175 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012176 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012177
Mark Mueller4042b652016-09-05 22:52:21 -060012178 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012179 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12180 m_errorMonitor->SetUnexpectedError(
12181 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12182 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012183 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12187 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012188 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012189 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12190 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012191
12192 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012193
12194 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012195}
12196
Tony Barbour626994c2017-02-08 15:29:37 -070012197TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12198 TEST_DESCRIPTION(
12199 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12200 "errors");
12201 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12202 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12203 ASSERT_NO_FATAL_FAILURE(InitState());
12204
12205 VkCommandBuffer cmd_bufs[2];
12206 VkCommandBufferAllocateInfo alloc_info;
12207 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12208 alloc_info.pNext = NULL;
12209 alloc_info.commandBufferCount = 2;
12210 alloc_info.commandPool = m_commandPool;
12211 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12212 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12213
12214 VkCommandBufferBeginInfo cb_binfo;
12215 cb_binfo.pNext = NULL;
12216 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12217 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12218 cb_binfo.flags = 0;
12219 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12220 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12221 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12222 vkEndCommandBuffer(cmd_bufs[0]);
12223 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12224
12225 VkSubmitInfo submit_info = {};
12226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12227 submit_info.commandBufferCount = 2;
12228 submit_info.pCommandBuffers = duplicates;
12229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12230 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12231 m_errorMonitor->VerifyFound();
12232 vkQueueWaitIdle(m_device->m_queue);
12233
12234 // Set one time use and now look for one time submit
12235 duplicates[0] = duplicates[1] = cmd_bufs[1];
12236 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12237 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12238 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12239 vkEndCommandBuffer(cmd_bufs[1]);
12240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12241 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12242 m_errorMonitor->VerifyFound();
12243 vkQueueWaitIdle(m_device->m_queue);
12244}
12245
Tobin Ehlisb093da82017-01-19 12:05:27 -070012246TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012247 TEST_DESCRIPTION(
12248 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12249 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012250
12251 ASSERT_NO_FATAL_FAILURE(InitState());
12252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12253
12254 std::vector<const char *> device_extension_names;
12255 auto features = m_device->phy().features();
12256 // Make sure gs & ts are disabled
12257 features.geometryShader = false;
12258 features.tessellationShader = false;
12259 // The sacrificial device object
12260 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12261
12262 VkCommandPoolCreateInfo pool_create_info{};
12263 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12264 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12265
12266 VkCommandPool command_pool;
12267 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12268
12269 VkCommandBufferAllocateInfo cmd = {};
12270 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12271 cmd.pNext = NULL;
12272 cmd.commandPool = command_pool;
12273 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12274 cmd.commandBufferCount = 1;
12275
12276 VkCommandBuffer cmd_buffer;
12277 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12278 ASSERT_VK_SUCCESS(err);
12279
12280 VkEvent event;
12281 VkEventCreateInfo evci = {};
12282 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12283 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12284 ASSERT_VK_SUCCESS(result);
12285
12286 VkCommandBufferBeginInfo cbbi = {};
12287 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12288 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12290 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12291 m_errorMonitor->VerifyFound();
12292
12293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12294 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12295 m_errorMonitor->VerifyFound();
12296
12297 vkDestroyEvent(test_device.handle(), event, NULL);
12298 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12299}
12300
Mark Mueller917f6bc2016-08-30 10:57:19 -060012301TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012302 TEST_DESCRIPTION(
12303 "Use vkCmdExecuteCommands with invalid state "
12304 "in primary and secondary command buffers. "
12305 "Delete objects that are inuse. Call VkQueueSubmit "
12306 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012307
12308 ASSERT_NO_FATAL_FAILURE(InitState());
12309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12310
Tony Barbour552f6c02016-12-21 14:34:07 -070012311 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312
12313 VkEvent event;
12314 VkEventCreateInfo event_create_info = {};
12315 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12316 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012318
Tony Barbour552f6c02016-12-21 14:34:07 -070012319 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012320 vkDestroyEvent(m_device->device(), event, nullptr);
12321
12322 VkSubmitInfo submit_info = {};
12323 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12324 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012327 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12328 m_errorMonitor->VerifyFound();
12329
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012330 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012331 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12332
12333 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12334
Mark Mueller917f6bc2016-08-30 10:57:19 -060012335 VkSemaphoreCreateInfo semaphore_create_info = {};
12336 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12337 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012338 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012339 VkFenceCreateInfo fence_create_info = {};
12340 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12341 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012343
12344 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012345 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012346 descriptor_pool_type_count.descriptorCount = 1;
12347
12348 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12349 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12350 descriptor_pool_create_info.maxSets = 1;
12351 descriptor_pool_create_info.poolSizeCount = 1;
12352 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012353 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012354
12355 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012356 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012357
12358 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012359 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012360 descriptorset_layout_binding.descriptorCount = 1;
12361 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12362
12363 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012365 descriptorset_layout_create_info.bindingCount = 1;
12366 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12367
12368 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 ASSERT_VK_SUCCESS(
12370 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012371
12372 VkDescriptorSet descriptorset;
12373 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012374 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012375 descriptorset_allocate_info.descriptorSetCount = 1;
12376 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12377 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012379
Mark Mueller4042b652016-09-05 22:52:21 -060012380 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12381
12382 VkDescriptorBufferInfo buffer_info = {};
12383 buffer_info.buffer = buffer_test.GetBuffer();
12384 buffer_info.offset = 0;
12385 buffer_info.range = 1024;
12386
12387 VkWriteDescriptorSet write_descriptor_set = {};
12388 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12389 write_descriptor_set.dstSet = descriptorset;
12390 write_descriptor_set.descriptorCount = 1;
12391 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12392 write_descriptor_set.pBufferInfo = &buffer_info;
12393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012396 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12397 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012398
12399 VkPipelineObj pipe(m_device);
12400 pipe.AddColorAttachment();
12401 pipe.AddShader(&vs);
12402 pipe.AddShader(&fs);
12403
12404 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012405 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012406 pipeline_layout_create_info.setLayoutCount = 1;
12407 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12408
12409 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012410 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012411
12412 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12413
Tony Barbour552f6c02016-12-21 14:34:07 -070012414 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12418 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12419 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012420
Tony Barbour552f6c02016-12-21 14:34:07 -070012421 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012422
Mark Mueller917f6bc2016-08-30 10:57:19 -060012423 submit_info.signalSemaphoreCount = 1;
12424 submit_info.pSignalSemaphores = &semaphore;
12425 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012426 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012427
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012429 vkDestroyEvent(m_device->device(), event, nullptr);
12430 m_errorMonitor->VerifyFound();
12431
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012433 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12434 m_errorMonitor->VerifyFound();
12435
Jeremy Hayes08369882017-02-02 10:31:06 -070012436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012437 vkDestroyFence(m_device->device(), fence, nullptr);
12438 m_errorMonitor->VerifyFound();
12439
Tobin Ehlis122207b2016-09-01 08:50:06 -070012440 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012441 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12442 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012443 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012444 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12445 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012446 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012447 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12448 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012449 vkDestroyEvent(m_device->device(), event, nullptr);
12450 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012451 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012452 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12453}
12454
Tobin Ehlis2adda372016-09-01 08:51:06 -070012455TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12456 TEST_DESCRIPTION("Delete in-use query pool.");
12457
12458 ASSERT_NO_FATAL_FAILURE(InitState());
12459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12460
12461 VkQueryPool query_pool;
12462 VkQueryPoolCreateInfo query_pool_ci{};
12463 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12464 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12465 query_pool_ci.queryCount = 1;
12466 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012467 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012468 // Reset query pool to create binding with cmd buffer
12469 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12470
Tony Barbour552f6c02016-12-21 14:34:07 -070012471 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012472
12473 VkSubmitInfo submit_info = {};
12474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12475 submit_info.commandBufferCount = 1;
12476 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12477 // Submit cmd buffer and then destroy query pool while in-flight
12478 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12479
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012481 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12482 m_errorMonitor->VerifyFound();
12483
12484 vkQueueWaitIdle(m_device->m_queue);
12485 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012486 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12487 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012488 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12489}
12490
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012491TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12492 TEST_DESCRIPTION("Delete in-use pipeline.");
12493
12494 ASSERT_NO_FATAL_FAILURE(InitState());
12495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12496
12497 // Empty pipeline layout used for binding PSO
12498 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12499 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12500 pipeline_layout_ci.setLayoutCount = 0;
12501 pipeline_layout_ci.pSetLayouts = NULL;
12502
12503 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012504 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012505 ASSERT_VK_SUCCESS(err);
12506
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012508 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012509 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012511 // Store pipeline handle so we can actually delete it before test finishes
12512 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012513 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012514 VkPipelineObj pipe(m_device);
12515 pipe.AddShader(&vs);
12516 pipe.AddShader(&fs);
12517 pipe.AddColorAttachment();
12518 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12519 delete_this_pipeline = pipe.handle();
12520
Tony Barbour552f6c02016-12-21 14:34:07 -070012521 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012522 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012523 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012524
Tony Barbour552f6c02016-12-21 14:34:07 -070012525 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012526
12527 VkSubmitInfo submit_info = {};
12528 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12529 submit_info.commandBufferCount = 1;
12530 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12531 // Submit cmd buffer and then pipeline destroyed while in-flight
12532 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012533 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012534 m_errorMonitor->VerifyFound();
12535 // Make sure queue finished and then actually delete pipeline
12536 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012537 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12538 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012539 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12540 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12541}
12542
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012543TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12544 TEST_DESCRIPTION("Delete in-use imageView.");
12545
12546 ASSERT_NO_FATAL_FAILURE(InitState());
12547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12548
12549 VkDescriptorPoolSize ds_type_count;
12550 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12551 ds_type_count.descriptorCount = 1;
12552
12553 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12554 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12555 ds_pool_ci.maxSets = 1;
12556 ds_pool_ci.poolSizeCount = 1;
12557 ds_pool_ci.pPoolSizes = &ds_type_count;
12558
12559 VkDescriptorPool ds_pool;
12560 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12561 ASSERT_VK_SUCCESS(err);
12562
12563 VkSamplerCreateInfo sampler_ci = {};
12564 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12565 sampler_ci.pNext = NULL;
12566 sampler_ci.magFilter = VK_FILTER_NEAREST;
12567 sampler_ci.minFilter = VK_FILTER_NEAREST;
12568 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12569 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12570 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12571 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12572 sampler_ci.mipLodBias = 1.0;
12573 sampler_ci.anisotropyEnable = VK_FALSE;
12574 sampler_ci.maxAnisotropy = 1;
12575 sampler_ci.compareEnable = VK_FALSE;
12576 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12577 sampler_ci.minLod = 1.0;
12578 sampler_ci.maxLod = 1.0;
12579 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12580 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12581 VkSampler sampler;
12582
12583 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12584 ASSERT_VK_SUCCESS(err);
12585
12586 VkDescriptorSetLayoutBinding layout_binding;
12587 layout_binding.binding = 0;
12588 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12589 layout_binding.descriptorCount = 1;
12590 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12591 layout_binding.pImmutableSamplers = NULL;
12592
12593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12595 ds_layout_ci.bindingCount = 1;
12596 ds_layout_ci.pBindings = &layout_binding;
12597 VkDescriptorSetLayout ds_layout;
12598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12599 ASSERT_VK_SUCCESS(err);
12600
12601 VkDescriptorSetAllocateInfo alloc_info = {};
12602 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12603 alloc_info.descriptorSetCount = 1;
12604 alloc_info.descriptorPool = ds_pool;
12605 alloc_info.pSetLayouts = &ds_layout;
12606 VkDescriptorSet descriptor_set;
12607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12608 ASSERT_VK_SUCCESS(err);
12609
12610 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12611 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12612 pipeline_layout_ci.pNext = NULL;
12613 pipeline_layout_ci.setLayoutCount = 1;
12614 pipeline_layout_ci.pSetLayouts = &ds_layout;
12615
12616 VkPipelineLayout pipeline_layout;
12617 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12618 ASSERT_VK_SUCCESS(err);
12619
12620 VkImageObj image(m_device);
12621 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12622 ASSERT_TRUE(image.initialized());
12623
12624 VkImageView view;
12625 VkImageViewCreateInfo ivci = {};
12626 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12627 ivci.image = image.handle();
12628 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12629 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12630 ivci.subresourceRange.layerCount = 1;
12631 ivci.subresourceRange.baseMipLevel = 0;
12632 ivci.subresourceRange.levelCount = 1;
12633 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12634
12635 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12636 ASSERT_VK_SUCCESS(err);
12637
12638 VkDescriptorImageInfo image_info{};
12639 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12640 image_info.imageView = view;
12641 image_info.sampler = sampler;
12642
12643 VkWriteDescriptorSet descriptor_write = {};
12644 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12645 descriptor_write.dstSet = descriptor_set;
12646 descriptor_write.dstBinding = 0;
12647 descriptor_write.descriptorCount = 1;
12648 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12649 descriptor_write.pImageInfo = &image_info;
12650
12651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12652
12653 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012654 char const *vsSource =
12655 "#version 450\n"
12656 "\n"
12657 "out gl_PerVertex { \n"
12658 " vec4 gl_Position;\n"
12659 "};\n"
12660 "void main(){\n"
12661 " gl_Position = vec4(1);\n"
12662 "}\n";
12663 char const *fsSource =
12664 "#version 450\n"
12665 "\n"
12666 "layout(set=0, binding=0) uniform sampler2D s;\n"
12667 "layout(location=0) out vec4 x;\n"
12668 "void main(){\n"
12669 " x = texture(s, vec2(1));\n"
12670 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012671 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12672 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12673 VkPipelineObj pipe(m_device);
12674 pipe.AddShader(&vs);
12675 pipe.AddShader(&fs);
12676 pipe.AddColorAttachment();
12677 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12678
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012680
Tony Barbour552f6c02016-12-21 14:34:07 -070012681 m_commandBuffer->BeginCommandBuffer();
12682 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012683 // Bind pipeline to cmd buffer
12684 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12686 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012687
12688 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12689 VkRect2D scissor = {{0, 0}, {16, 16}};
12690 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12691 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12692
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012693 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012694 m_commandBuffer->EndRenderPass();
12695 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012696 // Submit cmd buffer then destroy sampler
12697 VkSubmitInfo submit_info = {};
12698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12699 submit_info.commandBufferCount = 1;
12700 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12701 // Submit cmd buffer and then destroy imageView while in-flight
12702 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12703
12704 vkDestroyImageView(m_device->device(), view, nullptr);
12705 m_errorMonitor->VerifyFound();
12706 vkQueueWaitIdle(m_device->m_queue);
12707 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012708 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12709 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012710 vkDestroyImageView(m_device->device(), view, NULL);
12711 vkDestroySampler(m_device->device(), sampler, nullptr);
12712 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12713 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12714 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12715}
12716
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012717TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12718 TEST_DESCRIPTION("Delete in-use bufferView.");
12719
12720 ASSERT_NO_FATAL_FAILURE(InitState());
12721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12722
12723 VkDescriptorPoolSize ds_type_count;
12724 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12725 ds_type_count.descriptorCount = 1;
12726
12727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12729 ds_pool_ci.maxSets = 1;
12730 ds_pool_ci.poolSizeCount = 1;
12731 ds_pool_ci.pPoolSizes = &ds_type_count;
12732
12733 VkDescriptorPool ds_pool;
12734 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12735 ASSERT_VK_SUCCESS(err);
12736
12737 VkDescriptorSetLayoutBinding layout_binding;
12738 layout_binding.binding = 0;
12739 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12740 layout_binding.descriptorCount = 1;
12741 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12742 layout_binding.pImmutableSamplers = NULL;
12743
12744 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12745 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12746 ds_layout_ci.bindingCount = 1;
12747 ds_layout_ci.pBindings = &layout_binding;
12748 VkDescriptorSetLayout ds_layout;
12749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12750 ASSERT_VK_SUCCESS(err);
12751
12752 VkDescriptorSetAllocateInfo alloc_info = {};
12753 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12754 alloc_info.descriptorSetCount = 1;
12755 alloc_info.descriptorPool = ds_pool;
12756 alloc_info.pSetLayouts = &ds_layout;
12757 VkDescriptorSet descriptor_set;
12758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12759 ASSERT_VK_SUCCESS(err);
12760
12761 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12762 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12763 pipeline_layout_ci.pNext = NULL;
12764 pipeline_layout_ci.setLayoutCount = 1;
12765 pipeline_layout_ci.pSetLayouts = &ds_layout;
12766
12767 VkPipelineLayout pipeline_layout;
12768 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12769 ASSERT_VK_SUCCESS(err);
12770
12771 VkBuffer buffer;
12772 uint32_t queue_family_index = 0;
12773 VkBufferCreateInfo buffer_create_info = {};
12774 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12775 buffer_create_info.size = 1024;
12776 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12777 buffer_create_info.queueFamilyIndexCount = 1;
12778 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12779
12780 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12781 ASSERT_VK_SUCCESS(err);
12782
12783 VkMemoryRequirements memory_reqs;
12784 VkDeviceMemory buffer_memory;
12785
12786 VkMemoryAllocateInfo memory_info = {};
12787 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12788 memory_info.allocationSize = 0;
12789 memory_info.memoryTypeIndex = 0;
12790
12791 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12792 memory_info.allocationSize = memory_reqs.size;
12793 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12794 ASSERT_TRUE(pass);
12795
12796 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12797 ASSERT_VK_SUCCESS(err);
12798 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12799 ASSERT_VK_SUCCESS(err);
12800
12801 VkBufferView view;
12802 VkBufferViewCreateInfo bvci = {};
12803 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12804 bvci.buffer = buffer;
12805 bvci.format = VK_FORMAT_R8_UNORM;
12806 bvci.range = VK_WHOLE_SIZE;
12807
12808 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12809 ASSERT_VK_SUCCESS(err);
12810
12811 VkWriteDescriptorSet descriptor_write = {};
12812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12813 descriptor_write.dstSet = descriptor_set;
12814 descriptor_write.dstBinding = 0;
12815 descriptor_write.descriptorCount = 1;
12816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12817 descriptor_write.pTexelBufferView = &view;
12818
12819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012821 char const *vsSource =
12822 "#version 450\n"
12823 "\n"
12824 "out gl_PerVertex { \n"
12825 " vec4 gl_Position;\n"
12826 "};\n"
12827 "void main(){\n"
12828 " gl_Position = vec4(1);\n"
12829 "}\n";
12830 char const *fsSource =
12831 "#version 450\n"
12832 "\n"
12833 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12834 "layout(location=0) out vec4 x;\n"
12835 "void main(){\n"
12836 " x = imageLoad(s, 0);\n"
12837 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12840 VkPipelineObj pipe(m_device);
12841 pipe.AddShader(&vs);
12842 pipe.AddShader(&fs);
12843 pipe.AddColorAttachment();
12844 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12845
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012847
Tony Barbour552f6c02016-12-21 14:34:07 -070012848 m_commandBuffer->BeginCommandBuffer();
12849 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012850 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12851 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12852 VkRect2D scissor = {{0, 0}, {16, 16}};
12853 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12854 // Bind pipeline to cmd buffer
12855 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12856 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12857 &descriptor_set, 0, nullptr);
12858 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012859 m_commandBuffer->EndRenderPass();
12860 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012861
12862 VkSubmitInfo submit_info = {};
12863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12864 submit_info.commandBufferCount = 1;
12865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12866 // Submit cmd buffer and then destroy bufferView while in-flight
12867 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12868
12869 vkDestroyBufferView(m_device->device(), view, nullptr);
12870 m_errorMonitor->VerifyFound();
12871 vkQueueWaitIdle(m_device->m_queue);
12872 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012873 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12874 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012875 vkDestroyBufferView(m_device->device(), view, NULL);
12876 vkDestroyBuffer(m_device->device(), buffer, NULL);
12877 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12880 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12881}
12882
Tobin Ehlis209532e2016-09-07 13:52:18 -060012883TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12884 TEST_DESCRIPTION("Delete in-use sampler.");
12885
12886 ASSERT_NO_FATAL_FAILURE(InitState());
12887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12888
12889 VkDescriptorPoolSize ds_type_count;
12890 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12891 ds_type_count.descriptorCount = 1;
12892
12893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12895 ds_pool_ci.maxSets = 1;
12896 ds_pool_ci.poolSizeCount = 1;
12897 ds_pool_ci.pPoolSizes = &ds_type_count;
12898
12899 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012900 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012901 ASSERT_VK_SUCCESS(err);
12902
12903 VkSamplerCreateInfo sampler_ci = {};
12904 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12905 sampler_ci.pNext = NULL;
12906 sampler_ci.magFilter = VK_FILTER_NEAREST;
12907 sampler_ci.minFilter = VK_FILTER_NEAREST;
12908 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12909 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12910 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12911 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12912 sampler_ci.mipLodBias = 1.0;
12913 sampler_ci.anisotropyEnable = VK_FALSE;
12914 sampler_ci.maxAnisotropy = 1;
12915 sampler_ci.compareEnable = VK_FALSE;
12916 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12917 sampler_ci.minLod = 1.0;
12918 sampler_ci.maxLod = 1.0;
12919 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12920 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12921 VkSampler sampler;
12922
12923 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12924 ASSERT_VK_SUCCESS(err);
12925
12926 VkDescriptorSetLayoutBinding layout_binding;
12927 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012928 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012929 layout_binding.descriptorCount = 1;
12930 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12931 layout_binding.pImmutableSamplers = NULL;
12932
12933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12935 ds_layout_ci.bindingCount = 1;
12936 ds_layout_ci.pBindings = &layout_binding;
12937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012939 ASSERT_VK_SUCCESS(err);
12940
12941 VkDescriptorSetAllocateInfo alloc_info = {};
12942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12943 alloc_info.descriptorSetCount = 1;
12944 alloc_info.descriptorPool = ds_pool;
12945 alloc_info.pSetLayouts = &ds_layout;
12946 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012948 ASSERT_VK_SUCCESS(err);
12949
12950 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12951 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12952 pipeline_layout_ci.pNext = NULL;
12953 pipeline_layout_ci.setLayoutCount = 1;
12954 pipeline_layout_ci.pSetLayouts = &ds_layout;
12955
12956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012958 ASSERT_VK_SUCCESS(err);
12959
12960 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012962 ASSERT_TRUE(image.initialized());
12963
12964 VkImageView view;
12965 VkImageViewCreateInfo ivci = {};
12966 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12967 ivci.image = image.handle();
12968 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12969 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12970 ivci.subresourceRange.layerCount = 1;
12971 ivci.subresourceRange.baseMipLevel = 0;
12972 ivci.subresourceRange.levelCount = 1;
12973 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12974
12975 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12976 ASSERT_VK_SUCCESS(err);
12977
12978 VkDescriptorImageInfo image_info{};
12979 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12980 image_info.imageView = view;
12981 image_info.sampler = sampler;
12982
12983 VkWriteDescriptorSet descriptor_write = {};
12984 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12985 descriptor_write.dstSet = descriptor_set;
12986 descriptor_write.dstBinding = 0;
12987 descriptor_write.descriptorCount = 1;
12988 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12989 descriptor_write.pImageInfo = &image_info;
12990
12991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12992
12993 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012994 char const *vsSource =
12995 "#version 450\n"
12996 "\n"
12997 "out gl_PerVertex { \n"
12998 " vec4 gl_Position;\n"
12999 "};\n"
13000 "void main(){\n"
13001 " gl_Position = vec4(1);\n"
13002 "}\n";
13003 char const *fsSource =
13004 "#version 450\n"
13005 "\n"
13006 "layout(set=0, binding=0) uniform sampler2D s;\n"
13007 "layout(location=0) out vec4 x;\n"
13008 "void main(){\n"
13009 " x = texture(s, vec2(1));\n"
13010 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013011 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13012 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13013 VkPipelineObj pipe(m_device);
13014 pipe.AddShader(&vs);
13015 pipe.AddShader(&fs);
13016 pipe.AddColorAttachment();
13017 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13018
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013020
Tony Barbour552f6c02016-12-21 14:34:07 -070013021 m_commandBuffer->BeginCommandBuffer();
13022 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013023 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13025 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13026 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013027
13028 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13029 VkRect2D scissor = {{0, 0}, {16, 16}};
13030 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13031 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13032
Tobin Ehlis209532e2016-09-07 13:52:18 -060013033 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013034 m_commandBuffer->EndRenderPass();
13035 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013036 // Submit cmd buffer then destroy sampler
13037 VkSubmitInfo submit_info = {};
13038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13039 submit_info.commandBufferCount = 1;
13040 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13041 // Submit cmd buffer and then destroy sampler while in-flight
13042 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13043
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013044 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013045 m_errorMonitor->VerifyFound();
13046 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013047
Tobin Ehlis209532e2016-09-07 13:52:18 -060013048 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013049 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13050 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013051 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013052 vkDestroyImageView(m_device->device(), view, NULL);
13053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13054 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13055 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13056}
13057
Mark Mueller1cd9f412016-08-25 13:23:52 -060013058TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 TEST_DESCRIPTION(
13060 "Call VkQueueSubmit with a semaphore that is already "
13061 "signaled but not waited on by the queue. Wait on a "
13062 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013063
13064 ASSERT_NO_FATAL_FAILURE(InitState());
13065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013068 const char *invalid_fence_wait_message =
13069 " which has not been submitted on a Queue or during "
13070 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013071
Tony Barbour552f6c02016-12-21 14:34:07 -070013072 m_commandBuffer->BeginCommandBuffer();
13073 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013074
13075 VkSemaphoreCreateInfo semaphore_create_info = {};
13076 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13077 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013078 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013079 VkSubmitInfo submit_info = {};
13080 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13081 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013082 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013083 submit_info.signalSemaphoreCount = 1;
13084 submit_info.pSignalSemaphores = &semaphore;
13085 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013086 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013087 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013088 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013089 m_commandBuffer->BeginCommandBuffer();
13090 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013092 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13093 m_errorMonitor->VerifyFound();
13094
Mark Mueller1cd9f412016-08-25 13:23:52 -060013095 VkFenceCreateInfo fence_create_info = {};
13096 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13097 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013098 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013101 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13102 m_errorMonitor->VerifyFound();
13103
Mark Mueller4042b652016-09-05 22:52:21 -060013104 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013105 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013106 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13107}
13108
Tobin Ehlis4af23302016-07-19 10:50:30 -060013109TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013110 TEST_DESCRIPTION(
13111 "Bind a secondary command buffer with with a framebuffer "
13112 "that does not match the framebuffer for the active "
13113 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013114 ASSERT_NO_FATAL_FAILURE(InitState());
13115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13116
13117 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 VkAttachmentDescription attachment = {0,
13119 VK_FORMAT_B8G8R8A8_UNORM,
13120 VK_SAMPLE_COUNT_1_BIT,
13121 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13122 VK_ATTACHMENT_STORE_OP_STORE,
13123 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13124 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13125 VK_IMAGE_LAYOUT_UNDEFINED,
13126 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013130 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013132 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013133
13134 VkRenderPass rp;
13135 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13136 ASSERT_VK_SUCCESS(err);
13137
13138 // A compatible framebuffer.
13139 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013141 ASSERT_TRUE(image.initialized());
13142
13143 VkImageViewCreateInfo ivci = {
13144 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13145 nullptr,
13146 0,
13147 image.handle(),
13148 VK_IMAGE_VIEW_TYPE_2D,
13149 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013150 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13151 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013152 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13153 };
13154 VkImageView view;
13155 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13156 ASSERT_VK_SUCCESS(err);
13157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013159 VkFramebuffer fb;
13160 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13161 ASSERT_VK_SUCCESS(err);
13162
13163 VkCommandBufferAllocateInfo cbai = {};
13164 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13165 cbai.commandPool = m_commandPool;
13166 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13167 cbai.commandBufferCount = 1;
13168
13169 VkCommandBuffer sec_cb;
13170 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13171 ASSERT_VK_SUCCESS(err);
13172 VkCommandBufferBeginInfo cbbi = {};
13173 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013174 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013175 cbii.renderPass = renderPass();
13176 cbii.framebuffer = fb;
13177 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13178 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013180 cbbi.pInheritanceInfo = &cbii;
13181 vkBeginCommandBuffer(sec_cb, &cbbi);
13182 vkEndCommandBuffer(sec_cb);
13183
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013184 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013185 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13186 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013189 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013190 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13191 m_errorMonitor->VerifyFound();
13192 // Cleanup
13193 vkDestroyImageView(m_device->device(), view, NULL);
13194 vkDestroyRenderPass(m_device->device(), rp, NULL);
13195 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13196}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013197
13198TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013199 TEST_DESCRIPTION(
13200 "If logicOp is available on the device, set it to an "
13201 "invalid value. If logicOp is not available, attempt to "
13202 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013203 ASSERT_NO_FATAL_FAILURE(InitState());
13204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13205
13206 auto features = m_device->phy().features();
13207 // Set the expected error depending on whether or not logicOp available
13208 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13210 "If logic operations feature not "
13211 "enabled, logicOpEnable must be "
13212 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013213 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013215 }
13216 // Create a pipeline using logicOp
13217 VkResult err;
13218
13219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13221
13222 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013224 ASSERT_VK_SUCCESS(err);
13225
13226 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13227 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13228 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013229 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013230 vp_state_ci.pViewports = &vp;
13231 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013232 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013233 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013234
13235 VkPipelineShaderStageCreateInfo shaderStages[2];
13236 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13239 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013240 shaderStages[0] = vs.GetStageCreateInfo();
13241 shaderStages[1] = fs.GetStageCreateInfo();
13242
13243 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13244 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13245
13246 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13247 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13248 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13249
13250 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13251 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013252 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013253
13254 VkPipelineColorBlendAttachmentState att = {};
13255 att.blendEnable = VK_FALSE;
13256 att.colorWriteMask = 0xf;
13257
13258 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13259 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13260 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13261 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013262 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013263 cb_ci.attachmentCount = 1;
13264 cb_ci.pAttachments = &att;
13265
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013266 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13267 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13268 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13269
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013270 VkGraphicsPipelineCreateInfo gp_ci = {};
13271 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13272 gp_ci.stageCount = 2;
13273 gp_ci.pStages = shaderStages;
13274 gp_ci.pVertexInputState = &vi_ci;
13275 gp_ci.pInputAssemblyState = &ia_ci;
13276 gp_ci.pViewportState = &vp_state_ci;
13277 gp_ci.pRasterizationState = &rs_ci;
13278 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013279 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013280 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13281 gp_ci.layout = pipeline_layout;
13282 gp_ci.renderPass = renderPass();
13283
13284 VkPipelineCacheCreateInfo pc_ci = {};
13285 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13286
13287 VkPipeline pipeline;
13288 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013289 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013290 ASSERT_VK_SUCCESS(err);
13291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013293 m_errorMonitor->VerifyFound();
13294 if (VK_SUCCESS == err) {
13295 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13296 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013297 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13299}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013300
Mike Stroyanaccf7692015-05-12 16:00:45 -060013301#if GTEST_IS_THREADSAFE
13302struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013303 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013304 VkEvent event;
13305 bool bailout;
13306};
13307
Karl Schultz6addd812016-02-02 17:17:23 -070013308extern "C" void *AddToCommandBuffer(void *arg) {
13309 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013310
Mike Stroyana6d14942016-07-13 15:10:05 -060013311 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013312 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013313 if (data->bailout) {
13314 break;
13315 }
13316 }
13317 return NULL;
13318}
13319
Karl Schultz6addd812016-02-02 17:17:23 -070013320TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013321 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013324
Mike Stroyanaccf7692015-05-12 16:00:45 -060013325 ASSERT_NO_FATAL_FAILURE(InitState());
13326 ASSERT_NO_FATAL_FAILURE(InitViewport());
13327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13328
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013329 // Calls AllocateCommandBuffers
13330 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013331
13332 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013334
13335 VkEventCreateInfo event_info;
13336 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013337 VkResult err;
13338
13339 memset(&event_info, 0, sizeof(event_info));
13340 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13341
Chia-I Wuf7458c52015-10-26 21:10:41 +080013342 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013343 ASSERT_VK_SUCCESS(err);
13344
Mike Stroyanaccf7692015-05-12 16:00:45 -060013345 err = vkResetEvent(device(), event);
13346 ASSERT_VK_SUCCESS(err);
13347
13348 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013349 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013350 data.event = event;
13351 data.bailout = false;
13352 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013353
13354 // First do some correct operations using multiple threads.
13355 // Add many entries to command buffer from another thread.
13356 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13357 // Make non-conflicting calls from this thread at the same time.
13358 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013359 uint32_t count;
13360 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013361 }
13362 test_platform_thread_join(thread, NULL);
13363
13364 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013365 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013366 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013367 // Add many entries to command buffer from this thread at the same time.
13368 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013369
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013370 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013371 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013372
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013373 m_errorMonitor->SetBailout(NULL);
13374
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013375 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013376
Chia-I Wuf7458c52015-10-26 21:10:41 +080013377 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013378}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013379#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013380
Karl Schultz6addd812016-02-02 17:17:23 -070013381TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013382 TEST_DESCRIPTION(
13383 "Test that an error is produced for a spirv module "
13384 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013387
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013388 ASSERT_NO_FATAL_FAILURE(InitState());
13389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13390
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013391 VkShaderModule module;
13392 VkShaderModuleCreateInfo moduleCreateInfo;
13393 struct icd_spv_header spv;
13394
13395 spv.magic = ICD_SPV_MAGIC;
13396 spv.version = ICD_SPV_VERSION;
13397 spv.gen_magic = 0;
13398
13399 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13400 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013401 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013402 moduleCreateInfo.codeSize = 4;
13403 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013404 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013405
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013406 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013407}
13408
Karl Schultz6addd812016-02-02 17:17:23 -070013409TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013410 TEST_DESCRIPTION(
13411 "Test that an error is produced for a spirv module "
13412 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013415
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013416 ASSERT_NO_FATAL_FAILURE(InitState());
13417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13418
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013419 VkShaderModule module;
13420 VkShaderModuleCreateInfo moduleCreateInfo;
13421 struct icd_spv_header spv;
13422
13423 spv.magic = ~ICD_SPV_MAGIC;
13424 spv.version = ICD_SPV_VERSION;
13425 spv.gen_magic = 0;
13426
13427 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13428 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013429 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013430 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13431 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013432 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013433
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013434 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013435}
13436
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013437#if 0
13438// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013439TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013441 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013442
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013443 ASSERT_NO_FATAL_FAILURE(InitState());
13444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13445
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013446 VkShaderModule module;
13447 VkShaderModuleCreateInfo moduleCreateInfo;
13448 struct icd_spv_header spv;
13449
13450 spv.magic = ICD_SPV_MAGIC;
13451 spv.version = ~ICD_SPV_VERSION;
13452 spv.gen_magic = 0;
13453
13454 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13455 moduleCreateInfo.pNext = NULL;
13456
Karl Schultz6addd812016-02-02 17:17:23 -070013457 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013458 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13459 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013460 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013461
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013462 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013463}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013464#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013465
Karl Schultz6addd812016-02-02 17:17:23 -070013466TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013467 TEST_DESCRIPTION(
13468 "Test that a warning is produced for a vertex output that "
13469 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013471
Chris Forbes9f7ff632015-05-25 11:13:08 +120013472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013475 char const *vsSource =
13476 "#version 450\n"
13477 "\n"
13478 "layout(location=0) out float x;\n"
13479 "out gl_PerVertex {\n"
13480 " vec4 gl_Position;\n"
13481 "};\n"
13482 "void main(){\n"
13483 " gl_Position = vec4(1);\n"
13484 " x = 0;\n"
13485 "}\n";
13486 char const *fsSource =
13487 "#version 450\n"
13488 "\n"
13489 "layout(location=0) out vec4 color;\n"
13490 "void main(){\n"
13491 " color = vec4(1);\n"
13492 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013493
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013496
13497 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013498 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013499 pipe.AddShader(&vs);
13500 pipe.AddShader(&fs);
13501
Chris Forbes9f7ff632015-05-25 11:13:08 +120013502 VkDescriptorSetObj descriptorSet(m_device);
13503 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013505
Tony Barbour5781e8f2015-08-04 16:23:11 -060013506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013507
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013508 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013509}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013510
Mark Mueller098c9cb2016-09-08 09:01:57 -060013511TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13512 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13513
13514 ASSERT_NO_FATAL_FAILURE(InitState());
13515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13516
13517 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013518 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013520 char const *vsSource =
13521 "#version 450\n"
13522 "\n"
13523 "out gl_PerVertex {\n"
13524 " vec4 gl_Position;\n"
13525 "};\n"
13526 "void main(){\n"
13527 " gl_Position = vec4(1);\n"
13528 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013530 char const *fsSource =
13531 "#version 450\n"
13532 "\n"
13533 "layout (constant_id = 0) const float r = 0.0f;\n"
13534 "layout(location = 0) out vec4 uFragColor;\n"
13535 "void main(){\n"
13536 " uFragColor = vec4(r,1,0,1);\n"
13537 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013538
13539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13541
13542 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13543 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13544
13545 VkPipelineLayout pipeline_layout;
13546 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13547
13548 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13549 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13550 vp_state_create_info.viewportCount = 1;
13551 VkViewport viewport = {};
13552 vp_state_create_info.pViewports = &viewport;
13553 vp_state_create_info.scissorCount = 1;
13554 VkRect2D scissors = {};
13555 vp_state_create_info.pScissors = &scissors;
13556
13557 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13558
13559 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13560 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13561 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13562 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13563
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013564 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013565
13566 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13567 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13568
13569 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13570 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13571 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13572
13573 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13574 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13575 rasterization_state_create_info.pNext = nullptr;
13576 rasterization_state_create_info.lineWidth = 1.0f;
13577 rasterization_state_create_info.rasterizerDiscardEnable = true;
13578
13579 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13580 color_blend_attachment_state.blendEnable = VK_FALSE;
13581 color_blend_attachment_state.colorWriteMask = 0xf;
13582
13583 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13584 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13585 color_blend_state_create_info.attachmentCount = 1;
13586 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13587
13588 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13589 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13590 graphicspipe_create_info.stageCount = 2;
13591 graphicspipe_create_info.pStages = shader_stage_create_info;
13592 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13593 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13594 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13595 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13596 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13597 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13598 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13599 graphicspipe_create_info.layout = pipeline_layout;
13600 graphicspipe_create_info.renderPass = renderPass();
13601
13602 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13603 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13604
13605 VkPipelineCache pipelineCache;
13606 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13607
13608 // This structure maps constant ids to data locations.
13609 const VkSpecializationMapEntry entry =
13610 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013611 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013612
13613 uint32_t data = 1;
13614
13615 // Set up the info describing spec map and data
13616 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013617 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013618 };
13619 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13620
13621 VkPipeline pipeline;
13622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13623 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13624 m_errorMonitor->VerifyFound();
13625
13626 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13627 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13628}
13629
13630TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13631 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13632
13633 ASSERT_NO_FATAL_FAILURE(InitState());
13634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13635
13636 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13637
13638 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13639 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13640 descriptor_pool_type_count[0].descriptorCount = 1;
13641 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13642 descriptor_pool_type_count[1].descriptorCount = 1;
13643
13644 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13645 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13646 descriptor_pool_create_info.maxSets = 1;
13647 descriptor_pool_create_info.poolSizeCount = 2;
13648 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13649 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13650
13651 VkDescriptorPool descriptorset_pool;
13652 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13653
13654 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13655 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13656 descriptorset_layout_binding.descriptorCount = 1;
13657 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013658 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013659
13660 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13661 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13662 descriptorset_layout_create_info.bindingCount = 1;
13663 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13664
13665 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013666 ASSERT_VK_SUCCESS(
13667 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013668
13669 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13670 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13671 descriptorset_allocate_info.descriptorSetCount = 1;
13672 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13673 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13674 VkDescriptorSet descriptorset;
13675 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13676
13677 // Challenge core_validation with a non uniform buffer type.
13678 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13679
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013680 char const *vsSource =
13681 "#version 450\n"
13682 "\n"
13683 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13684 " mat4 mvp;\n"
13685 "} ubuf;\n"
13686 "out gl_PerVertex {\n"
13687 " vec4 gl_Position;\n"
13688 "};\n"
13689 "void main(){\n"
13690 " gl_Position = ubuf.mvp * vec4(1);\n"
13691 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013692
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013693 char const *fsSource =
13694 "#version 450\n"
13695 "\n"
13696 "layout(location = 0) out vec4 uFragColor;\n"
13697 "void main(){\n"
13698 " uFragColor = vec4(0,1,0,1);\n"
13699 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013700
13701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13703
13704 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13705 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13706 pipeline_layout_create_info.setLayoutCount = 1;
13707 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13708
13709 VkPipelineLayout pipeline_layout;
13710 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13711
13712 VkPipelineObj pipe(m_device);
13713 pipe.AddColorAttachment();
13714 pipe.AddShader(&vs);
13715 pipe.AddShader(&fs);
13716
13717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13718 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13719 m_errorMonitor->VerifyFound();
13720
13721 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13722 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13723 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13724}
13725
13726TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13727 TEST_DESCRIPTION(
13728 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13729
13730 ASSERT_NO_FATAL_FAILURE(InitState());
13731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13732
13733 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13734
13735 VkDescriptorPoolSize descriptor_pool_type_count = {};
13736 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13737 descriptor_pool_type_count.descriptorCount = 1;
13738
13739 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13740 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13741 descriptor_pool_create_info.maxSets = 1;
13742 descriptor_pool_create_info.poolSizeCount = 1;
13743 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13744 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13745
13746 VkDescriptorPool descriptorset_pool;
13747 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13748
13749 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13750 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13751 descriptorset_layout_binding.descriptorCount = 1;
13752 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13753 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013754 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013755
13756 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13757 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13758 descriptorset_layout_create_info.bindingCount = 1;
13759 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13760
13761 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013762 ASSERT_VK_SUCCESS(
13763 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013764
13765 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13766 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13767 descriptorset_allocate_info.descriptorSetCount = 1;
13768 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13769 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13770 VkDescriptorSet descriptorset;
13771 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13772
13773 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13774
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013775 char const *vsSource =
13776 "#version 450\n"
13777 "\n"
13778 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13779 " mat4 mvp;\n"
13780 "} ubuf;\n"
13781 "out gl_PerVertex {\n"
13782 " vec4 gl_Position;\n"
13783 "};\n"
13784 "void main(){\n"
13785 " gl_Position = ubuf.mvp * vec4(1);\n"
13786 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013788 char const *fsSource =
13789 "#version 450\n"
13790 "\n"
13791 "layout(location = 0) out vec4 uFragColor;\n"
13792 "void main(){\n"
13793 " uFragColor = vec4(0,1,0,1);\n"
13794 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013795
13796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13798
13799 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13800 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13801 pipeline_layout_create_info.setLayoutCount = 1;
13802 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13803
13804 VkPipelineLayout pipeline_layout;
13805 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13806
13807 VkPipelineObj pipe(m_device);
13808 pipe.AddColorAttachment();
13809 pipe.AddShader(&vs);
13810 pipe.AddShader(&fs);
13811
13812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13813 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13814 m_errorMonitor->VerifyFound();
13815
13816 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13817 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13818 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13819}
13820
13821TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013822 TEST_DESCRIPTION(
13823 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13824 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013825
13826 ASSERT_NO_FATAL_FAILURE(InitState());
13827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13828
13829 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013830 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013831
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013832 char const *vsSource =
13833 "#version 450\n"
13834 "\n"
13835 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13836 "out gl_PerVertex {\n"
13837 " vec4 gl_Position;\n"
13838 "};\n"
13839 "void main(){\n"
13840 " gl_Position = vec4(consts.x);\n"
13841 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013842
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013843 char const *fsSource =
13844 "#version 450\n"
13845 "\n"
13846 "layout(location = 0) out vec4 uFragColor;\n"
13847 "void main(){\n"
13848 " uFragColor = vec4(0,1,0,1);\n"
13849 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013850
13851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13853
13854 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13855 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13856
13857 // Set up a push constant range
13858 VkPushConstantRange push_constant_ranges = {};
13859 // Set to the wrong stage to challenge core_validation
13860 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13861 push_constant_ranges.size = 4;
13862
13863 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13864 pipeline_layout_create_info.pushConstantRangeCount = 1;
13865
13866 VkPipelineLayout pipeline_layout;
13867 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13868
13869 VkPipelineObj pipe(m_device);
13870 pipe.AddColorAttachment();
13871 pipe.AddShader(&vs);
13872 pipe.AddShader(&fs);
13873
13874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13875 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13876 m_errorMonitor->VerifyFound();
13877
13878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13879}
13880
13881TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13882 TEST_DESCRIPTION(
13883 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13884
13885 ASSERT_NO_FATAL_FAILURE(InitState());
13886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13887
13888 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013889 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013890
13891 // Some awkward steps are required to test with custom device features.
13892 std::vector<const char *> device_extension_names;
13893 auto features = m_device->phy().features();
13894 // Disable support for 64 bit floats
13895 features.shaderFloat64 = false;
13896 // The sacrificial device object
13897 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13898
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013899 char const *vsSource =
13900 "#version 450\n"
13901 "\n"
13902 "out gl_PerVertex {\n"
13903 " vec4 gl_Position;\n"
13904 "};\n"
13905 "void main(){\n"
13906 " gl_Position = vec4(1);\n"
13907 "}\n";
13908 char const *fsSource =
13909 "#version 450\n"
13910 "\n"
13911 "layout(location=0) out vec4 color;\n"
13912 "void main(){\n"
13913 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13914 " color = vec4(green);\n"
13915 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013916
13917 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13918 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13919
13920 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013921
13922 VkPipelineObj pipe(&test_device);
13923 pipe.AddColorAttachment();
13924 pipe.AddShader(&vs);
13925 pipe.AddShader(&fs);
13926
13927 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13928 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13929 VkPipelineLayout pipeline_layout;
13930 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13931
13932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13933 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13934 m_errorMonitor->VerifyFound();
13935
13936 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13937}
13938
13939TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13940 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13941
13942 ASSERT_NO_FATAL_FAILURE(InitState());
13943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13944
13945 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13946
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013947 char const *vsSource =
13948 "#version 450\n"
13949 "\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "layout(xfb_buffer = 1) out;"
13954 "void main(){\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource =
13958 "#version 450\n"
13959 "\n"
13960 "layout(location=0) out vec4 color;\n"
13961 "void main(){\n"
13962 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13963 " color = vec4(green);\n"
13964 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013965
13966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13968
13969 VkPipelineObj pipe(m_device);
13970 pipe.AddColorAttachment();
13971 pipe.AddShader(&vs);
13972 pipe.AddShader(&fs);
13973
13974 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13975 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13976 VkPipelineLayout pipeline_layout;
13977 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13978
13979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13980 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13981 m_errorMonitor->VerifyFound();
13982
13983 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13984}
13985
Karl Schultz6addd812016-02-02 17:17:23 -070013986TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013987 TEST_DESCRIPTION(
13988 "Test that an error is produced for a fragment shader input "
13989 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013992
Chris Forbes59cb88d2015-05-25 11:13:13 +120013993 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013996 char const *vsSource =
13997 "#version 450\n"
13998 "\n"
13999 "out gl_PerVertex {\n"
14000 " vec4 gl_Position;\n"
14001 "};\n"
14002 "void main(){\n"
14003 " gl_Position = vec4(1);\n"
14004 "}\n";
14005 char const *fsSource =
14006 "#version 450\n"
14007 "\n"
14008 "layout(location=0) in float x;\n"
14009 "layout(location=0) out vec4 color;\n"
14010 "void main(){\n"
14011 " color = vec4(x);\n"
14012 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014013
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014016
14017 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014018 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014019 pipe.AddShader(&vs);
14020 pipe.AddShader(&fs);
14021
Chris Forbes59cb88d2015-05-25 11:13:13 +120014022 VkDescriptorSetObj descriptorSet(m_device);
14023 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014025
Tony Barbour5781e8f2015-08-04 16:23:11 -060014026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014027
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014028 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014029}
14030
Karl Schultz6addd812016-02-02 17:17:23 -070014031TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014032 TEST_DESCRIPTION(
14033 "Test that an error is produced for a fragment shader input "
14034 "within an interace block, which is not present in the outputs "
14035 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014037
14038 ASSERT_NO_FATAL_FAILURE(InitState());
14039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14040
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014041 char const *vsSource =
14042 "#version 450\n"
14043 "\n"
14044 "out gl_PerVertex {\n"
14045 " vec4 gl_Position;\n"
14046 "};\n"
14047 "void main(){\n"
14048 " gl_Position = vec4(1);\n"
14049 "}\n";
14050 char const *fsSource =
14051 "#version 450\n"
14052 "\n"
14053 "in block { layout(location=0) float x; } ins;\n"
14054 "layout(location=0) out vec4 color;\n"
14055 "void main(){\n"
14056 " color = vec4(ins.x);\n"
14057 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014058
14059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14061
14062 VkPipelineObj pipe(m_device);
14063 pipe.AddColorAttachment();
14064 pipe.AddShader(&vs);
14065 pipe.AddShader(&fs);
14066
14067 VkDescriptorSetObj descriptorSet(m_device);
14068 descriptorSet.AppendDummy();
14069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14070
14071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014073 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014074}
14075
Karl Schultz6addd812016-02-02 17:17:23 -070014076TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014077 TEST_DESCRIPTION(
14078 "Test that an error is produced for mismatched array sizes "
14079 "across the vertex->fragment shader interface");
14080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14081 "Type mismatch on location 0.0: 'ptr to "
14082 "output arr[2] of float32' vs 'ptr to "
14083 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014084
14085 ASSERT_NO_FATAL_FAILURE(InitState());
14086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14087
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014088 char const *vsSource =
14089 "#version 450\n"
14090 "\n"
14091 "layout(location=0) out float x[2];\n"
14092 "out gl_PerVertex {\n"
14093 " vec4 gl_Position;\n"
14094 "};\n"
14095 "void main(){\n"
14096 " x[0] = 0; x[1] = 0;\n"
14097 " gl_Position = vec4(1);\n"
14098 "}\n";
14099 char const *fsSource =
14100 "#version 450\n"
14101 "\n"
14102 "layout(location=0) in float x[1];\n"
14103 "layout(location=0) out vec4 color;\n"
14104 "void main(){\n"
14105 " color = vec4(x[0]);\n"
14106 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014107
14108 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14109 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14110
14111 VkPipelineObj pipe(m_device);
14112 pipe.AddColorAttachment();
14113 pipe.AddShader(&vs);
14114 pipe.AddShader(&fs);
14115
14116 VkDescriptorSetObj descriptorSet(m_device);
14117 descriptorSet.AppendDummy();
14118 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14119
14120 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14121
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014122 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014123}
14124
Karl Schultz6addd812016-02-02 17:17:23 -070014125TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014126 TEST_DESCRIPTION(
14127 "Test that an error is produced for mismatched types across "
14128 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014130
Chris Forbesb56af562015-05-25 11:13:17 +120014131 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "layout(location=0) out int x;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " x = 0;\n"
14143 " gl_Position = vec4(1);\n"
14144 "}\n";
14145 char const *fsSource =
14146 "#version 450\n"
14147 "\n"
14148 "layout(location=0) in float x;\n" /* VS writes int */
14149 "layout(location=0) out vec4 color;\n"
14150 "void main(){\n"
14151 " color = vec4(x);\n"
14152 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014153
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014156
14157 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014158 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
Chris Forbesb56af562015-05-25 11:13:17 +120014162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014165
Tony Barbour5781e8f2015-08-04 16:23:11 -060014166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014169}
14170
Karl Schultz6addd812016-02-02 17:17:23 -070014171TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014172 TEST_DESCRIPTION(
14173 "Test that an error is produced for mismatched types across "
14174 "the vertex->fragment shader interface, when the variable is contained within "
14175 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014177
14178 ASSERT_NO_FATAL_FAILURE(InitState());
14179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014181 char const *vsSource =
14182 "#version 450\n"
14183 "\n"
14184 "out block { layout(location=0) int x; } outs;\n"
14185 "out gl_PerVertex {\n"
14186 " vec4 gl_Position;\n"
14187 "};\n"
14188 "void main(){\n"
14189 " outs.x = 0;\n"
14190 " gl_Position = vec4(1);\n"
14191 "}\n";
14192 char const *fsSource =
14193 "#version 450\n"
14194 "\n"
14195 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14196 "layout(location=0) out vec4 color;\n"
14197 "void main(){\n"
14198 " color = vec4(ins.x);\n"
14199 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014200
14201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14203
14204 VkPipelineObj pipe(m_device);
14205 pipe.AddColorAttachment();
14206 pipe.AddShader(&vs);
14207 pipe.AddShader(&fs);
14208
14209 VkDescriptorSetObj descriptorSet(m_device);
14210 descriptorSet.AppendDummy();
14211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14212
14213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014215 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014216}
14217
14218TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014219 TEST_DESCRIPTION(
14220 "Test that an error is produced for location mismatches across "
14221 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14222 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130014224
14225 ASSERT_NO_FATAL_FAILURE(InitState());
14226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014228 char const *vsSource =
14229 "#version 450\n"
14230 "\n"
14231 "out block { layout(location=1) float x; } outs;\n"
14232 "out gl_PerVertex {\n"
14233 " vec4 gl_Position;\n"
14234 "};\n"
14235 "void main(){\n"
14236 " outs.x = 0;\n"
14237 " gl_Position = vec4(1);\n"
14238 "}\n";
14239 char const *fsSource =
14240 "#version 450\n"
14241 "\n"
14242 "in block { layout(location=0) float x; } ins;\n"
14243 "layout(location=0) out vec4 color;\n"
14244 "void main(){\n"
14245 " color = vec4(ins.x);\n"
14246 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014247
14248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14250
14251 VkPipelineObj pipe(m_device);
14252 pipe.AddColorAttachment();
14253 pipe.AddShader(&vs);
14254 pipe.AddShader(&fs);
14255
14256 VkDescriptorSetObj descriptorSet(m_device);
14257 descriptorSet.AppendDummy();
14258 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14259
14260 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014262 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014263}
14264
14265TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014266 TEST_DESCRIPTION(
14267 "Test that an error is produced for component mismatches across the "
14268 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14269 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130014271
14272 ASSERT_NO_FATAL_FAILURE(InitState());
14273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14274
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014275 char const *vsSource =
14276 "#version 450\n"
14277 "\n"
14278 "out block { layout(location=0, component=0) float x; } outs;\n"
14279 "out gl_PerVertex {\n"
14280 " vec4 gl_Position;\n"
14281 "};\n"
14282 "void main(){\n"
14283 " outs.x = 0;\n"
14284 " gl_Position = vec4(1);\n"
14285 "}\n";
14286 char const *fsSource =
14287 "#version 450\n"
14288 "\n"
14289 "in block { layout(location=0, component=1) float x; } ins;\n"
14290 "layout(location=0) out vec4 color;\n"
14291 "void main(){\n"
14292 " color = vec4(ins.x);\n"
14293 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014294
14295 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14296 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14297
14298 VkPipelineObj pipe(m_device);
14299 pipe.AddColorAttachment();
14300 pipe.AddShader(&vs);
14301 pipe.AddShader(&fs);
14302
14303 VkDescriptorSetObj descriptorSet(m_device);
14304 descriptorSet.AppendDummy();
14305 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14306
14307 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014309 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014310}
14311
Chris Forbes1f3b0152016-11-30 12:48:40 +130014312TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14313 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14314
14315 ASSERT_NO_FATAL_FAILURE(InitState());
14316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14317
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014318 char const *vsSource =
14319 "#version 450\n"
14320 "layout(location=0) out mediump float x;\n"
14321 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14322 char const *fsSource =
14323 "#version 450\n"
14324 "layout(location=0) in highp float x;\n"
14325 "layout(location=0) out vec4 color;\n"
14326 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014327
14328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14330
14331 VkPipelineObj pipe(m_device);
14332 pipe.AddColorAttachment();
14333 pipe.AddShader(&vs);
14334 pipe.AddShader(&fs);
14335
14336 VkDescriptorSetObj descriptorSet(m_device);
14337 descriptorSet.AppendDummy();
14338 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14339
14340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14341
14342 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14343
14344 m_errorMonitor->VerifyFound();
14345}
14346
Chris Forbes870a39e2016-11-30 12:55:56 +130014347TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14348 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
14351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014353 char const *vsSource =
14354 "#version 450\n"
14355 "out block { layout(location=0) mediump float x; };\n"
14356 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14357 char const *fsSource =
14358 "#version 450\n"
14359 "in block { layout(location=0) highp float x; };\n"
14360 "layout(location=0) out vec4 color;\n"
14361 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014362
14363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14365
14366 VkPipelineObj pipe(m_device);
14367 pipe.AddColorAttachment();
14368 pipe.AddShader(&vs);
14369 pipe.AddShader(&fs);
14370
14371 VkDescriptorSetObj descriptorSet(m_device);
14372 descriptorSet.AppendDummy();
14373 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14374
14375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14376
14377 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14378
14379 m_errorMonitor->VerifyFound();
14380}
14381
Karl Schultz6addd812016-02-02 17:17:23 -070014382TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014383 TEST_DESCRIPTION(
14384 "Test that a warning is produced for a vertex attribute which is "
14385 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014387
Chris Forbesde136e02015-05-25 11:13:28 +120014388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014390
14391 VkVertexInputBindingDescription input_binding;
14392 memset(&input_binding, 0, sizeof(input_binding));
14393
14394 VkVertexInputAttributeDescription input_attrib;
14395 memset(&input_attrib, 0, sizeof(input_attrib));
14396 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14397
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014398 char const *vsSource =
14399 "#version 450\n"
14400 "\n"
14401 "out gl_PerVertex {\n"
14402 " vec4 gl_Position;\n"
14403 "};\n"
14404 "void main(){\n"
14405 " gl_Position = vec4(1);\n"
14406 "}\n";
14407 char const *fsSource =
14408 "#version 450\n"
14409 "\n"
14410 "layout(location=0) out vec4 color;\n"
14411 "void main(){\n"
14412 " color = vec4(1);\n"
14413 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014414
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014415 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14416 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014417
14418 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014419 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014420 pipe.AddShader(&vs);
14421 pipe.AddShader(&fs);
14422
14423 pipe.AddVertexInputBindings(&input_binding, 1);
14424 pipe.AddVertexInputAttribs(&input_attrib, 1);
14425
Chris Forbesde136e02015-05-25 11:13:28 +120014426 VkDescriptorSetObj descriptorSet(m_device);
14427 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014429
Tony Barbour5781e8f2015-08-04 16:23:11 -060014430 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014431
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014432 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014433}
14434
Karl Schultz6addd812016-02-02 17:17:23 -070014435TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014436 TEST_DESCRIPTION(
14437 "Test that a warning is produced for a location mismatch on "
14438 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014440
14441 ASSERT_NO_FATAL_FAILURE(InitState());
14442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14443
14444 VkVertexInputBindingDescription input_binding;
14445 memset(&input_binding, 0, sizeof(input_binding));
14446
14447 VkVertexInputAttributeDescription input_attrib;
14448 memset(&input_attrib, 0, sizeof(input_attrib));
14449 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14450
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014451 char const *vsSource =
14452 "#version 450\n"
14453 "\n"
14454 "layout(location=1) in float x;\n"
14455 "out gl_PerVertex {\n"
14456 " vec4 gl_Position;\n"
14457 "};\n"
14458 "void main(){\n"
14459 " gl_Position = vec4(x);\n"
14460 "}\n";
14461 char const *fsSource =
14462 "#version 450\n"
14463 "\n"
14464 "layout(location=0) out vec4 color;\n"
14465 "void main(){\n"
14466 " color = vec4(1);\n"
14467 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014468
14469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14471
14472 VkPipelineObj pipe(m_device);
14473 pipe.AddColorAttachment();
14474 pipe.AddShader(&vs);
14475 pipe.AddShader(&fs);
14476
14477 pipe.AddVertexInputBindings(&input_binding, 1);
14478 pipe.AddVertexInputAttribs(&input_attrib, 1);
14479
14480 VkDescriptorSetObj descriptorSet(m_device);
14481 descriptorSet.AppendDummy();
14482 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14483
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014484 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014485 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14486
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014487 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014488}
14489
Karl Schultz6addd812016-02-02 17:17:23 -070014490TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014491 TEST_DESCRIPTION(
14492 "Test that an error is produced for a vertex shader input which is not "
14493 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14495 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014496
Chris Forbes62e8e502015-05-25 11:13:29 +120014497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 char const *vsSource =
14501 "#version 450\n"
14502 "\n"
14503 "layout(location=0) in vec4 x;\n" /* not provided */
14504 "out gl_PerVertex {\n"
14505 " vec4 gl_Position;\n"
14506 "};\n"
14507 "void main(){\n"
14508 " gl_Position = x;\n"
14509 "}\n";
14510 char const *fsSource =
14511 "#version 450\n"
14512 "\n"
14513 "layout(location=0) out vec4 color;\n"
14514 "void main(){\n"
14515 " color = vec4(1);\n"
14516 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014517
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014520
14521 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014522 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014523 pipe.AddShader(&vs);
14524 pipe.AddShader(&fs);
14525
Chris Forbes62e8e502015-05-25 11:13:29 +120014526 VkDescriptorSetObj descriptorSet(m_device);
14527 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014529
Tony Barbour5781e8f2015-08-04 16:23:11 -060014530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014531
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014532 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014533}
14534
Karl Schultz6addd812016-02-02 17:17:23 -070014535TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014536 TEST_DESCRIPTION(
14537 "Test that an error is produced for a mismatch between the "
14538 "fundamental type (float/int/uint) of an attribute and the "
14539 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match vertex shader input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014541
Chris Forbesc97d98e2015-05-25 11:13:31 +120014542 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014544
14545 VkVertexInputBindingDescription input_binding;
14546 memset(&input_binding, 0, sizeof(input_binding));
14547
14548 VkVertexInputAttributeDescription input_attrib;
14549 memset(&input_attrib, 0, sizeof(input_attrib));
14550 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14551
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014552 char const *vsSource =
14553 "#version 450\n"
14554 "\n"
14555 "layout(location=0) in int x;\n" /* attrib provided float */
14556 "out gl_PerVertex {\n"
14557 " vec4 gl_Position;\n"
14558 "};\n"
14559 "void main(){\n"
14560 " gl_Position = vec4(x);\n"
14561 "}\n";
14562 char const *fsSource =
14563 "#version 450\n"
14564 "\n"
14565 "layout(location=0) out vec4 color;\n"
14566 "void main(){\n"
14567 " color = vec4(1);\n"
14568 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014569
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014572
14573 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014574 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014575 pipe.AddShader(&vs);
14576 pipe.AddShader(&fs);
14577
14578 pipe.AddVertexInputBindings(&input_binding, 1);
14579 pipe.AddVertexInputAttribs(&input_attrib, 1);
14580
Chris Forbesc97d98e2015-05-25 11:13:31 +120014581 VkDescriptorSetObj descriptorSet(m_device);
14582 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014583 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014584
Tony Barbour5781e8f2015-08-04 16:23:11 -060014585 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014586
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014587 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014588}
14589
Chris Forbesc68b43c2016-04-06 11:18:47 +120014590TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014591 TEST_DESCRIPTION(
14592 "Test that an error is produced for a pipeline containing multiple "
14593 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14595 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014596
14597 ASSERT_NO_FATAL_FAILURE(InitState());
14598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14599
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014600 char const *vsSource =
14601 "#version 450\n"
14602 "\n"
14603 "out gl_PerVertex {\n"
14604 " vec4 gl_Position;\n"
14605 "};\n"
14606 "void main(){\n"
14607 " gl_Position = vec4(1);\n"
14608 "}\n";
14609 char const *fsSource =
14610 "#version 450\n"
14611 "\n"
14612 "layout(location=0) out vec4 color;\n"
14613 "void main(){\n"
14614 " color = vec4(1);\n"
14615 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014616
14617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14619
14620 VkPipelineObj pipe(m_device);
14621 pipe.AddColorAttachment();
14622 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014623 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014624 pipe.AddShader(&fs);
14625
14626 VkDescriptorSetObj descriptorSet(m_device);
14627 descriptorSet.AppendDummy();
14628 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14629
14630 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14631
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014632 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014633}
14634
Chris Forbes82ff92a2016-09-09 10:50:24 +120014635TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014637
14638 ASSERT_NO_FATAL_FAILURE(InitState());
14639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14640
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014641 char const *vsSource =
14642 "#version 450\n"
14643 "out gl_PerVertex {\n"
14644 " vec4 gl_Position;\n"
14645 "};\n"
14646 "void main(){\n"
14647 " gl_Position = vec4(0);\n"
14648 "}\n";
14649 char const *fsSource =
14650 "#version 450\n"
14651 "\n"
14652 "layout(location=0) out vec4 color;\n"
14653 "void main(){\n"
14654 " color = vec4(1);\n"
14655 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014656
14657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14659
14660 VkPipelineObj pipe(m_device);
14661 pipe.AddColorAttachment();
14662 pipe.AddShader(&vs);
14663 pipe.AddShader(&fs);
14664
14665 VkDescriptorSetObj descriptorSet(m_device);
14666 descriptorSet.AppendDummy();
14667 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14668
14669 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14670
14671 m_errorMonitor->VerifyFound();
14672}
14673
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014674TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14676 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14677 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014678
14679 ASSERT_NO_FATAL_FAILURE(InitState());
14680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14681
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014682 char const *vsSource =
14683 "#version 450\n"
14684 "void main(){ gl_Position = vec4(0); }\n";
14685 char const *fsSource =
14686 "#version 450\n"
14687 "\n"
14688 "layout(location=0) out vec4 color;\n"
14689 "void main(){\n"
14690 " color = vec4(1);\n"
14691 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014692
14693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14695
14696 VkPipelineObj pipe(m_device);
14697 pipe.AddColorAttachment();
14698 pipe.AddShader(&vs);
14699 pipe.AddShader(&fs);
14700
14701 VkDescriptorSetObj descriptorSet(m_device);
14702 descriptorSet.AppendDummy();
14703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14704
14705 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014706 {
14707 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14708 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14709 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014710 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014711 {
14712 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14714 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014715 },
14716 };
14717 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014718 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014719 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014720 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14721 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014722 VkRenderPass rp;
14723 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14724 ASSERT_VK_SUCCESS(err);
14725
14726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14727
14728 m_errorMonitor->VerifyFound();
14729
14730 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14731}
14732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014734 TEST_DESCRIPTION(
14735 "Test that an error is produced for a variable output from "
14736 "the TCS without the patch decoration, but consumed in the TES "
14737 "with the decoration.");
14738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14739 "is per-vertex in tessellation control shader stage "
14740 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014741
14742 ASSERT_NO_FATAL_FAILURE(InitState());
14743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14744
Chris Forbesc1e852d2016-04-04 19:26:42 +120014745 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014746 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014747 return;
14748 }
14749
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014750 char const *vsSource =
14751 "#version 450\n"
14752 "void main(){}\n";
14753 char const *tcsSource =
14754 "#version 450\n"
14755 "layout(location=0) out int x[];\n"
14756 "layout(vertices=3) out;\n"
14757 "void main(){\n"
14758 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14759 " gl_TessLevelInner[0] = 1;\n"
14760 " x[gl_InvocationID] = gl_InvocationID;\n"
14761 "}\n";
14762 char const *tesSource =
14763 "#version 450\n"
14764 "layout(triangles, equal_spacing, cw) in;\n"
14765 "layout(location=0) patch in int x;\n"
14766 "out gl_PerVertex { vec4 gl_Position; };\n"
14767 "void main(){\n"
14768 " gl_Position.xyz = gl_TessCoord;\n"
14769 " gl_Position.w = x;\n"
14770 "}\n";
14771 char const *fsSource =
14772 "#version 450\n"
14773 "layout(location=0) out vec4 color;\n"
14774 "void main(){\n"
14775 " color = vec4(1);\n"
14776 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014777
14778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14779 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14780 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014783 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14784 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014786 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014787
14788 VkPipelineObj pipe(m_device);
14789 pipe.SetInputAssembly(&iasci);
14790 pipe.SetTessellation(&tsci);
14791 pipe.AddColorAttachment();
14792 pipe.AddShader(&vs);
14793 pipe.AddShader(&tcs);
14794 pipe.AddShader(&tes);
14795 pipe.AddShader(&fs);
14796
14797 VkDescriptorSetObj descriptorSet(m_device);
14798 descriptorSet.AppendDummy();
14799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14800
14801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14802
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014803 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014804}
14805
Karl Schultz6addd812016-02-02 17:17:23 -070014806TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014807 TEST_DESCRIPTION(
14808 "Test that an error is produced for a vertex attribute setup where multiple "
14809 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14811 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014812
Chris Forbes280ba2c2015-06-12 11:16:41 +120014813 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014815
14816 /* Two binding descriptions for binding 0 */
14817 VkVertexInputBindingDescription input_bindings[2];
14818 memset(input_bindings, 0, sizeof(input_bindings));
14819
14820 VkVertexInputAttributeDescription input_attrib;
14821 memset(&input_attrib, 0, sizeof(input_attrib));
14822 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014824 char const *vsSource =
14825 "#version 450\n"
14826 "\n"
14827 "layout(location=0) in float x;\n" /* attrib provided float */
14828 "out gl_PerVertex {\n"
14829 " vec4 gl_Position;\n"
14830 "};\n"
14831 "void main(){\n"
14832 " gl_Position = vec4(x);\n"
14833 "}\n";
14834 char const *fsSource =
14835 "#version 450\n"
14836 "\n"
14837 "layout(location=0) out vec4 color;\n"
14838 "void main(){\n"
14839 " color = vec4(1);\n"
14840 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014841
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014844
14845 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014846 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014847 pipe.AddShader(&vs);
14848 pipe.AddShader(&fs);
14849
14850 pipe.AddVertexInputBindings(input_bindings, 2);
14851 pipe.AddVertexInputAttribs(&input_attrib, 1);
14852
Chris Forbes280ba2c2015-06-12 11:16:41 +120014853 VkDescriptorSetObj descriptorSet(m_device);
14854 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014855 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014856
Tony Barbour5781e8f2015-08-04 16:23:11 -060014857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014859 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014860}
Chris Forbes8f68b562015-05-25 11:13:32 +120014861
Karl Schultz6addd812016-02-02 17:17:23 -070014862TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014863 TEST_DESCRIPTION(
14864 "Test that an error is produced for a fragment shader which does not "
14865 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014867
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014868 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014869
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014870 char const *vsSource =
14871 "#version 450\n"
14872 "\n"
14873 "out gl_PerVertex {\n"
14874 " vec4 gl_Position;\n"
14875 "};\n"
14876 "void main(){\n"
14877 " gl_Position = vec4(1);\n"
14878 "}\n";
14879 char const *fsSource =
14880 "#version 450\n"
14881 "\n"
14882 "void main(){\n"
14883 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014884
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014887
14888 VkPipelineObj pipe(m_device);
14889 pipe.AddShader(&vs);
14890 pipe.AddShader(&fs);
14891
Chia-I Wu08accc62015-07-07 11:50:03 +080014892 /* set up CB 0, not written */
14893 pipe.AddColorAttachment();
14894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014895
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014896 VkDescriptorSetObj descriptorSet(m_device);
14897 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014899
Tony Barbour5781e8f2015-08-04 16:23:11 -060014900 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014902 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014903}
14904
Karl Schultz6addd812016-02-02 17:17:23 -070014905TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014906 TEST_DESCRIPTION(
14907 "Test that a warning is produced for a fragment shader which provides a spurious "
14908 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014910 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014911
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014912 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014913
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014914 char const *vsSource =
14915 "#version 450\n"
14916 "\n"
14917 "out gl_PerVertex {\n"
14918 " vec4 gl_Position;\n"
14919 "};\n"
14920 "void main(){\n"
14921 " gl_Position = vec4(1);\n"
14922 "}\n";
14923 char const *fsSource =
14924 "#version 450\n"
14925 "\n"
14926 "layout(location=0) out vec4 x;\n"
14927 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14928 "void main(){\n"
14929 " x = vec4(1);\n"
14930 " y = vec4(1);\n"
14931 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014932
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014935
14936 VkPipelineObj pipe(m_device);
14937 pipe.AddShader(&vs);
14938 pipe.AddShader(&fs);
14939
Chia-I Wu08accc62015-07-07 11:50:03 +080014940 /* set up CB 0, not written */
14941 pipe.AddColorAttachment();
14942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014943 /* FS writes CB 1, but we don't configure it */
14944
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014945 VkDescriptorSetObj descriptorSet(m_device);
14946 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014948
Tony Barbour5781e8f2015-08-04 16:23:11 -060014949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014951 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014952}
14953
Karl Schultz6addd812016-02-02 17:17:23 -070014954TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014955 TEST_DESCRIPTION(
14956 "Test that an error is produced for a mismatch between the fundamental "
14957 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014959
Chris Forbesa36d69e2015-05-25 11:13:44 +120014960 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014961
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014962 char const *vsSource =
14963 "#version 450\n"
14964 "\n"
14965 "out gl_PerVertex {\n"
14966 " vec4 gl_Position;\n"
14967 "};\n"
14968 "void main(){\n"
14969 " gl_Position = vec4(1);\n"
14970 "}\n";
14971 char const *fsSource =
14972 "#version 450\n"
14973 "\n"
14974 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14975 "void main(){\n"
14976 " x = ivec4(1);\n"
14977 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014978
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014981
14982 VkPipelineObj pipe(m_device);
14983 pipe.AddShader(&vs);
14984 pipe.AddShader(&fs);
14985
Chia-I Wu08accc62015-07-07 11:50:03 +080014986 /* set up CB 0; type is UNORM by default */
14987 pipe.AddColorAttachment();
14988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014989
Chris Forbesa36d69e2015-05-25 11:13:44 +120014990 VkDescriptorSetObj descriptorSet(m_device);
14991 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014993
Tony Barbour5781e8f2015-08-04 16:23:11 -060014994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014995
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014996 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014997}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014998
Karl Schultz6addd812016-02-02 17:17:23 -070014999TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015000 TEST_DESCRIPTION(
15001 "Test that an error is produced for a shader consuming a uniform "
15002 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015004
Chris Forbes556c76c2015-08-14 12:04:59 +120015005 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015006
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015007 char const *vsSource =
15008 "#version 450\n"
15009 "\n"
15010 "out gl_PerVertex {\n"
15011 " vec4 gl_Position;\n"
15012 "};\n"
15013 "void main(){\n"
15014 " gl_Position = vec4(1);\n"
15015 "}\n";
15016 char const *fsSource =
15017 "#version 450\n"
15018 "\n"
15019 "layout(location=0) out vec4 x;\n"
15020 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15021 "void main(){\n"
15022 " x = vec4(bar.y);\n"
15023 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015024
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015027
Chris Forbes556c76c2015-08-14 12:04:59 +120015028 VkPipelineObj pipe(m_device);
15029 pipe.AddShader(&vs);
15030 pipe.AddShader(&fs);
15031
15032 /* set up CB 0; type is UNORM by default */
15033 pipe.AddColorAttachment();
15034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15035
15036 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015038
15039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015041 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015042}
15043
Chris Forbes5c59e902016-02-26 16:56:09 +130015044TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015045 TEST_DESCRIPTION(
15046 "Test that an error is produced for a shader consuming push constants "
15047 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015049
15050 ASSERT_NO_FATAL_FAILURE(InitState());
15051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015052 char const *vsSource =
15053 "#version 450\n"
15054 "\n"
15055 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15056 "out gl_PerVertex {\n"
15057 " vec4 gl_Position;\n"
15058 "};\n"
15059 "void main(){\n"
15060 " gl_Position = vec4(consts.x);\n"
15061 "}\n";
15062 char const *fsSource =
15063 "#version 450\n"
15064 "\n"
15065 "layout(location=0) out vec4 x;\n"
15066 "void main(){\n"
15067 " x = vec4(1);\n"
15068 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015069
15070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15072
15073 VkPipelineObj pipe(m_device);
15074 pipe.AddShader(&vs);
15075 pipe.AddShader(&fs);
15076
15077 /* set up CB 0; type is UNORM by default */
15078 pipe.AddColorAttachment();
15079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15080
15081 VkDescriptorSetObj descriptorSet(m_device);
15082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15083
15084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15085
15086 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015087 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015088}
15089
Chris Forbes3fb17902016-08-22 14:57:55 +120015090TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015091 TEST_DESCRIPTION(
15092 "Test that an error is produced for a shader consuming an input attachment "
15093 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15095 "consumes input attachment index 0 but not provided in subpass");
15096
15097 ASSERT_NO_FATAL_FAILURE(InitState());
15098
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015099 char const *vsSource =
15100 "#version 450\n"
15101 "\n"
15102 "out gl_PerVertex {\n"
15103 " vec4 gl_Position;\n"
15104 "};\n"
15105 "void main(){\n"
15106 " gl_Position = vec4(1);\n"
15107 "}\n";
15108 char const *fsSource =
15109 "#version 450\n"
15110 "\n"
15111 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15112 "layout(location=0) out vec4 color;\n"
15113 "void main() {\n"
15114 " color = subpassLoad(x);\n"
15115 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015116
15117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15119
15120 VkPipelineObj pipe(m_device);
15121 pipe.AddShader(&vs);
15122 pipe.AddShader(&fs);
15123 pipe.AddColorAttachment();
15124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015126 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15127 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015128 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015130 ASSERT_VK_SUCCESS(err);
15131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015133 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015135 ASSERT_VK_SUCCESS(err);
15136
15137 // error here.
15138 pipe.CreateVKPipeline(pl, renderPass());
15139
15140 m_errorMonitor->VerifyFound();
15141
15142 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15143 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15144}
15145
Chris Forbes5a9a0472016-08-22 16:02:09 +120015146TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015147 TEST_DESCRIPTION(
15148 "Test that an error is produced for a shader consuming an input attachment "
15149 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15151 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15152
15153 ASSERT_NO_FATAL_FAILURE(InitState());
15154
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015155 char const *vsSource =
15156 "#version 450\n"
15157 "\n"
15158 "out gl_PerVertex {\n"
15159 " vec4 gl_Position;\n"
15160 "};\n"
15161 "void main(){\n"
15162 " gl_Position = vec4(1);\n"
15163 "}\n";
15164 char const *fsSource =
15165 "#version 450\n"
15166 "\n"
15167 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15168 "layout(location=0) out vec4 color;\n"
15169 "void main() {\n"
15170 " color = subpassLoad(x);\n"
15171 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015172
15173 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15174 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15175
15176 VkPipelineObj pipe(m_device);
15177 pipe.AddShader(&vs);
15178 pipe.AddShader(&fs);
15179 pipe.AddColorAttachment();
15180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15183 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015184 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015186 ASSERT_VK_SUCCESS(err);
15187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015188 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015189 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015191 ASSERT_VK_SUCCESS(err);
15192
15193 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15195 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15196 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15197 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15198 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120015199 };
15200 VkAttachmentReference color = {
15201 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15202 };
15203 VkAttachmentReference input = {
15204 1, VK_IMAGE_LAYOUT_GENERAL,
15205 };
15206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015210 VkRenderPass rp;
15211 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15212 ASSERT_VK_SUCCESS(err);
15213
15214 // error here.
15215 pipe.CreateVKPipeline(pl, rp);
15216
15217 m_errorMonitor->VerifyFound();
15218
15219 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15220 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15221 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15222}
15223
Chris Forbes541f7b02016-08-22 15:30:27 +120015224TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015225 TEST_DESCRIPTION(
15226 "Test that an error is produced for a shader consuming an input attachment "
15227 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015229 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015230
15231 ASSERT_NO_FATAL_FAILURE(InitState());
15232
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015233 char const *vsSource =
15234 "#version 450\n"
15235 "\n"
15236 "out gl_PerVertex {\n"
15237 " vec4 gl_Position;\n"
15238 "};\n"
15239 "void main(){\n"
15240 " gl_Position = vec4(1);\n"
15241 "}\n";
15242 char const *fsSource =
15243 "#version 450\n"
15244 "\n"
15245 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15246 "layout(location=0) out vec4 color;\n"
15247 "void main() {\n"
15248 " color = subpassLoad(xs[0]);\n"
15249 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015250
15251 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15252 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15253
15254 VkPipelineObj pipe(m_device);
15255 pipe.AddShader(&vs);
15256 pipe.AddShader(&fs);
15257 pipe.AddColorAttachment();
15258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15261 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015262 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015264 ASSERT_VK_SUCCESS(err);
15265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015266 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015267 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015269 ASSERT_VK_SUCCESS(err);
15270
15271 // error here.
15272 pipe.CreateVKPipeline(pl, renderPass());
15273
15274 m_errorMonitor->VerifyFound();
15275
15276 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15277 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15278}
15279
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015280TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015281 TEST_DESCRIPTION(
15282 "Test that an error is produced for a compute pipeline consuming a "
15283 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015285
15286 ASSERT_NO_FATAL_FAILURE(InitState());
15287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015288 char const *csSource =
15289 "#version 450\n"
15290 "\n"
15291 "layout(local_size_x=1) in;\n"
15292 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15293 "void main(){\n"
15294 " x = vec4(1);\n"
15295 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015296
15297 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15298
15299 VkDescriptorSetObj descriptorSet(m_device);
15300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015302 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15303 nullptr,
15304 0,
15305 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15306 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15307 descriptorSet.GetPipelineLayout(),
15308 VK_NULL_HANDLE,
15309 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015310
15311 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015312 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015313
15314 m_errorMonitor->VerifyFound();
15315
15316 if (err == VK_SUCCESS) {
15317 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15318 }
15319}
15320
Chris Forbes22a9b092016-07-19 14:34:05 +120015321TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015322 TEST_DESCRIPTION(
15323 "Test that an error is produced for a pipeline consuming a "
15324 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15326 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015327
15328 ASSERT_NO_FATAL_FAILURE(InitState());
15329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015330 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15331 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015332 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015333 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015334 ASSERT_VK_SUCCESS(err);
15335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015337 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015339 ASSERT_VK_SUCCESS(err);
15340
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015341 char const *csSource =
15342 "#version 450\n"
15343 "\n"
15344 "layout(local_size_x=1) in;\n"
15345 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15346 "void main() {\n"
15347 " x.x = 1.0f;\n"
15348 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015349 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15352 nullptr,
15353 0,
15354 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15355 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15356 pl,
15357 VK_NULL_HANDLE,
15358 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015359
15360 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015361 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015362
15363 m_errorMonitor->VerifyFound();
15364
15365 if (err == VK_SUCCESS) {
15366 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15367 }
15368
15369 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15370 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15371}
15372
Chris Forbes50020592016-07-27 13:52:41 +120015373TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015374 TEST_DESCRIPTION(
15375 "Test that an error is produced when an image view type "
15376 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires an image view of type VK_IMAGE_VIEW_TYPE_3D");
Chris Forbes50020592016-07-27 13:52:41 +120015379
15380 ASSERT_NO_FATAL_FAILURE(InitState());
15381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15382
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015383 char const *vsSource =
15384 "#version 450\n"
15385 "\n"
15386 "out gl_PerVertex { vec4 gl_Position; };\n"
15387 "void main() { gl_Position = vec4(0); }\n";
15388 char const *fsSource =
15389 "#version 450\n"
15390 "\n"
15391 "layout(set=0, binding=0) uniform sampler3D s;\n"
15392 "layout(location=0) out vec4 color;\n"
15393 "void main() {\n"
15394 " color = texture(s, vec3(0));\n"
15395 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15398
15399 VkPipelineObj pipe(m_device);
15400 pipe.AddShader(&vs);
15401 pipe.AddShader(&fs);
15402 pipe.AddColorAttachment();
15403
15404 VkTextureObj texture(m_device, nullptr);
15405 VkSamplerObj sampler(m_device);
15406
15407 VkDescriptorSetObj descriptorSet(m_device);
15408 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15409 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15410
15411 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15412 ASSERT_VK_SUCCESS(err);
15413
Tony Barbour552f6c02016-12-21 14:34:07 -070015414 m_commandBuffer->BeginCommandBuffer();
15415 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015416
15417 m_commandBuffer->BindPipeline(pipe);
15418 m_commandBuffer->BindDescriptorSet(descriptorSet);
15419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015420 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015421 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015422 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015423 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15424
15425 // error produced here.
15426 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15427
15428 m_errorMonitor->VerifyFound();
15429
Tony Barbour552f6c02016-12-21 14:34:07 -070015430 m_commandBuffer->EndRenderPass();
15431 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015432}
15433
Chris Forbes5533bfc2016-07-27 14:12:34 +120015434TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015435 TEST_DESCRIPTION(
15436 "Test that an error is produced when a multisampled images "
15437 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15443
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015444 char const *vsSource =
15445 "#version 450\n"
15446 "\n"
15447 "out gl_PerVertex { vec4 gl_Position; };\n"
15448 "void main() { gl_Position = vec4(0); }\n";
15449 char const *fsSource =
15450 "#version 450\n"
15451 "\n"
15452 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15453 "layout(location=0) out vec4 color;\n"
15454 "void main() {\n"
15455 " color = texelFetch(s, ivec2(0), 0);\n"
15456 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15459
15460 VkPipelineObj pipe(m_device);
15461 pipe.AddShader(&vs);
15462 pipe.AddShader(&fs);
15463 pipe.AddColorAttachment();
15464
15465 VkTextureObj texture(m_device, nullptr);
15466 VkSamplerObj sampler(m_device);
15467
15468 VkDescriptorSetObj descriptorSet(m_device);
15469 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15470 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15471
15472 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15473 ASSERT_VK_SUCCESS(err);
15474
Tony Barbour552f6c02016-12-21 14:34:07 -070015475 m_commandBuffer->BeginCommandBuffer();
15476 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015477
15478 m_commandBuffer->BindPipeline(pipe);
15479 m_commandBuffer->BindDescriptorSet(descriptorSet);
15480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015482 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015484 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15485
15486 // error produced here.
15487 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15488
15489 m_errorMonitor->VerifyFound();
15490
Tony Barbour552f6c02016-12-21 14:34:07 -070015491 m_commandBuffer->EndRenderPass();
15492 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015493}
15494
Mark Youngc48c4c12016-04-11 14:26:49 -060015495TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015497
15498 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015499
15500 // Create an image
15501 VkImage image;
15502
Karl Schultz6addd812016-02-02 17:17:23 -070015503 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15504 const int32_t tex_width = 32;
15505 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015506
15507 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015508 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15509 image_create_info.pNext = NULL;
15510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15511 image_create_info.format = tex_format;
15512 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015513 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015514 image_create_info.extent.depth = 1;
15515 image_create_info.mipLevels = 1;
15516 image_create_info.arrayLayers = 1;
15517 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15518 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15519 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15520 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015521
15522 // Introduce error by sending down a bogus width extent
15523 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015524 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015526 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015527}
15528
Mark Youngc48c4c12016-04-11 14:26:49 -060015529TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015531
15532 ASSERT_NO_FATAL_FAILURE(InitState());
15533
15534 // Create an image
15535 VkImage image;
15536
15537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15538 const int32_t tex_width = 32;
15539 const int32_t tex_height = 32;
15540
15541 VkImageCreateInfo image_create_info = {};
15542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15543 image_create_info.pNext = NULL;
15544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15545 image_create_info.format = tex_format;
15546 image_create_info.extent.width = tex_width;
15547 image_create_info.extent.height = tex_height;
15548 image_create_info.extent.depth = 1;
15549 image_create_info.mipLevels = 1;
15550 image_create_info.arrayLayers = 1;
15551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15552 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15553 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15554 image_create_info.flags = 0;
15555
15556 // Introduce error by sending down a bogus width extent
15557 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015558 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015559 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15560
15561 m_errorMonitor->VerifyFound();
15562}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015563
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015564TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015565 TEST_DESCRIPTION(
15566 "Create a render pass with an attachment description "
15567 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015568
15569 ASSERT_NO_FATAL_FAILURE(InitState());
15570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15571
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015573
15574 VkAttachmentReference color_attach = {};
15575 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15576 color_attach.attachment = 0;
15577 VkSubpassDescription subpass = {};
15578 subpass.colorAttachmentCount = 1;
15579 subpass.pColorAttachments = &color_attach;
15580
15581 VkRenderPassCreateInfo rpci = {};
15582 rpci.subpassCount = 1;
15583 rpci.pSubpasses = &subpass;
15584 rpci.attachmentCount = 1;
15585 VkAttachmentDescription attach_desc = {};
15586 attach_desc.format = VK_FORMAT_UNDEFINED;
15587 rpci.pAttachments = &attach_desc;
15588 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15589 VkRenderPass rp;
15590 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15591
15592 m_errorMonitor->VerifyFound();
15593
15594 if (result == VK_SUCCESS) {
15595 vkDestroyRenderPass(m_device->device(), rp, NULL);
15596 }
15597}
15598
Karl Schultz6addd812016-02-02 17:17:23 -070015599TEST_F(VkLayerTest, InvalidImageView) {
Tobin Ehliscde08892015-09-22 10:11:37 -060015600 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015601
Mike Stroyana3082432015-09-25 13:39:21 -060015602 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015603 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15604 const int32_t tex_width = 32;
15605 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015606
15607 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015608 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15609 image_create_info.pNext = NULL;
15610 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15611 image_create_info.format = tex_format;
15612 image_create_info.extent.width = tex_width;
15613 image_create_info.extent.height = tex_height;
15614 image_create_info.extent.depth = 1;
15615 image_create_info.mipLevels = 1;
15616 image_create_info.arrayLayers = 1;
15617 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15618 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15619 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15620 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015621
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015622 VkImage image;
15623 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015624 ASSERT_VK_SUCCESS(err);
15625
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015626 VkMemoryRequirements requirements;
15627 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
15628
15629 VkMemoryAllocateInfo alloc_info{};
15630 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15631 alloc_info.pNext = NULL;
15632 alloc_info.memoryTypeIndex = 0;
15633 alloc_info.allocationSize = requirements.size;
15634 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15635 ASSERT_TRUE(pass);
15636
15637 VkDeviceMemory memory;
15638 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
15639 ASSERT_VK_SUCCESS(err);
15640
15641 err = vkBindImageMemory(m_device->device(), image, memory, 0);
15642
Tobin Ehliscde08892015-09-22 10:11:37 -060015643 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015644 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015645 image_view_create_info.image = image;
15646 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15647 image_view_create_info.format = tex_format;
15648 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015649 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015650 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015651 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015652
15653 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015656 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015657
15658 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060015659 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015660}
Mike Stroyana3082432015-09-25 13:39:21 -060015661
Mark Youngd339ba32016-05-30 13:28:35 -060015662TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15663 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015665 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015666
15667 ASSERT_NO_FATAL_FAILURE(InitState());
15668
15669 // Create an image and try to create a view with no memory backing the image
15670 VkImage image;
15671
15672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15673 const int32_t tex_width = 32;
15674 const int32_t tex_height = 32;
15675
15676 VkImageCreateInfo image_create_info = {};
15677 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15678 image_create_info.pNext = NULL;
15679 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15680 image_create_info.format = tex_format;
15681 image_create_info.extent.width = tex_width;
15682 image_create_info.extent.height = tex_height;
15683 image_create_info.extent.depth = 1;
15684 image_create_info.mipLevels = 1;
15685 image_create_info.arrayLayers = 1;
15686 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15687 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15688 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15689 image_create_info.flags = 0;
15690
15691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15692 ASSERT_VK_SUCCESS(err);
15693
15694 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015695 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015696 image_view_create_info.image = image;
15697 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15698 image_view_create_info.format = tex_format;
15699 image_view_create_info.subresourceRange.layerCount = 1;
15700 image_view_create_info.subresourceRange.baseMipLevel = 0;
15701 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015702 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015703
15704 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015705 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015706
15707 m_errorMonitor->VerifyFound();
15708 vkDestroyImage(m_device->device(), image, NULL);
15709 // If last error is success, it still created the view, so delete it.
15710 if (err == VK_SUCCESS) {
15711 vkDestroyImageView(m_device->device(), view, NULL);
15712 }
Mark Youngd339ba32016-05-30 13:28:35 -060015713}
15714
Karl Schultz6addd812016-02-02 17:17:23 -070015715TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015718
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015719 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015720
Karl Schultz6addd812016-02-02 17:17:23 -070015721 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015722 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015724 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015725
15726 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015727 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015728 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015729 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15730 image_view_create_info.format = tex_format;
15731 image_view_create_info.subresourceRange.baseMipLevel = 0;
15732 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015733 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015734 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015735 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015736
15737 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015738 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015739
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015740 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015741}
15742
Mike Weiblena1e13f42017-02-09 21:25:59 -070015743TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15744 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15745
15746 ASSERT_NO_FATAL_FAILURE(InitState());
15747 VkSubresourceLayout subres_layout = {};
15748
15749 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15750 {
15751 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15752 VkImageObj img(m_device);
15753 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15754 ASSERT_TRUE(img.initialized());
15755
15756 VkImageSubresource subres = {};
15757 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15758 subres.mipLevel = 0;
15759 subres.arrayLayer = 0;
15760
15761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15762 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15763 m_errorMonitor->VerifyFound();
15764 }
15765
15766 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15767 {
15768 VkImageObj img(m_device);
15769 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15770 ASSERT_TRUE(img.initialized());
15771
15772 VkImageSubresource subres = {};
15773 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15774 subres.mipLevel = 0;
15775 subres.arrayLayer = 0;
15776
15777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15779 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15780 m_errorMonitor->VerifyFound();
15781 }
15782
15783 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15784 {
15785 VkImageObj img(m_device);
15786 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15787 ASSERT_TRUE(img.initialized());
15788
15789 VkImageSubresource subres = {};
15790 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15791 subres.mipLevel = 1; // ERROR: triggers VU 00739
15792 subres.arrayLayer = 0;
15793
15794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15795 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15796 m_errorMonitor->VerifyFound();
15797 }
15798
15799 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15800 {
15801 VkImageObj img(m_device);
15802 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15803 ASSERT_TRUE(img.initialized());
15804
15805 VkImageSubresource subres = {};
15806 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15807 subres.mipLevel = 0;
15808 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15809
15810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15811 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15812 m_errorMonitor->VerifyFound();
15813 }
15814}
15815
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015816TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015817 VkResult err;
15818 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015819
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015821
Mike Stroyana3082432015-09-25 13:39:21 -060015822 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015823
15824 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015825 VkImage srcImage;
15826 VkImage dstImage;
15827 VkDeviceMemory srcMem;
15828 VkDeviceMemory destMem;
15829 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015830
15831 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015832 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15833 image_create_info.pNext = NULL;
15834 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15835 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15836 image_create_info.extent.width = 32;
15837 image_create_info.extent.height = 32;
15838 image_create_info.extent.depth = 1;
15839 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015840 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015841 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15842 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15843 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15844 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015846 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015847 ASSERT_VK_SUCCESS(err);
15848
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015849 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015851 ASSERT_VK_SUCCESS(err);
15852
15853 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015854 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015855 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15856 memAlloc.pNext = NULL;
15857 memAlloc.allocationSize = 0;
15858 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015859
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015860 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015861 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015862 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015863 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015864 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015865 ASSERT_VK_SUCCESS(err);
15866
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015867 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015868 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015869 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015870 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015871 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015872 ASSERT_VK_SUCCESS(err);
15873
15874 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15875 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015876 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015877 ASSERT_VK_SUCCESS(err);
15878
Tony Barbour552f6c02016-12-21 14:34:07 -070015879 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015880 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015881 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015882 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015883 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015884 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015885 copyRegion.srcOffset.x = 0;
15886 copyRegion.srcOffset.y = 0;
15887 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015888 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015889 copyRegion.dstSubresource.mipLevel = 0;
15890 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015891 // Introduce failure by forcing the dst layerCount to differ from src
15892 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015893 copyRegion.dstOffset.x = 0;
15894 copyRegion.dstOffset.y = 0;
15895 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015896 copyRegion.extent.width = 1;
15897 copyRegion.extent.height = 1;
15898 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015899 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015900 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015902 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015903
Chia-I Wuf7458c52015-10-26 21:10:41 +080015904 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015905 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015906 vkFreeMemory(m_device->device(), srcMem, NULL);
15907 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015908}
15909
Tony Barbourd6673642016-05-05 14:46:39 -060015910TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015911 TEST_DESCRIPTION("Creating images with unsuported formats ");
15912
15913 ASSERT_NO_FATAL_FAILURE(InitState());
15914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060015915
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015916 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015917 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15920 image_create_info.format = VK_FORMAT_UNDEFINED;
15921 image_create_info.extent.width = 32;
15922 image_create_info.extent.height = 32;
15923 image_create_info.extent.depth = 1;
15924 image_create_info.mipLevels = 1;
15925 image_create_info.arrayLayers = 1;
15926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15927 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15928 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15931 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015932
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015933 VkImage image;
15934 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015935 m_errorMonitor->VerifyFound();
15936
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015937 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015938 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060015939 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15940 VkFormat format = static_cast<VkFormat>(f);
15941 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015942 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015943 unsupported = format;
15944 break;
15945 }
15946 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015947
Tony Barbourd6673642016-05-05 14:46:39 -060015948 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015949 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015951
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015952 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060015953 m_errorMonitor->VerifyFound();
15954 }
15955}
15956
15957TEST_F(VkLayerTest, ImageLayerViewTests) {
15958 VkResult ret;
15959 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15960
15961 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015962 auto depth_format = find_depth_stencil_format(m_device);
15963 if (!depth_format) {
15964 return;
15965 }
Tony Barbourd6673642016-05-05 14:46:39 -060015966
15967 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015968 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 -060015969 VK_IMAGE_TILING_OPTIMAL, 0);
15970 ASSERT_TRUE(image.initialized());
15971
15972 VkImageView imgView;
15973 VkImageViewCreateInfo imgViewInfo = {};
15974 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15975 imgViewInfo.image = image.handle();
15976 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15977 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15978 imgViewInfo.subresourceRange.layerCount = 1;
15979 imgViewInfo.subresourceRange.baseMipLevel = 0;
15980 imgViewInfo.subresourceRange.levelCount = 1;
15981 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15982
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015984 // View can't have baseMipLevel >= image's mipLevels - Expect
15985 // VIEW_CREATE_ERROR
15986 imgViewInfo.subresourceRange.baseMipLevel = 1;
15987 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15988 m_errorMonitor->VerifyFound();
15989 imgViewInfo.subresourceRange.baseMipLevel = 0;
15990
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015992 // View can't have baseArrayLayer >= image's arraySize - Expect
15993 // VIEW_CREATE_ERROR
15994 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15995 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15996 m_errorMonitor->VerifyFound();
15997 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15998
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016000 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16001 imgViewInfo.subresourceRange.levelCount = 0;
16002 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16003 m_errorMonitor->VerifyFound();
16004 imgViewInfo.subresourceRange.levelCount = 1;
16005
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016006 m_errorMonitor->SetDesiredFailureMsg(
16007 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16008 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016009 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16010 imgViewInfo.subresourceRange.layerCount = 0;
16011 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16012 m_errorMonitor->VerifyFound();
16013 imgViewInfo.subresourceRange.layerCount = 1;
16014
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16016 "Formats MUST be IDENTICAL unless "
16017 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16018 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016019 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016020 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060016021 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16022 m_errorMonitor->VerifyFound();
16023 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16024
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016026 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16027 // VIEW_CREATE_ERROR
16028 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16029 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16030 m_errorMonitor->VerifyFound();
16031 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16032
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016034 // TODO: Update framework to easily passing mutable flag into ImageObj init
16035 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016036 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16037 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16038 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016039 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16040 // VIEW_CREATE_ERROR
16041 VkImageCreateInfo mutImgInfo = image.create_info();
16042 VkImage mutImage;
16043 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016045 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16046 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16047 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16048 ASSERT_VK_SUCCESS(ret);
16049 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016050 m_errorMonitor->SetUnexpectedError(
16051 "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 -060016052 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16053 m_errorMonitor->VerifyFound();
16054 imgViewInfo.image = image.handle();
16055 vkDestroyImage(m_device->handle(), mutImage, NULL);
16056}
16057
Dave Houlton75967fc2017-03-06 17:21:16 -070016058TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16059 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16060
16061 ASSERT_NO_FATAL_FAILURE(InitState());
16062
Jamie Madill35127872017-03-15 16:17:46 -040016063 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016064 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16065 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16066 if (device_features.textureCompressionBC) {
16067 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16068 } else if (device_features.textureCompressionETC2) {
16069 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16070 } else if (device_features.textureCompressionASTC_LDR) {
16071 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16072 } else {
16073 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16074 return;
16075 }
16076
16077 VkImageCreateInfo ci;
16078 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16079 ci.pNext = NULL;
16080 ci.flags = 0;
16081 ci.imageType = VK_IMAGE_TYPE_2D;
16082 ci.format = compressed_format;
16083 ci.extent = {32, 32, 1};
16084 ci.mipLevels = 6;
16085 ci.arrayLayers = 1;
16086 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16087 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16088 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16089 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16090 ci.queueFamilyIndexCount = 0;
16091 ci.pQueueFamilyIndices = NULL;
16092 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16093
16094 VkImageObj image(m_device);
16095 image.init(&ci);
16096 ASSERT_TRUE(image.initialized());
16097
16098 VkImageObj odd_image(m_device);
16099 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16100 odd_image.init(&ci);
16101 ASSERT_TRUE(odd_image.initialized());
16102
16103 // Allocate buffers
16104 VkMemoryPropertyFlags reqs = 0;
16105 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16106 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16107 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16108 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16109 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16110
16111 VkBufferImageCopy region = {};
16112 region.bufferRowLength = 0;
16113 region.bufferImageHeight = 0;
16114 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16115 region.imageSubresource.layerCount = 1;
16116 region.imageOffset = {0, 0, 0};
16117 region.bufferOffset = 0;
16118
16119 // start recording
16120 m_commandBuffer->BeginCommandBuffer();
16121
16122 // Mip level copies that work - 5 levels
16123 m_errorMonitor->ExpectSuccess();
16124
16125 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16126 region.imageExtent = {32, 32, 1};
16127 region.imageSubresource.mipLevel = 0;
16128 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16129 &region);
16130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16131 &region);
16132
16133 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16134 region.imageExtent = {8, 8, 1};
16135 region.imageSubresource.mipLevel = 2;
16136 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16137 &region);
16138 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16139 &region);
16140
16141 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16142 region.imageExtent = {4, 4, 1};
16143 region.imageSubresource.mipLevel = 3;
16144 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16145 &region);
16146 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16147 &region);
16148
16149 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16150 region.imageExtent = {2, 2, 1};
16151 region.imageSubresource.mipLevel = 4;
16152 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16153 &region);
16154 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16155 &region);
16156
16157 region.imageExtent = {1, 1, 1};
16158 region.imageSubresource.mipLevel = 5;
16159 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16160 &region);
16161 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16162 &region);
16163 m_errorMonitor->VerifyNotFound();
16164
16165 // Buffer must accomodate a full compressed block, regardless of texel count
16166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16167 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16168 &region);
16169 m_errorMonitor->VerifyFound();
16170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16171 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16172 &region);
16173 m_errorMonitor->VerifyFound();
16174
16175 // Copy width < compressed block size, but not the full mip width
16176 region.imageExtent = {1, 2, 1};
16177 region.imageSubresource.mipLevel = 4;
16178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16179 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16180 &region);
16181 m_errorMonitor->VerifyFound();
16182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16183 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16184 &region);
16185 m_errorMonitor->VerifyFound();
16186
16187 // Copy height < compressed block size but not the full mip height
16188 region.imageExtent = {2, 1, 1};
16189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16190 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16191 &region);
16192 m_errorMonitor->VerifyFound();
16193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16194 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16195 &region);
16196 m_errorMonitor->VerifyFound();
16197
16198 // Offsets must be multiple of compressed block size
16199 region.imageOffset = {1, 1, 0};
16200 region.imageExtent = {1, 1, 1};
16201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16202 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16203 &region);
16204 m_errorMonitor->VerifyFound();
16205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16206 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16207 &region);
16208 m_errorMonitor->VerifyFound();
16209
16210 // Offset + extent width = mip width - should succeed
16211 region.imageOffset = {4, 4, 0};
16212 region.imageExtent = {3, 4, 1};
16213 region.imageSubresource.mipLevel = 2;
16214 m_errorMonitor->ExpectSuccess();
16215 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16216 &region);
16217 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16218 &region);
16219 m_errorMonitor->VerifyNotFound();
16220
16221 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16222 region.imageExtent = {4, 4, 1};
16223 m_errorMonitor->ExpectSuccess();
16224 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16225 &region);
16226 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16227 &region);
16228 m_errorMonitor->VerifyNotFound();
16229
16230 // Offset + extent width < mip width and not a multiple of block width - should fail
16231 region.imageExtent = {3, 3, 1};
16232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16233 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16234 &region);
16235 m_errorMonitor->VerifyFound();
16236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16237 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16238 &region);
16239 m_errorMonitor->VerifyFound();
16240}
16241
Dave Houlton59a20702017-02-02 17:26:23 -070016242TEST_F(VkLayerTest, ImageBufferCopyTests) {
16243 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16244
16245 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016246 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16247 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16248 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16249 return;
16250 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016251
16252 // Bail if any dimension of transfer granularity is 0.
16253 auto index = m_device->graphics_queue_node_index_;
16254 auto queue_family_properties = m_device->phy().queue_properties();
16255 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16256 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16257 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16258 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16259 return;
16260 }
16261
Dave Houlton59a20702017-02-02 17:26:23 -070016262 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16263 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16264 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016265 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16266 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16267 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16268 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16269
Dave Houlton59a20702017-02-02 17:26:23 -070016270 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16271 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16272 VK_IMAGE_TILING_OPTIMAL, 0);
16273 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16274 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16275 VK_IMAGE_TILING_OPTIMAL, 0);
16276 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16277 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016278 ASSERT_TRUE(image_64k.initialized());
16279 ASSERT_TRUE(image_16k.initialized());
16280 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016281
Dave Houltonf3229d52017-02-21 15:59:08 -070016282 // Verify all needed Depth/Stencil formats are supported
16283 bool missing_ds_support = false;
16284 VkFormatProperties props = {0, 0, 0};
16285 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16286 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16287 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16288 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16289 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16290 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16291 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16292 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16293
16294 if (!missing_ds_support) {
16295 ds_image_4D_1S.init(
16296 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16297 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16298 VK_IMAGE_TILING_OPTIMAL, 0);
16299 ASSERT_TRUE(ds_image_4D_1S.initialized());
16300
16301 ds_image_3D_1S.init(
16302 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16303 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16304 VK_IMAGE_TILING_OPTIMAL, 0);
16305 ASSERT_TRUE(ds_image_3D_1S.initialized());
16306
16307 ds_image_2D.init(
16308 256, 256, VK_FORMAT_D16_UNORM,
16309 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16310 VK_IMAGE_TILING_OPTIMAL, 0);
16311 ASSERT_TRUE(ds_image_2D.initialized());
16312
16313 ds_image_1S.init(
16314 256, 256, VK_FORMAT_S8_UINT,
16315 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16316 VK_IMAGE_TILING_OPTIMAL, 0);
16317 ASSERT_TRUE(ds_image_1S.initialized());
16318 }
16319
16320 // Allocate buffers
16321 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016322 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016323 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16324 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16325 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16326 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016327
16328 VkBufferImageCopy region = {};
16329 region.bufferRowLength = 0;
16330 region.bufferImageHeight = 0;
16331 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16332 region.imageSubresource.layerCount = 1;
16333 region.imageOffset = {0, 0, 0};
16334 region.imageExtent = {64, 64, 1};
16335 region.bufferOffset = 0;
16336
16337 // attempt copies before putting command buffer in recording state
16338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16339 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16340 &region);
16341 m_errorMonitor->VerifyFound();
16342
16343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16344 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16345 &region);
16346 m_errorMonitor->VerifyFound();
16347
16348 // start recording
16349 m_commandBuffer->BeginCommandBuffer();
16350
16351 // successful copies
16352 m_errorMonitor->ExpectSuccess();
16353 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16354 &region);
16355 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16356 &region);
16357 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16359 &region);
16360 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16361 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16362 &region);
16363 region.imageOffset.x = 0;
16364 region.imageExtent.height = 64;
16365 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16366 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16367 &region);
16368 m_errorMonitor->VerifyNotFound();
16369
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016370 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016371 region.imageExtent = {65, 64, 1};
16372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16373 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16374 &region);
16375 m_errorMonitor->VerifyFound();
16376
16377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16378 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16379 &region);
16380 m_errorMonitor->VerifyFound();
16381
16382 // image/buffer too small (offset) on copy to image
16383 region.imageExtent = {64, 64, 1};
16384 region.imageOffset = {0, 4, 0};
16385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16386 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16387 &region);
16388 m_errorMonitor->VerifyFound();
16389
16390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16391 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16392 &region);
16393 m_errorMonitor->VerifyFound();
16394
16395 // image/buffer too small on copy to buffer
16396 region.imageExtent = {64, 64, 1};
16397 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016398 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16400 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16401 &region);
16402 m_errorMonitor->VerifyFound();
16403
16404 region.imageExtent = {64, 65, 1};
16405 region.bufferOffset = 0;
16406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16407 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16408 &region);
16409 m_errorMonitor->VerifyFound();
16410
16411 // buffer size ok but rowlength causes loose packing
16412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16413 region.imageExtent = {64, 64, 1};
16414 region.bufferRowLength = 68;
16415 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16416 &region);
16417 m_errorMonitor->VerifyFound();
16418
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016419 // An extent with zero area should produce a warning, but no error
16420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16421 region.imageExtent.width = 0;
16422 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16423 &region);
16424 m_errorMonitor->VerifyFound();
16425
Dave Houlton59a20702017-02-02 17:26:23 -070016426 // aspect bits
16427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16428 region.imageExtent = {64, 64, 1};
16429 region.bufferRowLength = 0;
16430 region.bufferImageHeight = 0;
16431 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16432 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16433 buffer_16k.handle(), 1, &region);
16434 m_errorMonitor->VerifyFound();
16435
16436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16437 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16438 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16439 &region);
16440 m_errorMonitor->VerifyFound();
16441
16442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16443 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16444 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16445 buffer_16k.handle(), 1, &region);
16446 m_errorMonitor->VerifyFound();
16447
Dave Houltonf3229d52017-02-21 15:59:08 -070016448 // Test Depth/Stencil copies
16449 if (missing_ds_support) {
16450 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16451 } else {
16452 VkBufferImageCopy ds_region = {};
16453 ds_region.bufferOffset = 0;
16454 ds_region.bufferRowLength = 0;
16455 ds_region.bufferImageHeight = 0;
16456 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16457 ds_region.imageSubresource.mipLevel = 0;
16458 ds_region.imageSubresource.baseArrayLayer = 0;
16459 ds_region.imageSubresource.layerCount = 1;
16460 ds_region.imageOffset = {0, 0, 0};
16461 ds_region.imageExtent = {256, 256, 1};
16462
16463 // Depth copies that should succeed
16464 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16465 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16466 buffer_256k.handle(), 1, &ds_region);
16467 m_errorMonitor->VerifyNotFound();
16468
16469 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16470 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16471 buffer_256k.handle(), 1, &ds_region);
16472 m_errorMonitor->VerifyNotFound();
16473
16474 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16475 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16476 buffer_128k.handle(), 1, &ds_region);
16477 m_errorMonitor->VerifyNotFound();
16478
16479 // Depth copies that should fail
16480 ds_region.bufferOffset = 4;
16481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16482 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16483 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16484 buffer_256k.handle(), 1, &ds_region);
16485 m_errorMonitor->VerifyFound();
16486
16487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16488 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16489 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16490 buffer_256k.handle(), 1, &ds_region);
16491 m_errorMonitor->VerifyFound();
16492
16493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16494 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16496 buffer_128k.handle(), 1, &ds_region);
16497 m_errorMonitor->VerifyFound();
16498
16499 // Stencil copies that should succeed
16500 ds_region.bufferOffset = 0;
16501 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16502 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16503 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16504 buffer_64k.handle(), 1, &ds_region);
16505 m_errorMonitor->VerifyNotFound();
16506
16507 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16508 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16509 buffer_64k.handle(), 1, &ds_region);
16510 m_errorMonitor->VerifyNotFound();
16511
16512 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16513 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16514 buffer_64k.handle(), 1, &ds_region);
16515 m_errorMonitor->VerifyNotFound();
16516
16517 // Stencil copies that should fail
16518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16519 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16520 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16521 buffer_16k.handle(), 1, &ds_region);
16522 m_errorMonitor->VerifyFound();
16523
16524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16525 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16526 ds_region.bufferRowLength = 260;
16527 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16528 buffer_64k.handle(), 1, &ds_region);
16529 m_errorMonitor->VerifyFound();
16530
16531 ds_region.bufferRowLength = 0;
16532 ds_region.bufferOffset = 4;
16533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16534 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16535 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16536 buffer_64k.handle(), 1, &ds_region);
16537 m_errorMonitor->VerifyFound();
16538 }
16539
Dave Houlton584d51e2017-02-16 12:52:54 -070016540 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040016541 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070016542 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016543 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16544 device_features.textureCompressionASTC_LDR)) {
16545 printf(" No compressed formats supported - block compression tests skipped.\n");
16546 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016547 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16548 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016549 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016550 image_16k_4x4comp.init(128, 128, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016551 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16552 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016553 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016554 image_16k_4x4comp.init(128, 128, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070016555 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016556 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16557 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016558 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016559 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16560 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016561 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16562 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016563 }
16564 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016565
Dave Houlton584d51e2017-02-16 12:52:54 -070016566 // Just fits
16567 m_errorMonitor->ExpectSuccess();
16568 region.imageExtent = {128, 128, 1};
16569 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16570 buffer_16k.handle(), 1, &region);
16571 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016572
Dave Houlton584d51e2017-02-16 12:52:54 -070016573 // with offset, too big for buffer
16574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16575 region.bufferOffset = 16;
16576 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16577 buffer_16k.handle(), 1, &region);
16578 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016579 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016580
Dave Houlton67e9b532017-03-02 17:00:10 -070016581 // extents that are not a multiple of compressed block size
16582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16583 region.imageExtent.width = 66;
16584 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16585 buffer_16k.handle(), 1, &region);
16586 m_errorMonitor->VerifyFound();
16587 region.imageExtent.width = 128;
16588
16589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016590 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016591 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16592 buffer_16k.handle(), 1, &region);
16593 m_errorMonitor->VerifyFound();
16594 region.imageExtent.height = 128;
16595
16596 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16597
16598 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16599 m_errorMonitor->ExpectSuccess();
16600 region.imageExtent.width = 66;
16601 region.imageOffset.x = 64;
16602 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16603 buffer_16k.handle(), 1, &region);
16604 region.imageExtent.width = 16;
16605 region.imageOffset.x = 0;
16606 region.imageExtent.height = 2;
16607 region.imageOffset.y = 128;
16608 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016609 buffer_16k.handle(), 1, &region);
16610 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016611 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016612
Dave Houlton584d51e2017-02-16 12:52:54 -070016613 // buffer offset must be a multiple of texel block size (16)
16614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16616 region.imageExtent = {64, 64, 1};
16617 region.bufferOffset = 24;
16618 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16619 buffer_16k.handle(), 1, &region);
16620 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016621
Dave Houlton584d51e2017-02-16 12:52:54 -070016622 // rowlength not a multiple of block width (4)
16623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16624 region.bufferOffset = 0;
16625 region.bufferRowLength = 130;
16626 region.bufferImageHeight = 0;
16627 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16628 buffer_64k.handle(), 1, &region);
16629 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016630
Dave Houlton584d51e2017-02-16 12:52:54 -070016631 // imageheight not a multiple of block height (4)
16632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16633 region.bufferRowLength = 0;
16634 region.bufferImageHeight = 130;
16635 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16636 buffer_64k.handle(), 1, &region);
16637 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016638 }
Dave Houlton59a20702017-02-02 17:26:23 -070016639}
16640
Tony Barbourd6673642016-05-05 14:46:39 -060016641TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016642 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016643
16644 ASSERT_NO_FATAL_FAILURE(InitState());
16645
Rene Lindsay135204f2016-12-22 17:11:09 -070016646 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016647 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016648 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 -070016649 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016650 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016651 vk_testing::Buffer buffer;
16652 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016653 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016654 VkBufferImageCopy region = {};
16655 region.bufferRowLength = 128;
16656 region.bufferImageHeight = 128;
16657 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16658 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016659 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016660 region.imageExtent.height = 4;
16661 region.imageExtent.width = 4;
16662 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016663
16664 VkImageObj image2(m_device);
16665 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 -070016666 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016667 ASSERT_TRUE(image2.initialized());
16668 vk_testing::Buffer buffer2;
16669 VkMemoryPropertyFlags reqs2 = 0;
16670 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16671 VkBufferImageCopy region2 = {};
16672 region2.bufferRowLength = 128;
16673 region2.bufferImageHeight = 128;
16674 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16675 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16676 region2.imageSubresource.layerCount = 1;
16677 region2.imageExtent.height = 4;
16678 region2.imageExtent.width = 4;
16679 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016680 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016681
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016682 // Image must have offset.z of 0 and extent.depth of 1
16683 // Introduce failure by setting imageExtent.depth to 0
16684 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016686 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016687 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016688 m_errorMonitor->VerifyFound();
16689
16690 region.imageExtent.depth = 1;
16691
16692 // Image must have offset.z of 0 and extent.depth of 1
16693 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016694 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016695 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016698 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016699 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016700 m_errorMonitor->VerifyFound();
16701
16702 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016703 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16704 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016705 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016707 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16708 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016709 m_errorMonitor->VerifyFound();
16710
16711 // BufferOffset must be a multiple of 4
16712 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016713 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016715 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16716 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016717 m_errorMonitor->VerifyFound();
16718
16719 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16720 region.bufferOffset = 0;
16721 region.imageExtent.height = 128;
16722 region.imageExtent.width = 128;
16723 // Introduce failure by setting bufferRowLength > 0 but less than width
16724 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016726 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16727 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016728 m_errorMonitor->VerifyFound();
16729
16730 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16731 region.bufferRowLength = 128;
16732 // Introduce failure by setting bufferRowHeight > 0 but less than height
16733 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016735 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16736 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016737 m_errorMonitor->VerifyFound();
16738
16739 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016740 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016741 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16742 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016743 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016744 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16745 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016746 VkImageBlit blitRegion = {};
16747 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16748 blitRegion.srcSubresource.baseArrayLayer = 0;
16749 blitRegion.srcSubresource.layerCount = 1;
16750 blitRegion.srcSubresource.mipLevel = 0;
16751 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16752 blitRegion.dstSubresource.baseArrayLayer = 0;
16753 blitRegion.dstSubresource.layerCount = 1;
16754 blitRegion.dstSubresource.mipLevel = 0;
16755
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016756 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016758 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016759 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16760 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016761 m_errorMonitor->VerifyFound();
16762
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016764 VkImageMemoryBarrier img_barrier;
16765 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16766 img_barrier.pNext = NULL;
16767 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16768 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16769 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16770 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16771 img_barrier.image = image.handle();
16772 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16773 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16774 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16775 img_barrier.subresourceRange.baseArrayLayer = 0;
16776 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016777 img_barrier.subresourceRange.layerCount = 0;
16778 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016779 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16780 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016781 m_errorMonitor->VerifyFound();
16782 img_barrier.subresourceRange.layerCount = 1;
16783}
16784
16785TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016786 TEST_DESCRIPTION("Exceed the limits of image format ");
16787
Cody Northropc31a84f2016-08-22 10:41:47 -060016788 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016790 VkImageCreateInfo image_create_info = {};
16791 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16792 image_create_info.pNext = NULL;
16793 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16794 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16795 image_create_info.extent.width = 32;
16796 image_create_info.extent.height = 32;
16797 image_create_info.extent.depth = 1;
16798 image_create_info.mipLevels = 1;
16799 image_create_info.arrayLayers = 1;
16800 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16801 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16802 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16803 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16804 image_create_info.flags = 0;
16805
16806 VkImage nullImg;
16807 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016808 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16809 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016810 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016811 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16812 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16813 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016814 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016815
Tony Barbour0907e362017-03-09 15:05:30 -070016816 uint32_t maxDim =
16817 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16818 // If max mip levels exceeds image extents, skip the max mip levels test
16819 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16821 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16822 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16823 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16824 m_errorMonitor->VerifyFound();
16825 image_create_info.mipLevels = 1;
16826 }
Tony Barbourd6673642016-05-05 14:46:39 -060016827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016829 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16830 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16831 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16832 m_errorMonitor->VerifyFound();
16833 image_create_info.arrayLayers = 1;
16834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016836 int samples = imgFmtProps.sampleCounts >> 1;
16837 image_create_info.samples = (VkSampleCountFlagBits)samples;
16838 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16839 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16840 m_errorMonitor->VerifyFound();
16841 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16842
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16844 "pCreateInfo->initialLayout, must be "
16845 "VK_IMAGE_LAYOUT_UNDEFINED or "
16846 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016847 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16848 // Expect INVALID_LAYOUT
16849 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16850 m_errorMonitor->VerifyFound();
16851 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16852}
16853
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016854TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016855 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016857
16858 ASSERT_NO_FATAL_FAILURE(InitState());
16859
16860 VkImageObj src_image(m_device);
16861 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16862 VkImageObj dst_image(m_device);
16863 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16864
Tony Barbour552f6c02016-12-21 14:34:07 -070016865 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016866 VkImageCopy copy_region;
16867 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16868 copy_region.srcSubresource.mipLevel = 0;
16869 copy_region.srcSubresource.baseArrayLayer = 0;
16870 copy_region.srcSubresource.layerCount = 0;
16871 copy_region.srcOffset.x = 0;
16872 copy_region.srcOffset.y = 0;
16873 copy_region.srcOffset.z = 0;
16874 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16875 copy_region.dstSubresource.mipLevel = 0;
16876 copy_region.dstSubresource.baseArrayLayer = 0;
16877 copy_region.dstSubresource.layerCount = 0;
16878 copy_region.dstOffset.x = 0;
16879 copy_region.dstOffset.y = 0;
16880 copy_region.dstOffset.z = 0;
16881 copy_region.extent.width = 64;
16882 copy_region.extent.height = 64;
16883 copy_region.extent.depth = 1;
16884 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16885 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016886 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016887
16888 m_errorMonitor->VerifyFound();
16889}
16890
16891TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016892 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016894
16895 ASSERT_NO_FATAL_FAILURE(InitState());
16896
16897 VkImageObj src_image(m_device);
16898 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16899 VkImageObj dst_image(m_device);
16900 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16901
Tony Barbour552f6c02016-12-21 14:34:07 -070016902 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016903 VkImageCopy copy_region;
16904 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16905 copy_region.srcSubresource.mipLevel = 0;
16906 copy_region.srcSubresource.baseArrayLayer = 0;
16907 copy_region.srcSubresource.layerCount = 0;
16908 copy_region.srcOffset.x = 0;
16909 copy_region.srcOffset.y = 0;
16910 copy_region.srcOffset.z = 0;
16911 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16912 copy_region.dstSubresource.mipLevel = 0;
16913 copy_region.dstSubresource.baseArrayLayer = 0;
16914 copy_region.dstSubresource.layerCount = 0;
16915 copy_region.dstOffset.x = 0;
16916 copy_region.dstOffset.y = 0;
16917 copy_region.dstOffset.z = 0;
16918 copy_region.extent.width = 64;
16919 copy_region.extent.height = 64;
16920 copy_region.extent.depth = 1;
16921 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16922 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016923 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016924
16925 m_errorMonitor->VerifyFound();
16926}
16927
Karl Schultz6addd812016-02-02 17:17:23 -070016928TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016929 VkResult err;
16930 bool pass;
16931
16932 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016934
16935 ASSERT_NO_FATAL_FAILURE(InitState());
16936
16937 // Create two images of different types and try to copy between them
16938 VkImage srcImage;
16939 VkImage dstImage;
16940 VkDeviceMemory srcMem;
16941 VkDeviceMemory destMem;
16942 VkMemoryRequirements memReqs;
16943
16944 VkImageCreateInfo image_create_info = {};
16945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16946 image_create_info.pNext = NULL;
16947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16948 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16949 image_create_info.extent.width = 32;
16950 image_create_info.extent.height = 32;
16951 image_create_info.extent.depth = 1;
16952 image_create_info.mipLevels = 1;
16953 image_create_info.arrayLayers = 1;
16954 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16955 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16956 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16957 image_create_info.flags = 0;
16958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016959 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016960 ASSERT_VK_SUCCESS(err);
16961
16962 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16963 // Introduce failure by creating second image with a different-sized format.
16964 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016966 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016967 ASSERT_VK_SUCCESS(err);
16968
16969 // Allocate memory
16970 VkMemoryAllocateInfo memAlloc = {};
16971 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16972 memAlloc.pNext = NULL;
16973 memAlloc.allocationSize = 0;
16974 memAlloc.memoryTypeIndex = 0;
16975
16976 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16977 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016978 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016979 ASSERT_TRUE(pass);
16980 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16981 ASSERT_VK_SUCCESS(err);
16982
16983 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16984 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016985 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016986 ASSERT_TRUE(pass);
16987 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16988 ASSERT_VK_SUCCESS(err);
16989
16990 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16991 ASSERT_VK_SUCCESS(err);
16992 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16993 ASSERT_VK_SUCCESS(err);
16994
Tony Barbour552f6c02016-12-21 14:34:07 -070016995 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016996 VkImageCopy copyRegion;
16997 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16998 copyRegion.srcSubresource.mipLevel = 0;
16999 copyRegion.srcSubresource.baseArrayLayer = 0;
17000 copyRegion.srcSubresource.layerCount = 0;
17001 copyRegion.srcOffset.x = 0;
17002 copyRegion.srcOffset.y = 0;
17003 copyRegion.srcOffset.z = 0;
17004 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17005 copyRegion.dstSubresource.mipLevel = 0;
17006 copyRegion.dstSubresource.baseArrayLayer = 0;
17007 copyRegion.dstSubresource.layerCount = 0;
17008 copyRegion.dstOffset.x = 0;
17009 copyRegion.dstOffset.y = 0;
17010 copyRegion.dstOffset.z = 0;
17011 copyRegion.extent.width = 1;
17012 copyRegion.extent.height = 1;
17013 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017014 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017015 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017016
17017 m_errorMonitor->VerifyFound();
17018
17019 vkDestroyImage(m_device->device(), srcImage, NULL);
17020 vkDestroyImage(m_device->device(), dstImage, NULL);
17021 vkFreeMemory(m_device->device(), srcMem, NULL);
17022 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017023}
17024
Karl Schultz6addd812016-02-02 17:17:23 -070017025TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
17026 VkResult err;
17027 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017028
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017029 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17031 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017032
Mike Stroyana3082432015-09-25 13:39:21 -060017033 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017034 auto depth_format = find_depth_stencil_format(m_device);
17035 if (!depth_format) {
17036 return;
17037 }
Mike Stroyana3082432015-09-25 13:39:21 -060017038
17039 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017040 VkImage srcImage;
17041 VkImage dstImage;
17042 VkDeviceMemory srcMem;
17043 VkDeviceMemory destMem;
17044 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017045
17046 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17048 image_create_info.pNext = NULL;
17049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17050 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17051 image_create_info.extent.width = 32;
17052 image_create_info.extent.height = 32;
17053 image_create_info.extent.depth = 1;
17054 image_create_info.mipLevels = 1;
17055 image_create_info.arrayLayers = 1;
17056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17058 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17059 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017061 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017062 ASSERT_VK_SUCCESS(err);
17063
Karl Schultzbdb75952016-04-19 11:36:49 -060017064 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17065
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017066 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070017067 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070017068 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060017069 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017071 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017072 ASSERT_VK_SUCCESS(err);
17073
17074 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017075 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017076 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17077 memAlloc.pNext = NULL;
17078 memAlloc.allocationSize = 0;
17079 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017080
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017081 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017082 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017083 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017084 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017085 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017086 ASSERT_VK_SUCCESS(err);
17087
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017088 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017089 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017090 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017091 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017092 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017093 ASSERT_VK_SUCCESS(err);
17094
17095 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17096 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017097 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017098 ASSERT_VK_SUCCESS(err);
17099
Tony Barbour552f6c02016-12-21 14:34:07 -070017100 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017101 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017102 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017103 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017104 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017105 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017106 copyRegion.srcOffset.x = 0;
17107 copyRegion.srcOffset.y = 0;
17108 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017109 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017110 copyRegion.dstSubresource.mipLevel = 0;
17111 copyRegion.dstSubresource.baseArrayLayer = 0;
17112 copyRegion.dstSubresource.layerCount = 0;
17113 copyRegion.dstOffset.x = 0;
17114 copyRegion.dstOffset.y = 0;
17115 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017116 copyRegion.extent.width = 1;
17117 copyRegion.extent.height = 1;
17118 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017119 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017120 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017121
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017122 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017123
Chia-I Wuf7458c52015-10-26 21:10:41 +080017124 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017125 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017126 vkFreeMemory(m_device->device(), srcMem, NULL);
17127 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017128}
17129
Karl Schultz6addd812016-02-02 17:17:23 -070017130TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17131 VkResult err;
17132 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17135 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017136
Mike Stroyana3082432015-09-25 13:39:21 -060017137 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017138
17139 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017140 VkImage srcImage;
17141 VkImage dstImage;
17142 VkDeviceMemory srcMem;
17143 VkDeviceMemory destMem;
17144 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017145
17146 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017147 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17148 image_create_info.pNext = NULL;
17149 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17150 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17151 image_create_info.extent.width = 32;
17152 image_create_info.extent.height = 1;
17153 image_create_info.extent.depth = 1;
17154 image_create_info.mipLevels = 1;
17155 image_create_info.arrayLayers = 1;
17156 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17157 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17158 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17159 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017161 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017162 ASSERT_VK_SUCCESS(err);
17163
Karl Schultz6addd812016-02-02 17:17:23 -070017164 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017166 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017167 ASSERT_VK_SUCCESS(err);
17168
17169 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017170 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017171 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17172 memAlloc.pNext = NULL;
17173 memAlloc.allocationSize = 0;
17174 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017175
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017176 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017177 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017178 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017179 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017180 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017181 ASSERT_VK_SUCCESS(err);
17182
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017183 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017184 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017185 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017186 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017187 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017188 ASSERT_VK_SUCCESS(err);
17189
17190 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17191 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017192 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017193 ASSERT_VK_SUCCESS(err);
17194
Tony Barbour552f6c02016-12-21 14:34:07 -070017195 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017196 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017197 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17198 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017199 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017200 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017201 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017202 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017203 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017204 resolveRegion.srcOffset.x = 0;
17205 resolveRegion.srcOffset.y = 0;
17206 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017207 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017208 resolveRegion.dstSubresource.mipLevel = 0;
17209 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017210 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017211 resolveRegion.dstOffset.x = 0;
17212 resolveRegion.dstOffset.y = 0;
17213 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017214 resolveRegion.extent.width = 1;
17215 resolveRegion.extent.height = 1;
17216 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017217 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017218 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017219
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017220 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017221
Chia-I Wuf7458c52015-10-26 21:10:41 +080017222 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017223 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017224 vkFreeMemory(m_device->device(), srcMem, NULL);
17225 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017226}
17227
Karl Schultz6addd812016-02-02 17:17:23 -070017228TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17229 VkResult err;
17230 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17233 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017234
Mike Stroyana3082432015-09-25 13:39:21 -060017235 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017236
Chris Forbesa7530692016-05-08 12:35:39 +120017237 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017238 VkImage srcImage;
17239 VkImage dstImage;
17240 VkDeviceMemory srcMem;
17241 VkDeviceMemory destMem;
17242 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017243
17244 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017245 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17246 image_create_info.pNext = NULL;
17247 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17248 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17249 image_create_info.extent.width = 32;
17250 image_create_info.extent.height = 1;
17251 image_create_info.extent.depth = 1;
17252 image_create_info.mipLevels = 1;
17253 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017254 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017255 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17256 // Note: Some implementations expect color attachment usage for any
17257 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017258 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017259 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017262 ASSERT_VK_SUCCESS(err);
17263
Karl Schultz6addd812016-02-02 17:17:23 -070017264 // Note: Some implementations expect color attachment usage for any
17265 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017266 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017268 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017269 ASSERT_VK_SUCCESS(err);
17270
17271 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017272 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017273 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17274 memAlloc.pNext = NULL;
17275 memAlloc.allocationSize = 0;
17276 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017277
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017278 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017279 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017280 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017281 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017282 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017283 ASSERT_VK_SUCCESS(err);
17284
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017285 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017286 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017287 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017288 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017289 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017290 ASSERT_VK_SUCCESS(err);
17291
17292 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17293 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017294 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017295 ASSERT_VK_SUCCESS(err);
17296
Tony Barbour552f6c02016-12-21 14:34:07 -070017297 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017298 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017299 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17300 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017301 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017302 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017303 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017304 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017305 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017306 resolveRegion.srcOffset.x = 0;
17307 resolveRegion.srcOffset.y = 0;
17308 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017309 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017310 resolveRegion.dstSubresource.mipLevel = 0;
17311 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017312 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017313 resolveRegion.dstOffset.x = 0;
17314 resolveRegion.dstOffset.y = 0;
17315 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017316 resolveRegion.extent.width = 1;
17317 resolveRegion.extent.height = 1;
17318 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017319 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017320 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017322 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017323
Chia-I Wuf7458c52015-10-26 21:10:41 +080017324 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017325 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017326 vkFreeMemory(m_device->device(), srcMem, NULL);
17327 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017328}
17329
Karl Schultz6addd812016-02-02 17:17:23 -070017330TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17331 VkResult err;
17332 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017333
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017335 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017336
Mike Stroyana3082432015-09-25 13:39:21 -060017337 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017338
17339 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017340 VkImage srcImage;
17341 VkImage dstImage;
17342 VkDeviceMemory srcMem;
17343 VkDeviceMemory destMem;
17344 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017345
17346 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017347 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17348 image_create_info.pNext = NULL;
17349 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17350 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17351 image_create_info.extent.width = 32;
17352 image_create_info.extent.height = 1;
17353 image_create_info.extent.depth = 1;
17354 image_create_info.mipLevels = 1;
17355 image_create_info.arrayLayers = 1;
17356 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17357 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17358 // Note: Some implementations expect color attachment usage for any
17359 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017360 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017361 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017363 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017364 ASSERT_VK_SUCCESS(err);
17365
Karl Schultz6addd812016-02-02 17:17:23 -070017366 // Set format to something other than source image
17367 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17368 // Note: Some implementations expect color attachment usage for any
17369 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017370 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017371 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017373 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017374 ASSERT_VK_SUCCESS(err);
17375
17376 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017377 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017378 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17379 memAlloc.pNext = NULL;
17380 memAlloc.allocationSize = 0;
17381 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017382
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017383 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017384 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017385 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017386 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017387 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017388 ASSERT_VK_SUCCESS(err);
17389
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017390 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017391 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017392 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017393 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017394 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017395 ASSERT_VK_SUCCESS(err);
17396
17397 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17398 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017399 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017400 ASSERT_VK_SUCCESS(err);
17401
Tony Barbour552f6c02016-12-21 14:34:07 -070017402 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017403 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017404 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17405 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017406 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017407 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017408 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017409 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017410 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017411 resolveRegion.srcOffset.x = 0;
17412 resolveRegion.srcOffset.y = 0;
17413 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017414 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017415 resolveRegion.dstSubresource.mipLevel = 0;
17416 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017417 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017418 resolveRegion.dstOffset.x = 0;
17419 resolveRegion.dstOffset.y = 0;
17420 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017421 resolveRegion.extent.width = 1;
17422 resolveRegion.extent.height = 1;
17423 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017424 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017425 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017426
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017427 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017428
Chia-I Wuf7458c52015-10-26 21:10:41 +080017429 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017430 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017431 vkFreeMemory(m_device->device(), srcMem, NULL);
17432 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017433}
17434
Karl Schultz6addd812016-02-02 17:17:23 -070017435TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17436 VkResult err;
17437 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017438
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017440 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017441
Mike Stroyana3082432015-09-25 13:39:21 -060017442 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017443
17444 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017445 VkImage srcImage;
17446 VkImage dstImage;
17447 VkDeviceMemory srcMem;
17448 VkDeviceMemory destMem;
17449 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017450
17451 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017452 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17453 image_create_info.pNext = NULL;
17454 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17455 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17456 image_create_info.extent.width = 32;
17457 image_create_info.extent.height = 1;
17458 image_create_info.extent.depth = 1;
17459 image_create_info.mipLevels = 1;
17460 image_create_info.arrayLayers = 1;
17461 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17462 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17463 // Note: Some implementations expect color attachment usage for any
17464 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017465 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017466 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017468 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017469 ASSERT_VK_SUCCESS(err);
17470
Karl Schultz6addd812016-02-02 17:17:23 -070017471 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17472 // Note: Some implementations expect color attachment usage for any
17473 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017475 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017478 ASSERT_VK_SUCCESS(err);
17479
17480 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017481 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017482 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17483 memAlloc.pNext = NULL;
17484 memAlloc.allocationSize = 0;
17485 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017486
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017487 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017488 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017489 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017490 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017491 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017492 ASSERT_VK_SUCCESS(err);
17493
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017494 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017495 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017496 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017497 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017498 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017499 ASSERT_VK_SUCCESS(err);
17500
17501 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17502 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017503 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017504 ASSERT_VK_SUCCESS(err);
17505
Tony Barbour552f6c02016-12-21 14:34:07 -070017506 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017507 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017508 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17509 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017510 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017511 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017512 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017513 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017514 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017515 resolveRegion.srcOffset.x = 0;
17516 resolveRegion.srcOffset.y = 0;
17517 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017518 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017519 resolveRegion.dstSubresource.mipLevel = 0;
17520 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017521 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017522 resolveRegion.dstOffset.x = 0;
17523 resolveRegion.dstOffset.y = 0;
17524 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017525 resolveRegion.extent.width = 1;
17526 resolveRegion.extent.height = 1;
17527 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017528 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017529 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017530
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017531 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017532
Chia-I Wuf7458c52015-10-26 21:10:41 +080017533 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017534 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017535 vkFreeMemory(m_device->device(), srcMem, NULL);
17536 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017537}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017538
Karl Schultz6addd812016-02-02 17:17:23 -070017539TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017540 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017541 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17542 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017543 // The image format check comes 2nd in validation so we trigger it first,
17544 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017545 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17548 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017549
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017550 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017551 auto depth_format = find_depth_stencil_format(m_device);
17552 if (!depth_format) {
17553 return;
17554 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017555
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017556 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017557 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17558 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017559
17560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17562 ds_pool_ci.pNext = NULL;
17563 ds_pool_ci.maxSets = 1;
17564 ds_pool_ci.poolSizeCount = 1;
17565 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017566
17567 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017568 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017569 ASSERT_VK_SUCCESS(err);
17570
17571 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017572 dsl_binding.binding = 0;
17573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17574 dsl_binding.descriptorCount = 1;
17575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17576 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017577
17578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17580 ds_layout_ci.pNext = NULL;
17581 ds_layout_ci.bindingCount = 1;
17582 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017583 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017585 ASSERT_VK_SUCCESS(err);
17586
17587 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017588 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017589 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017590 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017591 alloc_info.descriptorPool = ds_pool;
17592 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017594 ASSERT_VK_SUCCESS(err);
17595
Karl Schultz6addd812016-02-02 17:17:23 -070017596 VkImage image_bad;
17597 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017598 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017599 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017600 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017601 const int32_t tex_width = 32;
17602 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017603
17604 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17606 image_create_info.pNext = NULL;
17607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17608 image_create_info.format = tex_format_bad;
17609 image_create_info.extent.width = tex_width;
17610 image_create_info.extent.height = tex_height;
17611 image_create_info.extent.depth = 1;
17612 image_create_info.mipLevels = 1;
17613 image_create_info.arrayLayers = 1;
17614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017617 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017620 ASSERT_VK_SUCCESS(err);
17621 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017622 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17623 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017624 ASSERT_VK_SUCCESS(err);
17625
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017626 // ---Bind image memory---
17627 VkMemoryRequirements img_mem_reqs;
17628 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17629 VkMemoryAllocateInfo image_alloc_info = {};
17630 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17631 image_alloc_info.pNext = NULL;
17632 image_alloc_info.memoryTypeIndex = 0;
17633 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017634 bool pass =
17635 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 -070017636 ASSERT_TRUE(pass);
17637 VkDeviceMemory mem;
17638 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17639 ASSERT_VK_SUCCESS(err);
17640 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17641 ASSERT_VK_SUCCESS(err);
17642 // -----------------------
17643
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017644 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017645 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017646 image_view_create_info.image = image_bad;
17647 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17648 image_view_create_info.format = tex_format_bad;
17649 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17650 image_view_create_info.subresourceRange.baseMipLevel = 0;
17651 image_view_create_info.subresourceRange.layerCount = 1;
17652 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017653 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017654
17655 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017656 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017657
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017658 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017659
Chia-I Wuf7458c52015-10-26 21:10:41 +080017660 vkDestroyImage(m_device->device(), image_bad, NULL);
17661 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017662 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17663 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017664
17665 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017666}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017667
17668TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017669 TEST_DESCRIPTION(
17670 "Call ClearColorImage w/ a depth|stencil image and "
17671 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017672
17673 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017674 auto depth_format = find_depth_stencil_format(m_device);
17675 if (!depth_format) {
17676 return;
17677 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17679
Tony Barbour552f6c02016-12-21 14:34:07 -070017680 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017681
17682 // Color image
17683 VkClearColorValue clear_color;
17684 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17685 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17686 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17687 const int32_t img_width = 32;
17688 const int32_t img_height = 32;
17689 VkImageCreateInfo image_create_info = {};
17690 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17691 image_create_info.pNext = NULL;
17692 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17693 image_create_info.format = color_format;
17694 image_create_info.extent.width = img_width;
17695 image_create_info.extent.height = img_height;
17696 image_create_info.extent.depth = 1;
17697 image_create_info.mipLevels = 1;
17698 image_create_info.arrayLayers = 1;
17699 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17700 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17701 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17702
17703 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017704 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017706 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017707
17708 // Depth/Stencil image
17709 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017710 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017711 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17712 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017713 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017714 ds_image_create_info.extent.width = 64;
17715 ds_image_create_info.extent.height = 64;
17716 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017717 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 -060017718
17719 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017720 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017722 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 -060017723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017726 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017727 &color_range);
17728
17729 m_errorMonitor->VerifyFound();
17730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17732 "vkCmdClearColorImage called with "
17733 "image created without "
17734 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017735
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017736 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017737 &color_range);
17738
17739 m_errorMonitor->VerifyFound();
17740
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017741 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17743 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017744
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017745 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17746 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017747
17748 m_errorMonitor->VerifyFound();
17749}
Tobin Ehliscde08892015-09-22 10:11:37 -060017750
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017751// WSI Enabled Tests
17752//
Chris Forbes09368e42016-10-13 11:59:22 +130017753#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017754TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17755
17756#if defined(VK_USE_PLATFORM_XCB_KHR)
17757 VkSurfaceKHR surface = VK_NULL_HANDLE;
17758
17759 VkResult err;
17760 bool pass;
17761 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17762 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17763 // uint32_t swapchain_image_count = 0;
17764 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17765 // uint32_t image_index = 0;
17766 // VkPresentInfoKHR present_info = {};
17767
17768 ASSERT_NO_FATAL_FAILURE(InitState());
17769
17770 // Use the create function from one of the VK_KHR_*_surface extension in
17771 // order to create a surface, testing all known errors in the process,
17772 // before successfully creating a surface:
17773 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17775 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17776 pass = (err != VK_SUCCESS);
17777 ASSERT_TRUE(pass);
17778 m_errorMonitor->VerifyFound();
17779
17780 // Next, try to create a surface with the wrong
17781 // VkXcbSurfaceCreateInfoKHR::sType:
17782 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17783 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17785 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17786 pass = (err != VK_SUCCESS);
17787 ASSERT_TRUE(pass);
17788 m_errorMonitor->VerifyFound();
17789
17790 // Create a native window, and then correctly create a surface:
17791 xcb_connection_t *connection;
17792 xcb_screen_t *screen;
17793 xcb_window_t xcb_window;
17794 xcb_intern_atom_reply_t *atom_wm_delete_window;
17795
17796 const xcb_setup_t *setup;
17797 xcb_screen_iterator_t iter;
17798 int scr;
17799 uint32_t value_mask, value_list[32];
17800 int width = 1;
17801 int height = 1;
17802
17803 connection = xcb_connect(NULL, &scr);
17804 ASSERT_TRUE(connection != NULL);
17805 setup = xcb_get_setup(connection);
17806 iter = xcb_setup_roots_iterator(setup);
17807 while (scr-- > 0)
17808 xcb_screen_next(&iter);
17809 screen = iter.data;
17810
17811 xcb_window = xcb_generate_id(connection);
17812
17813 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17814 value_list[0] = screen->black_pixel;
17815 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17816
17817 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17818 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17819
17820 /* Magic code that will send notification when window is destroyed */
17821 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17822 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17823
17824 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17825 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17826 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17827 free(reply);
17828
17829 xcb_map_window(connection, xcb_window);
17830
17831 // Force the x/y coordinates to 100,100 results are identical in consecutive
17832 // runs
17833 const uint32_t coords[] = { 100, 100 };
17834 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17835
17836 // Finally, try to correctly create a surface:
17837 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17838 xcb_create_info.pNext = NULL;
17839 xcb_create_info.flags = 0;
17840 xcb_create_info.connection = connection;
17841 xcb_create_info.window = xcb_window;
17842 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17843 pass = (err == VK_SUCCESS);
17844 ASSERT_TRUE(pass);
17845
17846 // Check if surface supports presentation:
17847
17848 // 1st, do so without having queried the queue families:
17849 VkBool32 supported = false;
17850 // TODO: Get the following error to come out:
17851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17852 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17853 "function");
17854 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17855 pass = (err != VK_SUCCESS);
17856 // ASSERT_TRUE(pass);
17857 // m_errorMonitor->VerifyFound();
17858
17859 // Next, query a queue family index that's too large:
17860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17861 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17862 pass = (err != VK_SUCCESS);
17863 ASSERT_TRUE(pass);
17864 m_errorMonitor->VerifyFound();
17865
17866 // Finally, do so correctly:
17867 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17868 // SUPPORTED
17869 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17870 pass = (err == VK_SUCCESS);
17871 ASSERT_TRUE(pass);
17872
17873 // Before proceeding, try to create a swapchain without having called
17874 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17875 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17876 swapchain_create_info.pNext = NULL;
17877 swapchain_create_info.flags = 0;
17878 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17879 swapchain_create_info.surface = surface;
17880 swapchain_create_info.imageArrayLayers = 1;
17881 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17882 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17884 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17885 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17886 pass = (err != VK_SUCCESS);
17887 ASSERT_TRUE(pass);
17888 m_errorMonitor->VerifyFound();
17889
17890 // Get the surface capabilities:
17891 VkSurfaceCapabilitiesKHR surface_capabilities;
17892
17893 // Do so correctly (only error logged by this entrypoint is if the
17894 // extension isn't enabled):
17895 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17896 pass = (err == VK_SUCCESS);
17897 ASSERT_TRUE(pass);
17898
17899 // Get the surface formats:
17900 uint32_t surface_format_count;
17901
17902 // First, try without a pointer to surface_format_count:
17903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17904 "specified as NULL");
17905 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17906 pass = (err == VK_SUCCESS);
17907 ASSERT_TRUE(pass);
17908 m_errorMonitor->VerifyFound();
17909
17910 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17911 // correctly done a 1st try (to get the count):
17912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17913 surface_format_count = 0;
17914 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17915 pass = (err == VK_SUCCESS);
17916 ASSERT_TRUE(pass);
17917 m_errorMonitor->VerifyFound();
17918
17919 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17920 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17921 pass = (err == VK_SUCCESS);
17922 ASSERT_TRUE(pass);
17923
17924 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17925 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17926
17927 // Next, do a 2nd try with surface_format_count being set too high:
17928 surface_format_count += 5;
17929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17930 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17931 pass = (err == VK_SUCCESS);
17932 ASSERT_TRUE(pass);
17933 m_errorMonitor->VerifyFound();
17934
17935 // Finally, do a correct 1st and 2nd try:
17936 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17937 pass = (err == VK_SUCCESS);
17938 ASSERT_TRUE(pass);
17939 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17940 pass = (err == VK_SUCCESS);
17941 ASSERT_TRUE(pass);
17942
17943 // Get the surface present modes:
17944 uint32_t surface_present_mode_count;
17945
17946 // First, try without a pointer to surface_format_count:
17947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17948 "specified as NULL");
17949
17950 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17951 pass = (err == VK_SUCCESS);
17952 ASSERT_TRUE(pass);
17953 m_errorMonitor->VerifyFound();
17954
17955 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17956 // correctly done a 1st try (to get the count):
17957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17958 surface_present_mode_count = 0;
17959 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17960 (VkPresentModeKHR *)&surface_present_mode_count);
17961 pass = (err == VK_SUCCESS);
17962 ASSERT_TRUE(pass);
17963 m_errorMonitor->VerifyFound();
17964
17965 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17966 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17967 pass = (err == VK_SUCCESS);
17968 ASSERT_TRUE(pass);
17969
17970 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17971 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17972
17973 // Next, do a 2nd try with surface_format_count being set too high:
17974 surface_present_mode_count += 5;
17975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17976 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17977 pass = (err == VK_SUCCESS);
17978 ASSERT_TRUE(pass);
17979 m_errorMonitor->VerifyFound();
17980
17981 // Finally, do a correct 1st and 2nd try:
17982 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17983 pass = (err == VK_SUCCESS);
17984 ASSERT_TRUE(pass);
17985 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17986 pass = (err == VK_SUCCESS);
17987 ASSERT_TRUE(pass);
17988
17989 // Create a swapchain:
17990
17991 // First, try without a pointer to swapchain_create_info:
17992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17993 "specified as NULL");
17994
17995 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17996 pass = (err != VK_SUCCESS);
17997 ASSERT_TRUE(pass);
17998 m_errorMonitor->VerifyFound();
17999
18000 // Next, call with a non-NULL swapchain_create_info, that has the wrong
18001 // sType:
18002 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18004
18005 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18006 pass = (err != VK_SUCCESS);
18007 ASSERT_TRUE(pass);
18008 m_errorMonitor->VerifyFound();
18009
18010 // Next, call with a NULL swapchain pointer:
18011 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
18012 swapchain_create_info.pNext = NULL;
18013 swapchain_create_info.flags = 0;
18014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
18015 "specified as NULL");
18016
18017 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
18018 pass = (err != VK_SUCCESS);
18019 ASSERT_TRUE(pass);
18020 m_errorMonitor->VerifyFound();
18021
18022 // TODO: Enhance swapchain layer so that
18023 // swapchain_create_info.queueFamilyIndexCount is checked against something?
18024
18025 // Next, call with a queue family index that's too large:
18026 uint32_t queueFamilyIndex[2] = { 100000, 0 };
18027 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18028 swapchain_create_info.queueFamilyIndexCount = 2;
18029 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
18030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
18031 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18032 pass = (err != VK_SUCCESS);
18033 ASSERT_TRUE(pass);
18034 m_errorMonitor->VerifyFound();
18035
18036 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
18037 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18038 swapchain_create_info.queueFamilyIndexCount = 1;
18039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18040 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
18041 "pCreateInfo->pQueueFamilyIndices).");
18042 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18043 pass = (err != VK_SUCCESS);
18044 ASSERT_TRUE(pass);
18045 m_errorMonitor->VerifyFound();
18046
18047 // Next, call with an invalid imageSharingMode:
18048 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
18049 swapchain_create_info.queueFamilyIndexCount = 1;
18050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18051 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
18052 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18053 pass = (err != VK_SUCCESS);
18054 ASSERT_TRUE(pass);
18055 m_errorMonitor->VerifyFound();
18056 // Fix for the future:
18057 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
18058 // SUPPORTED
18059 swapchain_create_info.queueFamilyIndexCount = 0;
18060 queueFamilyIndex[0] = 0;
18061 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
18062
18063 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
18064 // Get the images from a swapchain:
18065 // Acquire an image from a swapchain:
18066 // Present an image to a swapchain:
18067 // Destroy the swapchain:
18068
18069 // TODOs:
18070 //
18071 // - Try destroying the device without first destroying the swapchain
18072 //
18073 // - Try destroying the device without first destroying the surface
18074 //
18075 // - Try destroying the surface without first destroying the swapchain
18076
18077 // Destroy the surface:
18078 vkDestroySurfaceKHR(instance(), surface, NULL);
18079
18080 // Tear down the window:
18081 xcb_destroy_window(connection, xcb_window);
18082 xcb_disconnect(connection);
18083
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018084#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018085 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018086#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018087}
Chris Forbes09368e42016-10-13 11:59:22 +130018088#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018089
18090//
18091// POSITIVE VALIDATION TESTS
18092//
18093// These tests do not expect to encounter ANY validation errors pass only if this is true
18094
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018095TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18096 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18097 ASSERT_NO_FATAL_FAILURE(InitState());
18098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18099
18100 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18101 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18102 command_buffer_allocate_info.commandPool = m_commandPool;
18103 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18104 command_buffer_allocate_info.commandBufferCount = 1;
18105
18106 VkCommandBuffer secondary_command_buffer;
18107 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18108 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18109 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18110 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18111 command_buffer_inheritance_info.renderPass = m_renderPass;
18112 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18113
18114 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18115 command_buffer_begin_info.flags =
18116 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18117 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18118
18119 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18120 VkClearAttachment color_attachment;
18121 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18122 color_attachment.clearValue.color.float32[0] = 0;
18123 color_attachment.clearValue.color.float32[1] = 0;
18124 color_attachment.clearValue.color.float32[2] = 0;
18125 color_attachment.clearValue.color.float32[3] = 0;
18126 color_attachment.colorAttachment = 0;
18127 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18128 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18129}
18130
Tobin Ehlise0006882016-11-03 10:14:28 -060018131TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018132 TEST_DESCRIPTION(
18133 "Perform an image layout transition in a secondary command buffer followed "
18134 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018135 VkResult err;
18136 m_errorMonitor->ExpectSuccess();
18137 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018138 auto depth_format = find_depth_stencil_format(m_device);
18139 if (!depth_format) {
18140 return;
18141 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18143 // Allocate a secondary and primary cmd buffer
18144 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18145 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18146 command_buffer_allocate_info.commandPool = m_commandPool;
18147 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18148 command_buffer_allocate_info.commandBufferCount = 1;
18149
18150 VkCommandBuffer secondary_command_buffer;
18151 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18152 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18153 VkCommandBuffer primary_command_buffer;
18154 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18155 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18156 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18157 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18158 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18159 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18160 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18161
18162 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18163 ASSERT_VK_SUCCESS(err);
18164 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018165 image.init(128, 128, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060018166 ASSERT_TRUE(image.initialized());
18167 VkImageMemoryBarrier img_barrier = {};
18168 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18169 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18170 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18171 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18172 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18173 img_barrier.image = image.handle();
18174 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18175 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18176 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18177 img_barrier.subresourceRange.baseArrayLayer = 0;
18178 img_barrier.subresourceRange.baseMipLevel = 0;
18179 img_barrier.subresourceRange.layerCount = 1;
18180 img_barrier.subresourceRange.levelCount = 1;
18181 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18182 0, nullptr, 1, &img_barrier);
18183 err = vkEndCommandBuffer(secondary_command_buffer);
18184 ASSERT_VK_SUCCESS(err);
18185
18186 // Now update primary cmd buffer to execute secondary and transitions image
18187 command_buffer_begin_info.pInheritanceInfo = nullptr;
18188 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18189 ASSERT_VK_SUCCESS(err);
18190 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18191 VkImageMemoryBarrier img_barrier2 = {};
18192 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18193 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18194 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18195 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18196 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18197 img_barrier2.image = image.handle();
18198 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18199 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18200 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18201 img_barrier2.subresourceRange.baseArrayLayer = 0;
18202 img_barrier2.subresourceRange.baseMipLevel = 0;
18203 img_barrier2.subresourceRange.layerCount = 1;
18204 img_barrier2.subresourceRange.levelCount = 1;
18205 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18206 nullptr, 1, &img_barrier2);
18207 err = vkEndCommandBuffer(primary_command_buffer);
18208 ASSERT_VK_SUCCESS(err);
18209 VkSubmitInfo submit_info = {};
18210 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18211 submit_info.commandBufferCount = 1;
18212 submit_info.pCommandBuffers = &primary_command_buffer;
18213 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18214 ASSERT_VK_SUCCESS(err);
18215 m_errorMonitor->VerifyNotFound();
18216 err = vkDeviceWaitIdle(m_device->device());
18217 ASSERT_VK_SUCCESS(err);
18218 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18219 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18220}
18221
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018222// This is a positive test. No failures are expected.
18223TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018224 TEST_DESCRIPTION(
18225 "Ensure that the vkUpdateDescriptorSets validation code "
18226 "is ignoring VkWriteDescriptorSet members that are not "
18227 "related to the descriptor type specified by "
18228 "VkWriteDescriptorSet::descriptorType. Correct "
18229 "validation behavior will result in the test running to "
18230 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018231
18232 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18233
18234 ASSERT_NO_FATAL_FAILURE(InitState());
18235
18236 // Image Case
18237 {
18238 m_errorMonitor->ExpectSuccess();
18239
18240 VkImage image;
18241 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18242 const int32_t tex_width = 32;
18243 const int32_t tex_height = 32;
18244 VkImageCreateInfo image_create_info = {};
18245 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18246 image_create_info.pNext = NULL;
18247 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18248 image_create_info.format = tex_format;
18249 image_create_info.extent.width = tex_width;
18250 image_create_info.extent.height = tex_height;
18251 image_create_info.extent.depth = 1;
18252 image_create_info.mipLevels = 1;
18253 image_create_info.arrayLayers = 1;
18254 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18255 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18256 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18257 image_create_info.flags = 0;
18258 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18259 ASSERT_VK_SUCCESS(err);
18260
18261 VkMemoryRequirements memory_reqs;
18262 VkDeviceMemory image_memory;
18263 bool pass;
18264 VkMemoryAllocateInfo memory_info = {};
18265 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18266 memory_info.pNext = NULL;
18267 memory_info.allocationSize = 0;
18268 memory_info.memoryTypeIndex = 0;
18269 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18270 memory_info.allocationSize = memory_reqs.size;
18271 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18272 ASSERT_TRUE(pass);
18273 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18274 ASSERT_VK_SUCCESS(err);
18275 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18276 ASSERT_VK_SUCCESS(err);
18277
18278 VkImageViewCreateInfo image_view_create_info = {};
18279 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18280 image_view_create_info.image = image;
18281 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18282 image_view_create_info.format = tex_format;
18283 image_view_create_info.subresourceRange.layerCount = 1;
18284 image_view_create_info.subresourceRange.baseMipLevel = 0;
18285 image_view_create_info.subresourceRange.levelCount = 1;
18286 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18287
18288 VkImageView view;
18289 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18290 ASSERT_VK_SUCCESS(err);
18291
18292 VkDescriptorPoolSize ds_type_count = {};
18293 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18294 ds_type_count.descriptorCount = 1;
18295
18296 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18297 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18298 ds_pool_ci.pNext = NULL;
18299 ds_pool_ci.maxSets = 1;
18300 ds_pool_ci.poolSizeCount = 1;
18301 ds_pool_ci.pPoolSizes = &ds_type_count;
18302
18303 VkDescriptorPool ds_pool;
18304 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18305 ASSERT_VK_SUCCESS(err);
18306
18307 VkDescriptorSetLayoutBinding dsl_binding = {};
18308 dsl_binding.binding = 0;
18309 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18310 dsl_binding.descriptorCount = 1;
18311 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18312 dsl_binding.pImmutableSamplers = NULL;
18313
18314 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18315 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18316 ds_layout_ci.pNext = NULL;
18317 ds_layout_ci.bindingCount = 1;
18318 ds_layout_ci.pBindings = &dsl_binding;
18319 VkDescriptorSetLayout ds_layout;
18320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18321 ASSERT_VK_SUCCESS(err);
18322
18323 VkDescriptorSet descriptor_set;
18324 VkDescriptorSetAllocateInfo alloc_info = {};
18325 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18326 alloc_info.descriptorSetCount = 1;
18327 alloc_info.descriptorPool = ds_pool;
18328 alloc_info.pSetLayouts = &ds_layout;
18329 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18330 ASSERT_VK_SUCCESS(err);
18331
18332 VkDescriptorImageInfo image_info = {};
18333 image_info.imageView = view;
18334 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18335
18336 VkWriteDescriptorSet descriptor_write;
18337 memset(&descriptor_write, 0, sizeof(descriptor_write));
18338 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18339 descriptor_write.dstSet = descriptor_set;
18340 descriptor_write.dstBinding = 0;
18341 descriptor_write.descriptorCount = 1;
18342 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18343 descriptor_write.pImageInfo = &image_info;
18344
18345 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18346 // be
18347 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18348 // This will most likely produce a crash if the parameter_validation
18349 // layer
18350 // does not correctly ignore pBufferInfo.
18351 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18352 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18353
18354 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18355
18356 m_errorMonitor->VerifyNotFound();
18357
18358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18360 vkDestroyImageView(m_device->device(), view, NULL);
18361 vkDestroyImage(m_device->device(), image, NULL);
18362 vkFreeMemory(m_device->device(), image_memory, NULL);
18363 }
18364
18365 // Buffer Case
18366 {
18367 m_errorMonitor->ExpectSuccess();
18368
18369 VkBuffer buffer;
18370 uint32_t queue_family_index = 0;
18371 VkBufferCreateInfo buffer_create_info = {};
18372 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18373 buffer_create_info.size = 1024;
18374 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18375 buffer_create_info.queueFamilyIndexCount = 1;
18376 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18377
18378 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18379 ASSERT_VK_SUCCESS(err);
18380
18381 VkMemoryRequirements memory_reqs;
18382 VkDeviceMemory buffer_memory;
18383 bool pass;
18384 VkMemoryAllocateInfo memory_info = {};
18385 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18386 memory_info.pNext = NULL;
18387 memory_info.allocationSize = 0;
18388 memory_info.memoryTypeIndex = 0;
18389
18390 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18391 memory_info.allocationSize = memory_reqs.size;
18392 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18393 ASSERT_TRUE(pass);
18394
18395 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18396 ASSERT_VK_SUCCESS(err);
18397 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18398 ASSERT_VK_SUCCESS(err);
18399
18400 VkDescriptorPoolSize ds_type_count = {};
18401 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18402 ds_type_count.descriptorCount = 1;
18403
18404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18406 ds_pool_ci.pNext = NULL;
18407 ds_pool_ci.maxSets = 1;
18408 ds_pool_ci.poolSizeCount = 1;
18409 ds_pool_ci.pPoolSizes = &ds_type_count;
18410
18411 VkDescriptorPool ds_pool;
18412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18413 ASSERT_VK_SUCCESS(err);
18414
18415 VkDescriptorSetLayoutBinding dsl_binding = {};
18416 dsl_binding.binding = 0;
18417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18418 dsl_binding.descriptorCount = 1;
18419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18420 dsl_binding.pImmutableSamplers = NULL;
18421
18422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18424 ds_layout_ci.pNext = NULL;
18425 ds_layout_ci.bindingCount = 1;
18426 ds_layout_ci.pBindings = &dsl_binding;
18427 VkDescriptorSetLayout ds_layout;
18428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18429 ASSERT_VK_SUCCESS(err);
18430
18431 VkDescriptorSet descriptor_set;
18432 VkDescriptorSetAllocateInfo alloc_info = {};
18433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18434 alloc_info.descriptorSetCount = 1;
18435 alloc_info.descriptorPool = ds_pool;
18436 alloc_info.pSetLayouts = &ds_layout;
18437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18438 ASSERT_VK_SUCCESS(err);
18439
18440 VkDescriptorBufferInfo buffer_info = {};
18441 buffer_info.buffer = buffer;
18442 buffer_info.offset = 0;
18443 buffer_info.range = 1024;
18444
18445 VkWriteDescriptorSet descriptor_write;
18446 memset(&descriptor_write, 0, sizeof(descriptor_write));
18447 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18448 descriptor_write.dstSet = descriptor_set;
18449 descriptor_write.dstBinding = 0;
18450 descriptor_write.descriptorCount = 1;
18451 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18452 descriptor_write.pBufferInfo = &buffer_info;
18453
18454 // Set pImageInfo and pTexelBufferView to invalid values, which should
18455 // be
18456 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18457 // This will most likely produce a crash if the parameter_validation
18458 // layer
18459 // does not correctly ignore pImageInfo.
18460 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18461 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18462
18463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18464
18465 m_errorMonitor->VerifyNotFound();
18466
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018467 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18468 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18469 vkDestroyBuffer(m_device->device(), buffer, NULL);
18470 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18471 }
18472
18473 // Texel Buffer Case
18474 {
18475 m_errorMonitor->ExpectSuccess();
18476
18477 VkBuffer buffer;
18478 uint32_t queue_family_index = 0;
18479 VkBufferCreateInfo buffer_create_info = {};
18480 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18481 buffer_create_info.size = 1024;
18482 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18483 buffer_create_info.queueFamilyIndexCount = 1;
18484 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18485
18486 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18487 ASSERT_VK_SUCCESS(err);
18488
18489 VkMemoryRequirements memory_reqs;
18490 VkDeviceMemory buffer_memory;
18491 bool pass;
18492 VkMemoryAllocateInfo memory_info = {};
18493 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18494 memory_info.pNext = NULL;
18495 memory_info.allocationSize = 0;
18496 memory_info.memoryTypeIndex = 0;
18497
18498 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18499 memory_info.allocationSize = memory_reqs.size;
18500 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18501 ASSERT_TRUE(pass);
18502
18503 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18504 ASSERT_VK_SUCCESS(err);
18505 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18506 ASSERT_VK_SUCCESS(err);
18507
18508 VkBufferViewCreateInfo buff_view_ci = {};
18509 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18510 buff_view_ci.buffer = buffer;
18511 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18512 buff_view_ci.range = VK_WHOLE_SIZE;
18513 VkBufferView buffer_view;
18514 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18515
18516 VkDescriptorPoolSize ds_type_count = {};
18517 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18518 ds_type_count.descriptorCount = 1;
18519
18520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18522 ds_pool_ci.pNext = NULL;
18523 ds_pool_ci.maxSets = 1;
18524 ds_pool_ci.poolSizeCount = 1;
18525 ds_pool_ci.pPoolSizes = &ds_type_count;
18526
18527 VkDescriptorPool ds_pool;
18528 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18529 ASSERT_VK_SUCCESS(err);
18530
18531 VkDescriptorSetLayoutBinding dsl_binding = {};
18532 dsl_binding.binding = 0;
18533 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18534 dsl_binding.descriptorCount = 1;
18535 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18536 dsl_binding.pImmutableSamplers = NULL;
18537
18538 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18539 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18540 ds_layout_ci.pNext = NULL;
18541 ds_layout_ci.bindingCount = 1;
18542 ds_layout_ci.pBindings = &dsl_binding;
18543 VkDescriptorSetLayout ds_layout;
18544 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18545 ASSERT_VK_SUCCESS(err);
18546
18547 VkDescriptorSet descriptor_set;
18548 VkDescriptorSetAllocateInfo alloc_info = {};
18549 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18550 alloc_info.descriptorSetCount = 1;
18551 alloc_info.descriptorPool = ds_pool;
18552 alloc_info.pSetLayouts = &ds_layout;
18553 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18554 ASSERT_VK_SUCCESS(err);
18555
18556 VkWriteDescriptorSet descriptor_write;
18557 memset(&descriptor_write, 0, sizeof(descriptor_write));
18558 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18559 descriptor_write.dstSet = descriptor_set;
18560 descriptor_write.dstBinding = 0;
18561 descriptor_write.descriptorCount = 1;
18562 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18563 descriptor_write.pTexelBufferView = &buffer_view;
18564
18565 // Set pImageInfo and pBufferInfo to invalid values, which should be
18566 // ignored for descriptorType ==
18567 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18568 // This will most likely produce a crash if the parameter_validation
18569 // layer
18570 // does not correctly ignore pImageInfo and pBufferInfo.
18571 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18572 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18573
18574 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18575
18576 m_errorMonitor->VerifyNotFound();
18577
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018578 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18579 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18580 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18581 vkDestroyBuffer(m_device->device(), buffer, NULL);
18582 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18583 }
18584}
18585
Tobin Ehlisf7428442016-10-25 07:58:24 -060018586TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18587 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18588
18589 ASSERT_NO_FATAL_FAILURE(InitState());
18590 // Create layout where two binding #s are "1"
18591 static const uint32_t NUM_BINDINGS = 3;
18592 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18593 dsl_binding[0].binding = 1;
18594 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18595 dsl_binding[0].descriptorCount = 1;
18596 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18597 dsl_binding[0].pImmutableSamplers = NULL;
18598 dsl_binding[1].binding = 0;
18599 dsl_binding[1].descriptorCount = 1;
18600 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18601 dsl_binding[1].descriptorCount = 1;
18602 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18603 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018604 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018605 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18606 dsl_binding[2].descriptorCount = 1;
18607 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18608 dsl_binding[2].pImmutableSamplers = NULL;
18609
18610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18612 ds_layout_ci.pNext = NULL;
18613 ds_layout_ci.bindingCount = NUM_BINDINGS;
18614 ds_layout_ci.pBindings = dsl_binding;
18615 VkDescriptorSetLayout ds_layout;
18616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18617 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18618 m_errorMonitor->VerifyFound();
18619}
18620
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018621TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018622 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18623
18624 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018625
Tony Barbour552f6c02016-12-21 14:34:07 -070018626 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018627
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018628 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18629
18630 {
18631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18632 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18633 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18634 m_errorMonitor->VerifyFound();
18635 }
18636
18637 {
18638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18639 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18640 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18641 m_errorMonitor->VerifyFound();
18642 }
18643
18644 {
18645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18646 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18647 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18648 m_errorMonitor->VerifyFound();
18649 }
18650
18651 {
18652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18653 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18654 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18655 m_errorMonitor->VerifyFound();
18656 }
18657
18658 {
18659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18660 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18661 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18662 m_errorMonitor->VerifyFound();
18663 }
18664
18665 {
18666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18667 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18668 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18669 m_errorMonitor->VerifyFound();
18670 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018671
18672 {
18673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18674 VkRect2D scissor = {{-1, 0}, {16, 16}};
18675 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18676 m_errorMonitor->VerifyFound();
18677 }
18678
18679 {
18680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18681 VkRect2D scissor = {{0, -2}, {16, 16}};
18682 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18683 m_errorMonitor->VerifyFound();
18684 }
18685
18686 {
18687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18688 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18689 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18690 m_errorMonitor->VerifyFound();
18691 }
18692
18693 {
18694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18695 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18696 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18697 m_errorMonitor->VerifyFound();
18698 }
18699
Tony Barbour552f6c02016-12-21 14:34:07 -070018700 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018701}
18702
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018703// This is a positive test. No failures are expected.
18704TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18705 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18706 VkResult err;
18707
18708 ASSERT_NO_FATAL_FAILURE(InitState());
18709 m_errorMonitor->ExpectSuccess();
18710 VkDescriptorPoolSize ds_type_count = {};
18711 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18712 ds_type_count.descriptorCount = 2;
18713
18714 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18715 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18716 ds_pool_ci.pNext = NULL;
18717 ds_pool_ci.maxSets = 1;
18718 ds_pool_ci.poolSizeCount = 1;
18719 ds_pool_ci.pPoolSizes = &ds_type_count;
18720
18721 VkDescriptorPool ds_pool;
18722 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18723 ASSERT_VK_SUCCESS(err);
18724
18725 // Create layout with two uniform buffer descriptors w/ empty binding between them
18726 static const uint32_t NUM_BINDINGS = 3;
18727 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18728 dsl_binding[0].binding = 0;
18729 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18730 dsl_binding[0].descriptorCount = 1;
18731 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18732 dsl_binding[0].pImmutableSamplers = NULL;
18733 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018734 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018735 dsl_binding[2].binding = 2;
18736 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18737 dsl_binding[2].descriptorCount = 1;
18738 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18739 dsl_binding[2].pImmutableSamplers = NULL;
18740
18741 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18742 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18743 ds_layout_ci.pNext = NULL;
18744 ds_layout_ci.bindingCount = NUM_BINDINGS;
18745 ds_layout_ci.pBindings = dsl_binding;
18746 VkDescriptorSetLayout ds_layout;
18747 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18748 ASSERT_VK_SUCCESS(err);
18749
18750 VkDescriptorSet descriptor_set = {};
18751 VkDescriptorSetAllocateInfo alloc_info = {};
18752 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18753 alloc_info.descriptorSetCount = 1;
18754 alloc_info.descriptorPool = ds_pool;
18755 alloc_info.pSetLayouts = &ds_layout;
18756 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18757 ASSERT_VK_SUCCESS(err);
18758
18759 // Create a buffer to be used for update
18760 VkBufferCreateInfo buff_ci = {};
18761 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18762 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18763 buff_ci.size = 256;
18764 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18765 VkBuffer buffer;
18766 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18767 ASSERT_VK_SUCCESS(err);
18768 // Have to bind memory to buffer before descriptor update
18769 VkMemoryAllocateInfo mem_alloc = {};
18770 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18771 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018772 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018773 mem_alloc.memoryTypeIndex = 0;
18774
18775 VkMemoryRequirements mem_reqs;
18776 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18777 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18778 if (!pass) {
18779 vkDestroyBuffer(m_device->device(), buffer, NULL);
18780 return;
18781 }
18782
18783 VkDeviceMemory mem;
18784 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18785 ASSERT_VK_SUCCESS(err);
18786 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18787 ASSERT_VK_SUCCESS(err);
18788
18789 // Only update the descriptor at binding 2
18790 VkDescriptorBufferInfo buff_info = {};
18791 buff_info.buffer = buffer;
18792 buff_info.offset = 0;
18793 buff_info.range = VK_WHOLE_SIZE;
18794 VkWriteDescriptorSet descriptor_write = {};
18795 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18796 descriptor_write.dstBinding = 2;
18797 descriptor_write.descriptorCount = 1;
18798 descriptor_write.pTexelBufferView = nullptr;
18799 descriptor_write.pBufferInfo = &buff_info;
18800 descriptor_write.pImageInfo = nullptr;
18801 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18802 descriptor_write.dstSet = descriptor_set;
18803
18804 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18805
18806 m_errorMonitor->VerifyNotFound();
18807 // Cleanup
18808 vkFreeMemory(m_device->device(), mem, NULL);
18809 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18810 vkDestroyBuffer(m_device->device(), buffer, NULL);
18811 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18812}
18813
18814// This is a positive test. No failures are expected.
18815TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18816 VkResult err;
18817 bool pass;
18818
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018819 TEST_DESCRIPTION(
18820 "Create a buffer, allocate memory, bind memory, destroy "
18821 "the buffer, create an image, and bind the same memory to "
18822 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018823
18824 m_errorMonitor->ExpectSuccess();
18825
18826 ASSERT_NO_FATAL_FAILURE(InitState());
18827
18828 VkBuffer buffer;
18829 VkImage image;
18830 VkDeviceMemory mem;
18831 VkMemoryRequirements mem_reqs;
18832
18833 VkBufferCreateInfo buf_info = {};
18834 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18835 buf_info.pNext = NULL;
18836 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18837 buf_info.size = 256;
18838 buf_info.queueFamilyIndexCount = 0;
18839 buf_info.pQueueFamilyIndices = NULL;
18840 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18841 buf_info.flags = 0;
18842 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18843 ASSERT_VK_SUCCESS(err);
18844
18845 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18846
18847 VkMemoryAllocateInfo alloc_info = {};
18848 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18849 alloc_info.pNext = NULL;
18850 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018851
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018852 // Ensure memory is big enough for both bindings
18853 alloc_info.allocationSize = 0x10000;
18854
18855 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18856 if (!pass) {
18857 vkDestroyBuffer(m_device->device(), buffer, NULL);
18858 return;
18859 }
18860
18861 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18862 ASSERT_VK_SUCCESS(err);
18863
18864 uint8_t *pData;
18865 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18866 ASSERT_VK_SUCCESS(err);
18867
18868 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18869
18870 vkUnmapMemory(m_device->device(), mem);
18871
18872 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18873 ASSERT_VK_SUCCESS(err);
18874
18875 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18876 // memory. In fact, it was never used by the GPU.
18877 // Just be be sure, wait for idle.
18878 vkDestroyBuffer(m_device->device(), buffer, NULL);
18879 vkDeviceWaitIdle(m_device->device());
18880
Tobin Ehlis6a005702016-12-28 15:25:56 -070018881 // Use optimal as some platforms report linear support but then fail image creation
18882 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18883 VkImageFormatProperties image_format_properties;
18884 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18885 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18886 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018887 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018888 vkFreeMemory(m_device->device(), mem, NULL);
18889 return;
18890 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018891 VkImageCreateInfo image_create_info = {};
18892 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18893 image_create_info.pNext = NULL;
18894 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18895 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18896 image_create_info.extent.width = 64;
18897 image_create_info.extent.height = 64;
18898 image_create_info.extent.depth = 1;
18899 image_create_info.mipLevels = 1;
18900 image_create_info.arrayLayers = 1;
18901 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018902 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018903 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18904 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18905 image_create_info.queueFamilyIndexCount = 0;
18906 image_create_info.pQueueFamilyIndices = NULL;
18907 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18908 image_create_info.flags = 0;
18909
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018910 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018911 * to be textures or it will be the staging image if they are not.
18912 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018913 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18914 ASSERT_VK_SUCCESS(err);
18915
18916 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18917
Tobin Ehlis6a005702016-12-28 15:25:56 -070018918 VkMemoryAllocateInfo mem_alloc = {};
18919 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18920 mem_alloc.pNext = NULL;
18921 mem_alloc.allocationSize = 0;
18922 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018923 mem_alloc.allocationSize = mem_reqs.size;
18924
18925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18926 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018927 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018928 vkDestroyImage(m_device->device(), image, NULL);
18929 return;
18930 }
18931
18932 // VALIDATION FAILURE:
18933 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18934 ASSERT_VK_SUCCESS(err);
18935
18936 m_errorMonitor->VerifyNotFound();
18937
18938 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018939 vkDestroyImage(m_device->device(), image, NULL);
18940}
18941
Tony Barbourab713912017-02-02 14:17:35 -070018942// This is a positive test. No failures are expected.
18943TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18944 VkResult err;
18945
18946 TEST_DESCRIPTION(
18947 "Call all applicable destroy and free routines with NULL"
18948 "handles, expecting no validation errors");
18949
18950 m_errorMonitor->ExpectSuccess();
18951
18952 ASSERT_NO_FATAL_FAILURE(InitState());
18953 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18954 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18955 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18956 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18957 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18958 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18959 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18960 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18961 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18962 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18963 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18964 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18965 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18966 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18967 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18968 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18969 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18970 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18971 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18972 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18973
18974 VkCommandPool command_pool;
18975 VkCommandPoolCreateInfo pool_create_info{};
18976 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18977 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18978 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18979 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18980 VkCommandBuffer command_buffers[3] = {};
18981 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18982 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18983 command_buffer_allocate_info.commandPool = command_pool;
18984 command_buffer_allocate_info.commandBufferCount = 1;
18985 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18986 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18987 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18988 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18989
18990 VkDescriptorPoolSize ds_type_count = {};
18991 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18992 ds_type_count.descriptorCount = 1;
18993
18994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18996 ds_pool_ci.pNext = NULL;
18997 ds_pool_ci.maxSets = 1;
18998 ds_pool_ci.poolSizeCount = 1;
18999 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
19000 ds_pool_ci.pPoolSizes = &ds_type_count;
19001
19002 VkDescriptorPool ds_pool;
19003 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19004 ASSERT_VK_SUCCESS(err);
19005
19006 VkDescriptorSetLayoutBinding dsl_binding = {};
19007 dsl_binding.binding = 2;
19008 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19009 dsl_binding.descriptorCount = 1;
19010 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19011 dsl_binding.pImmutableSamplers = NULL;
19012 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19013 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19014 ds_layout_ci.pNext = NULL;
19015 ds_layout_ci.bindingCount = 1;
19016 ds_layout_ci.pBindings = &dsl_binding;
19017 VkDescriptorSetLayout ds_layout;
19018 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19019 ASSERT_VK_SUCCESS(err);
19020
19021 VkDescriptorSet descriptor_sets[3] = {};
19022 VkDescriptorSetAllocateInfo alloc_info = {};
19023 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19024 alloc_info.descriptorSetCount = 1;
19025 alloc_info.descriptorPool = ds_pool;
19026 alloc_info.pSetLayouts = &ds_layout;
19027 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
19028 ASSERT_VK_SUCCESS(err);
19029 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
19030 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19032
19033 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
19034
19035 m_errorMonitor->VerifyNotFound();
19036}
19037
Tony Barbour626994c2017-02-08 15:29:37 -070019038TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070019039 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070019040
19041 m_errorMonitor->ExpectSuccess();
19042
19043 ASSERT_NO_FATAL_FAILURE(InitState());
19044 VkCommandBuffer cmd_bufs[4];
19045 VkCommandBufferAllocateInfo alloc_info;
19046 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19047 alloc_info.pNext = NULL;
19048 alloc_info.commandBufferCount = 4;
19049 alloc_info.commandPool = m_commandPool;
19050 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19051 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
19052 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -070019053 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
19054 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
19055 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070019056 ASSERT_TRUE(image.initialized());
19057 VkCommandBufferBeginInfo cb_binfo;
19058 cb_binfo.pNext = NULL;
19059 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19060 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
19061 cb_binfo.flags = 0;
19062 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
19063 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
19064 VkImageMemoryBarrier img_barrier = {};
19065 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19066 img_barrier.pNext = NULL;
19067 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19068 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19069 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19070 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
19071 img_barrier.image = image.handle();
19072 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19073 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19074 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19075 img_barrier.subresourceRange.baseArrayLayer = 0;
19076 img_barrier.subresourceRange.baseMipLevel = 0;
19077 img_barrier.subresourceRange.layerCount = 1;
19078 img_barrier.subresourceRange.levelCount = 1;
19079 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19080 &img_barrier);
19081 vkEndCommandBuffer(cmd_bufs[0]);
19082 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
19083 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
19084 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19085 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19086 &img_barrier);
19087 vkEndCommandBuffer(cmd_bufs[1]);
19088 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19089 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19090 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19091 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19092 &img_barrier);
19093 vkEndCommandBuffer(cmd_bufs[2]);
19094 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19095 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19096 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19097 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19098 &img_barrier);
19099 vkEndCommandBuffer(cmd_bufs[3]);
19100
19101 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19102 VkSemaphore semaphore1, semaphore2;
19103 VkSemaphoreCreateInfo semaphore_create_info{};
19104 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19105 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19106 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19107 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19108 VkSubmitInfo submit_info[3];
19109 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19110 submit_info[0].pNext = nullptr;
19111 submit_info[0].commandBufferCount = 1;
19112 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19113 submit_info[0].signalSemaphoreCount = 1;
19114 submit_info[0].pSignalSemaphores = &semaphore1;
19115 submit_info[0].waitSemaphoreCount = 0;
19116 submit_info[0].pWaitDstStageMask = nullptr;
19117 submit_info[0].pWaitDstStageMask = flags;
19118 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19119 submit_info[1].pNext = nullptr;
19120 submit_info[1].commandBufferCount = 1;
19121 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19122 submit_info[1].waitSemaphoreCount = 1;
19123 submit_info[1].pWaitSemaphores = &semaphore1;
19124 submit_info[1].signalSemaphoreCount = 1;
19125 submit_info[1].pSignalSemaphores = &semaphore2;
19126 submit_info[1].pWaitDstStageMask = flags;
19127 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19128 submit_info[2].pNext = nullptr;
19129 submit_info[2].commandBufferCount = 2;
19130 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19131 submit_info[2].waitSemaphoreCount = 1;
19132 submit_info[2].pWaitSemaphores = &semaphore2;
19133 submit_info[2].signalSemaphoreCount = 0;
19134 submit_info[2].pSignalSemaphores = nullptr;
19135 submit_info[2].pWaitDstStageMask = flags;
19136 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19137 vkQueueWaitIdle(m_device->m_queue);
19138
19139 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19140 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19141 m_errorMonitor->VerifyNotFound();
19142}
19143
Tobin Ehlis953e8392016-11-17 10:54:13 -070019144TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19145 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19146 // We previously had a bug where dynamic offset of inactive bindings was still being used
19147 VkResult err;
19148 m_errorMonitor->ExpectSuccess();
19149
19150 ASSERT_NO_FATAL_FAILURE(InitState());
19151 ASSERT_NO_FATAL_FAILURE(InitViewport());
19152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19153
19154 VkDescriptorPoolSize ds_type_count = {};
19155 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19156 ds_type_count.descriptorCount = 3;
19157
19158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19160 ds_pool_ci.pNext = NULL;
19161 ds_pool_ci.maxSets = 1;
19162 ds_pool_ci.poolSizeCount = 1;
19163 ds_pool_ci.pPoolSizes = &ds_type_count;
19164
19165 VkDescriptorPool ds_pool;
19166 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19167 ASSERT_VK_SUCCESS(err);
19168
19169 const uint32_t BINDING_COUNT = 3;
19170 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019171 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019172 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19173 dsl_binding[0].descriptorCount = 1;
19174 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19175 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019176 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019177 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19178 dsl_binding[1].descriptorCount = 1;
19179 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19180 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019181 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019182 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19183 dsl_binding[2].descriptorCount = 1;
19184 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19185 dsl_binding[2].pImmutableSamplers = NULL;
19186
19187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19189 ds_layout_ci.pNext = NULL;
19190 ds_layout_ci.bindingCount = BINDING_COUNT;
19191 ds_layout_ci.pBindings = dsl_binding;
19192 VkDescriptorSetLayout ds_layout;
19193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19194 ASSERT_VK_SUCCESS(err);
19195
19196 VkDescriptorSet descriptor_set;
19197 VkDescriptorSetAllocateInfo alloc_info = {};
19198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19199 alloc_info.descriptorSetCount = 1;
19200 alloc_info.descriptorPool = ds_pool;
19201 alloc_info.pSetLayouts = &ds_layout;
19202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19203 ASSERT_VK_SUCCESS(err);
19204
19205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19207 pipeline_layout_ci.pNext = NULL;
19208 pipeline_layout_ci.setLayoutCount = 1;
19209 pipeline_layout_ci.pSetLayouts = &ds_layout;
19210
19211 VkPipelineLayout pipeline_layout;
19212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19213 ASSERT_VK_SUCCESS(err);
19214
19215 // Create two buffers to update the descriptors with
19216 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19217 uint32_t qfi = 0;
19218 VkBufferCreateInfo buffCI = {};
19219 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19220 buffCI.size = 2048;
19221 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19222 buffCI.queueFamilyIndexCount = 1;
19223 buffCI.pQueueFamilyIndices = &qfi;
19224
19225 VkBuffer dyub1;
19226 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19227 ASSERT_VK_SUCCESS(err);
19228 // buffer2
19229 buffCI.size = 1024;
19230 VkBuffer dyub2;
19231 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19232 ASSERT_VK_SUCCESS(err);
19233 // Allocate memory and bind to buffers
19234 VkMemoryAllocateInfo mem_alloc[2] = {};
19235 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19236 mem_alloc[0].pNext = NULL;
19237 mem_alloc[0].memoryTypeIndex = 0;
19238 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19239 mem_alloc[1].pNext = NULL;
19240 mem_alloc[1].memoryTypeIndex = 0;
19241
19242 VkMemoryRequirements mem_reqs1;
19243 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19244 VkMemoryRequirements mem_reqs2;
19245 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19246 mem_alloc[0].allocationSize = mem_reqs1.size;
19247 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19248 mem_alloc[1].allocationSize = mem_reqs2.size;
19249 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19250 if (!pass) {
19251 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19252 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19253 return;
19254 }
19255
19256 VkDeviceMemory mem1;
19257 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19258 ASSERT_VK_SUCCESS(err);
19259 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19260 ASSERT_VK_SUCCESS(err);
19261 VkDeviceMemory mem2;
19262 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19263 ASSERT_VK_SUCCESS(err);
19264 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19265 ASSERT_VK_SUCCESS(err);
19266 // Update descriptors
19267 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19268 buff_info[0].buffer = dyub1;
19269 buff_info[0].offset = 0;
19270 buff_info[0].range = 256;
19271 buff_info[1].buffer = dyub1;
19272 buff_info[1].offset = 256;
19273 buff_info[1].range = 512;
19274 buff_info[2].buffer = dyub2;
19275 buff_info[2].offset = 0;
19276 buff_info[2].range = 512;
19277
19278 VkWriteDescriptorSet descriptor_write;
19279 memset(&descriptor_write, 0, sizeof(descriptor_write));
19280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19281 descriptor_write.dstSet = descriptor_set;
19282 descriptor_write.dstBinding = 0;
19283 descriptor_write.descriptorCount = BINDING_COUNT;
19284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19285 descriptor_write.pBufferInfo = buff_info;
19286
19287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19288
Tony Barbour552f6c02016-12-21 14:34:07 -070019289 m_commandBuffer->BeginCommandBuffer();
19290 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019291
19292 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019293 char const *vsSource =
19294 "#version 450\n"
19295 "\n"
19296 "out gl_PerVertex { \n"
19297 " vec4 gl_Position;\n"
19298 "};\n"
19299 "void main(){\n"
19300 " gl_Position = vec4(1);\n"
19301 "}\n";
19302 char const *fsSource =
19303 "#version 450\n"
19304 "\n"
19305 "layout(location=0) out vec4 x;\n"
19306 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19307 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19308 "void main(){\n"
19309 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19310 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019311 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19312 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19313 VkPipelineObj pipe(m_device);
19314 pipe.SetViewport(m_viewports);
19315 pipe.SetScissor(m_scissors);
19316 pipe.AddShader(&vs);
19317 pipe.AddShader(&fs);
19318 pipe.AddColorAttachment();
19319 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19320
19321 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19322 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19323 // we used to have a bug in this case.
19324 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19325 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19326 &descriptor_set, BINDING_COUNT, dyn_off);
19327 Draw(1, 0, 0, 0);
19328 m_errorMonitor->VerifyNotFound();
19329
19330 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19331 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19332 vkFreeMemory(m_device->device(), mem1, NULL);
19333 vkFreeMemory(m_device->device(), mem2, NULL);
19334
19335 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19336 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19337 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19338}
19339
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019340TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019341 TEST_DESCRIPTION(
19342 "Ensure that validations handling of non-coherent memory "
19343 "mapping while using VK_WHOLE_SIZE does not cause access "
19344 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019345 VkResult err;
19346 uint8_t *pData;
19347 ASSERT_NO_FATAL_FAILURE(InitState());
19348
19349 VkDeviceMemory mem;
19350 VkMemoryRequirements mem_reqs;
19351 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019352 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019353 VkMemoryAllocateInfo alloc_info = {};
19354 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19355 alloc_info.pNext = NULL;
19356 alloc_info.memoryTypeIndex = 0;
19357
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019358 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019359 alloc_info.allocationSize = allocation_size;
19360
19361 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19362 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 -070019363 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019364 if (!pass) {
19365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019366 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19367 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019368 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019369 pass = m_device->phy().set_memory_type(
19370 mem_reqs.memoryTypeBits, &alloc_info,
19371 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19372 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019373 if (!pass) {
19374 return;
19375 }
19376 }
19377 }
19378
19379 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19380 ASSERT_VK_SUCCESS(err);
19381
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019382 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019383 m_errorMonitor->ExpectSuccess();
19384 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19385 ASSERT_VK_SUCCESS(err);
19386 VkMappedMemoryRange mmr = {};
19387 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19388 mmr.memory = mem;
19389 mmr.offset = 0;
19390 mmr.size = VK_WHOLE_SIZE;
19391 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19392 ASSERT_VK_SUCCESS(err);
19393 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19394 ASSERT_VK_SUCCESS(err);
19395 m_errorMonitor->VerifyNotFound();
19396 vkUnmapMemory(m_device->device(), mem);
19397
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019398 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019399 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019400 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019401 ASSERT_VK_SUCCESS(err);
19402 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19403 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019404 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019405 mmr.size = VK_WHOLE_SIZE;
19406 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19407 ASSERT_VK_SUCCESS(err);
19408 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19409 ASSERT_VK_SUCCESS(err);
19410 m_errorMonitor->VerifyNotFound();
19411 vkUnmapMemory(m_device->device(), mem);
19412
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019413 // Map with offset and size
19414 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019415 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019416 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019417 ASSERT_VK_SUCCESS(err);
19418 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19419 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019420 mmr.offset = 4 * atom_size;
19421 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019422 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19423 ASSERT_VK_SUCCESS(err);
19424 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19425 ASSERT_VK_SUCCESS(err);
19426 m_errorMonitor->VerifyNotFound();
19427 vkUnmapMemory(m_device->device(), mem);
19428
19429 // Map without offset and flush WHOLE_SIZE with two separate offsets
19430 m_errorMonitor->ExpectSuccess();
19431 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19432 ASSERT_VK_SUCCESS(err);
19433 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19434 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019435 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436 mmr.size = VK_WHOLE_SIZE;
19437 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19438 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019439 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019440 mmr.size = VK_WHOLE_SIZE;
19441 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19442 ASSERT_VK_SUCCESS(err);
19443 m_errorMonitor->VerifyNotFound();
19444 vkUnmapMemory(m_device->device(), mem);
19445
19446 vkFreeMemory(m_device->device(), mem, NULL);
19447}
19448
19449// This is a positive test. We used to expect error in this case but spec now allows it
19450TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19451 m_errorMonitor->ExpectSuccess();
19452 vk_testing::Fence testFence;
19453 VkFenceCreateInfo fenceInfo = {};
19454 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19455 fenceInfo.pNext = NULL;
19456
19457 ASSERT_NO_FATAL_FAILURE(InitState());
19458 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019459 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019460 VkResult result = vkResetFences(m_device->device(), 1, fences);
19461 ASSERT_VK_SUCCESS(result);
19462
19463 m_errorMonitor->VerifyNotFound();
19464}
19465
19466TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19467 m_errorMonitor->ExpectSuccess();
19468
19469 ASSERT_NO_FATAL_FAILURE(InitState());
19470 VkResult err;
19471
19472 // Record (empty!) command buffer that can be submitted multiple times
19473 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019474 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19475 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019476 m_commandBuffer->BeginCommandBuffer(&cbbi);
19477 m_commandBuffer->EndCommandBuffer();
19478
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019479 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019480 VkFence fence;
19481 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19482 ASSERT_VK_SUCCESS(err);
19483
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019484 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019485 VkSemaphore s1, s2;
19486 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19487 ASSERT_VK_SUCCESS(err);
19488 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19489 ASSERT_VK_SUCCESS(err);
19490
19491 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019492 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019493 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19494 ASSERT_VK_SUCCESS(err);
19495
19496 // Submit CB again, signaling s2.
19497 si.pSignalSemaphores = &s2;
19498 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19499 ASSERT_VK_SUCCESS(err);
19500
19501 // Wait for fence.
19502 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19503 ASSERT_VK_SUCCESS(err);
19504
19505 // CB is still in flight from second submission, but semaphore s1 is no
19506 // longer in flight. delete it.
19507 vkDestroySemaphore(m_device->device(), s1, nullptr);
19508
19509 m_errorMonitor->VerifyNotFound();
19510
19511 // Force device idle and clean up remaining objects
19512 vkDeviceWaitIdle(m_device->device());
19513 vkDestroySemaphore(m_device->device(), s2, nullptr);
19514 vkDestroyFence(m_device->device(), fence, nullptr);
19515}
19516
19517TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19518 m_errorMonitor->ExpectSuccess();
19519
19520 ASSERT_NO_FATAL_FAILURE(InitState());
19521 VkResult err;
19522
19523 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019524 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019525 VkFence f1;
19526 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19527 ASSERT_VK_SUCCESS(err);
19528
19529 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019530 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019531 VkFence f2;
19532 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19533 ASSERT_VK_SUCCESS(err);
19534
19535 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019536 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019537 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19538
19539 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019540 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019541 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19542
19543 // Should have both retired!
19544 vkDestroyFence(m_device->device(), f1, nullptr);
19545 vkDestroyFence(m_device->device(), f2, nullptr);
19546
19547 m_errorMonitor->VerifyNotFound();
19548}
19549
19550TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019551 TEST_DESCRIPTION(
19552 "Verify that creating an image view from an image with valid usage "
19553 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019554
19555 ASSERT_NO_FATAL_FAILURE(InitState());
19556
19557 m_errorMonitor->ExpectSuccess();
19558 // Verify that we can create a view with usage INPUT_ATTACHMENT
19559 VkImageObj image(m_device);
19560 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19561 ASSERT_TRUE(image.initialized());
19562 VkImageView imageView;
19563 VkImageViewCreateInfo ivci = {};
19564 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19565 ivci.image = image.handle();
19566 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19567 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19568 ivci.subresourceRange.layerCount = 1;
19569 ivci.subresourceRange.baseMipLevel = 0;
19570 ivci.subresourceRange.levelCount = 1;
19571 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19572
19573 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19574 m_errorMonitor->VerifyNotFound();
19575 vkDestroyImageView(m_device->device(), imageView, NULL);
19576}
19577
19578// This is a positive test. No failures are expected.
19579TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019580 TEST_DESCRIPTION(
19581 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19582 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019583
19584 ASSERT_NO_FATAL_FAILURE(InitState());
19585
19586 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019587 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019588
19589 m_errorMonitor->ExpectSuccess();
19590
19591 VkImage image;
19592 VkImageCreateInfo image_create_info = {};
19593 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19594 image_create_info.pNext = NULL;
19595 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19596 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19597 image_create_info.extent.width = 64;
19598 image_create_info.extent.height = 64;
19599 image_create_info.extent.depth = 1;
19600 image_create_info.mipLevels = 1;
19601 image_create_info.arrayLayers = 1;
19602 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19603 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19604 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19605 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19606 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19607 ASSERT_VK_SUCCESS(err);
19608
19609 VkMemoryRequirements memory_reqs;
19610 VkDeviceMemory memory_one, memory_two;
19611 bool pass;
19612 VkMemoryAllocateInfo memory_info = {};
19613 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19614 memory_info.pNext = NULL;
19615 memory_info.allocationSize = 0;
19616 memory_info.memoryTypeIndex = 0;
19617 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19618 // Find an image big enough to allow sparse mapping of 2 memory regions
19619 // Increase the image size until it is at least twice the
19620 // size of the required alignment, to ensure we can bind both
19621 // allocated memory blocks to the image on aligned offsets.
19622 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19623 vkDestroyImage(m_device->device(), image, nullptr);
19624 image_create_info.extent.width *= 2;
19625 image_create_info.extent.height *= 2;
19626 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19627 ASSERT_VK_SUCCESS(err);
19628 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19629 }
19630 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19631 // at the end of the first
19632 memory_info.allocationSize = memory_reqs.alignment;
19633 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19634 ASSERT_TRUE(pass);
19635 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19636 ASSERT_VK_SUCCESS(err);
19637 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19638 ASSERT_VK_SUCCESS(err);
19639 VkSparseMemoryBind binds[2];
19640 binds[0].flags = 0;
19641 binds[0].memory = memory_one;
19642 binds[0].memoryOffset = 0;
19643 binds[0].resourceOffset = 0;
19644 binds[0].size = memory_info.allocationSize;
19645 binds[1].flags = 0;
19646 binds[1].memory = memory_two;
19647 binds[1].memoryOffset = 0;
19648 binds[1].resourceOffset = memory_info.allocationSize;
19649 binds[1].size = memory_info.allocationSize;
19650
19651 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19652 opaqueBindInfo.image = image;
19653 opaqueBindInfo.bindCount = 2;
19654 opaqueBindInfo.pBinds = binds;
19655
19656 VkFence fence = VK_NULL_HANDLE;
19657 VkBindSparseInfo bindSparseInfo = {};
19658 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19659 bindSparseInfo.imageOpaqueBindCount = 1;
19660 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19661
19662 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19663 vkQueueWaitIdle(m_device->m_queue);
19664 vkDestroyImage(m_device->device(), image, NULL);
19665 vkFreeMemory(m_device->device(), memory_one, NULL);
19666 vkFreeMemory(m_device->device(), memory_two, NULL);
19667 m_errorMonitor->VerifyNotFound();
19668}
19669
19670TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019671 TEST_DESCRIPTION(
19672 "Ensure that CmdBeginRenderPass with an attachment's "
19673 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19674 "the command buffer has prior knowledge of that "
19675 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019676
19677 m_errorMonitor->ExpectSuccess();
19678
19679 ASSERT_NO_FATAL_FAILURE(InitState());
19680
19681 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019682 VkAttachmentDescription attachment = {0,
19683 VK_FORMAT_R8G8B8A8_UNORM,
19684 VK_SAMPLE_COUNT_1_BIT,
19685 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19686 VK_ATTACHMENT_STORE_OP_STORE,
19687 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19688 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19689 VK_IMAGE_LAYOUT_UNDEFINED,
19690 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019691
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019692 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019693
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019694 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019695
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019696 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019697
19698 VkRenderPass rp;
19699 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19700 ASSERT_VK_SUCCESS(err);
19701
19702 // A compatible framebuffer.
19703 VkImageObj image(m_device);
19704 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19705 ASSERT_TRUE(image.initialized());
19706
19707 VkImageViewCreateInfo ivci = {
19708 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19709 nullptr,
19710 0,
19711 image.handle(),
19712 VK_IMAGE_VIEW_TYPE_2D,
19713 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019714 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19715 VK_COMPONENT_SWIZZLE_IDENTITY},
19716 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019717 };
19718 VkImageView view;
19719 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19720 ASSERT_VK_SUCCESS(err);
19721
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019722 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019723 VkFramebuffer fb;
19724 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19725 ASSERT_VK_SUCCESS(err);
19726
19727 // Record a single command buffer which uses this renderpass twice. The
19728 // bug is triggered at the beginning of the second renderpass, when the
19729 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019730 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 -070019731 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019732 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19733 vkCmdEndRenderPass(m_commandBuffer->handle());
19734 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19735
19736 m_errorMonitor->VerifyNotFound();
19737
19738 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019739 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019740
19741 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19742 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19743 vkDestroyImageView(m_device->device(), view, nullptr);
19744}
19745
19746TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019747 TEST_DESCRIPTION(
19748 "This test should pass. Create a Framebuffer and "
19749 "command buffer, bind them together, then destroy "
19750 "command pool and framebuffer and verify there are no "
19751 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019752
19753 m_errorMonitor->ExpectSuccess();
19754
19755 ASSERT_NO_FATAL_FAILURE(InitState());
19756
19757 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019758 VkAttachmentDescription attachment = {0,
19759 VK_FORMAT_R8G8B8A8_UNORM,
19760 VK_SAMPLE_COUNT_1_BIT,
19761 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19762 VK_ATTACHMENT_STORE_OP_STORE,
19763 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19764 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19765 VK_IMAGE_LAYOUT_UNDEFINED,
19766 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019767
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019768 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019770 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019771
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019772 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019773
19774 VkRenderPass rp;
19775 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19776 ASSERT_VK_SUCCESS(err);
19777
19778 // A compatible framebuffer.
19779 VkImageObj image(m_device);
19780 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19781 ASSERT_TRUE(image.initialized());
19782
19783 VkImageViewCreateInfo ivci = {
19784 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19785 nullptr,
19786 0,
19787 image.handle(),
19788 VK_IMAGE_VIEW_TYPE_2D,
19789 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019790 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19791 VK_COMPONENT_SWIZZLE_IDENTITY},
19792 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019793 };
19794 VkImageView view;
19795 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19796 ASSERT_VK_SUCCESS(err);
19797
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019798 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019799 VkFramebuffer fb;
19800 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19801 ASSERT_VK_SUCCESS(err);
19802
19803 // Explicitly create a command buffer to bind the FB to so that we can then
19804 // destroy the command pool in order to implicitly free command buffer
19805 VkCommandPool command_pool;
19806 VkCommandPoolCreateInfo pool_create_info{};
19807 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19808 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19809 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19810 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19811
19812 VkCommandBuffer command_buffer;
19813 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19814 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19815 command_buffer_allocate_info.commandPool = command_pool;
19816 command_buffer_allocate_info.commandBufferCount = 1;
19817 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19818 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19819
19820 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019821 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 -060019822 VkCommandBufferBeginInfo begin_info{};
19823 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19824 vkBeginCommandBuffer(command_buffer, &begin_info);
19825
19826 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19827 vkCmdEndRenderPass(command_buffer);
19828 vkEndCommandBuffer(command_buffer);
19829 vkDestroyImageView(m_device->device(), view, nullptr);
19830 // Destroy command pool to implicitly free command buffer
19831 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19832 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19833 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19834 m_errorMonitor->VerifyNotFound();
19835}
19836
19837TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019838 TEST_DESCRIPTION(
19839 "Ensure that CmdBeginRenderPass applies the layout "
19840 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019841
19842 m_errorMonitor->ExpectSuccess();
19843
19844 ASSERT_NO_FATAL_FAILURE(InitState());
19845
19846 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019847 VkAttachmentDescription attachment = {0,
19848 VK_FORMAT_R8G8B8A8_UNORM,
19849 VK_SAMPLE_COUNT_1_BIT,
19850 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19851 VK_ATTACHMENT_STORE_OP_STORE,
19852 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19853 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19854 VK_IMAGE_LAYOUT_UNDEFINED,
19855 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019856
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019857 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019858
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019859 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019860
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019861 VkSubpassDependency dep = {0,
19862 0,
19863 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19864 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19865 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19866 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19867 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019868
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019869 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019870
19871 VkResult err;
19872 VkRenderPass rp;
19873 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19874 ASSERT_VK_SUCCESS(err);
19875
19876 // A compatible framebuffer.
19877 VkImageObj image(m_device);
19878 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19879 ASSERT_TRUE(image.initialized());
19880
19881 VkImageViewCreateInfo ivci = {
19882 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19883 nullptr,
19884 0,
19885 image.handle(),
19886 VK_IMAGE_VIEW_TYPE_2D,
19887 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019888 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19889 VK_COMPONENT_SWIZZLE_IDENTITY},
19890 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019891 };
19892 VkImageView view;
19893 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19894 ASSERT_VK_SUCCESS(err);
19895
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019896 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019897 VkFramebuffer fb;
19898 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19899 ASSERT_VK_SUCCESS(err);
19900
19901 // Record a single command buffer which issues a pipeline barrier w/
19902 // image memory barrier for the attachment. This detects the previously
19903 // missing tracking of the subpass layout by throwing a validation error
19904 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019905 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 -070019906 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019907 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19908
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019909 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19910 nullptr,
19911 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19912 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19913 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19914 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19915 VK_QUEUE_FAMILY_IGNORED,
19916 VK_QUEUE_FAMILY_IGNORED,
19917 image.handle(),
19918 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019919 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019920 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19921 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019922
19923 vkCmdEndRenderPass(m_commandBuffer->handle());
19924 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019925 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019926
19927 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19928 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19929 vkDestroyImageView(m_device->device(), view, nullptr);
19930}
19931
19932TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019933 TEST_DESCRIPTION(
19934 "Validate that when an imageView of a depth/stencil image "
19935 "is used as a depth/stencil framebuffer attachment, the "
19936 "aspectMask is ignored and both depth and stencil image "
19937 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019938
19939 VkFormatProperties format_properties;
19940 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19941 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19942 return;
19943 }
19944
19945 m_errorMonitor->ExpectSuccess();
19946
19947 ASSERT_NO_FATAL_FAILURE(InitState());
19948
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019949 VkAttachmentDescription attachment = {0,
19950 VK_FORMAT_D32_SFLOAT_S8_UINT,
19951 VK_SAMPLE_COUNT_1_BIT,
19952 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19953 VK_ATTACHMENT_STORE_OP_STORE,
19954 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19955 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19956 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19957 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019958
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019959 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019960
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019961 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019962
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019963 VkSubpassDependency dep = {0,
19964 0,
19965 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19966 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19967 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19968 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19969 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019970
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019971 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019972
19973 VkResult err;
19974 VkRenderPass rp;
19975 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19976 ASSERT_VK_SUCCESS(err);
19977
19978 VkImageObj image(m_device);
19979 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019980 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019981 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982 ASSERT_TRUE(image.initialized());
19983 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19984
19985 VkImageViewCreateInfo ivci = {
19986 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19987 nullptr,
19988 0,
19989 image.handle(),
19990 VK_IMAGE_VIEW_TYPE_2D,
19991 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019992 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19993 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019994 };
19995 VkImageView view;
19996 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19997 ASSERT_VK_SUCCESS(err);
19998
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019999 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020000 VkFramebuffer fb;
20001 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20002 ASSERT_VK_SUCCESS(err);
20003
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020004 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 -070020005 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020006 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20007
20008 VkImageMemoryBarrier imb = {};
20009 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20010 imb.pNext = nullptr;
20011 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20012 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20013 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20014 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
20015 imb.srcQueueFamilyIndex = 0;
20016 imb.dstQueueFamilyIndex = 0;
20017 imb.image = image.handle();
20018 imb.subresourceRange.aspectMask = 0x6;
20019 imb.subresourceRange.baseMipLevel = 0;
20020 imb.subresourceRange.levelCount = 0x1;
20021 imb.subresourceRange.baseArrayLayer = 0;
20022 imb.subresourceRange.layerCount = 0x1;
20023
20024 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020025 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
20026 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020027
20028 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070020029 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020030 QueueCommandBuffer(false);
20031 m_errorMonitor->VerifyNotFound();
20032
20033 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20034 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20035 vkDestroyImageView(m_device->device(), view, nullptr);
20036}
20037
20038TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020039 TEST_DESCRIPTION(
20040 "Ensure that layout transitions work correctly without "
20041 "errors, when an attachment reference is "
20042 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020043
20044 m_errorMonitor->ExpectSuccess();
20045
20046 ASSERT_NO_FATAL_FAILURE(InitState());
20047
20048 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020049 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020050
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020051 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020052
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020053 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020054
20055 VkRenderPass rp;
20056 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20057 ASSERT_VK_SUCCESS(err);
20058
20059 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020060 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020061 VkFramebuffer fb;
20062 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20063 ASSERT_VK_SUCCESS(err);
20064
20065 // Record a command buffer which just begins and ends the renderpass. The
20066 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020067 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 -070020068 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20070 vkCmdEndRenderPass(m_commandBuffer->handle());
20071 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070020072 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020073
20074 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20075 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20076}
20077
20078// This is a positive test. No errors are expected.
20079TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020080 TEST_DESCRIPTION(
20081 "Create a stencil-only attachment with a LOAD_OP set to "
20082 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020083 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070020084 ASSERT_NO_FATAL_FAILURE(InitState());
20085 auto depth_format = find_depth_stencil_format(m_device);
20086 if (!depth_format) {
20087 printf(" No Depth + Stencil format found. Skipped.\n");
20088 return;
20089 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020090 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020091 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020092 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20093 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020094 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20095 return;
20096 }
20097
Tony Barbourf887b162017-03-09 10:06:46 -070020098 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020099 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020100 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020101 VkAttachmentDescription att = {};
20102 VkAttachmentReference ref = {};
20103 att.format = depth_stencil_fmt;
20104 att.samples = VK_SAMPLE_COUNT_1_BIT;
20105 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20106 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20107 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20108 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20109 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20110 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20111
20112 VkClearValue clear;
20113 clear.depthStencil.depth = 1.0;
20114 clear.depthStencil.stencil = 0;
20115 ref.attachment = 0;
20116 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20117
20118 VkSubpassDescription subpass = {};
20119 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20120 subpass.flags = 0;
20121 subpass.inputAttachmentCount = 0;
20122 subpass.pInputAttachments = NULL;
20123 subpass.colorAttachmentCount = 0;
20124 subpass.pColorAttachments = NULL;
20125 subpass.pResolveAttachments = NULL;
20126 subpass.pDepthStencilAttachment = &ref;
20127 subpass.preserveAttachmentCount = 0;
20128 subpass.pPreserveAttachments = NULL;
20129
20130 VkRenderPass rp;
20131 VkRenderPassCreateInfo rp_info = {};
20132 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20133 rp_info.attachmentCount = 1;
20134 rp_info.pAttachments = &att;
20135 rp_info.subpassCount = 1;
20136 rp_info.pSubpasses = &subpass;
20137 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20138 ASSERT_VK_SUCCESS(result);
20139
20140 VkImageView *depthView = m_depthStencil->BindInfo();
20141 VkFramebufferCreateInfo fb_info = {};
20142 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20143 fb_info.pNext = NULL;
20144 fb_info.renderPass = rp;
20145 fb_info.attachmentCount = 1;
20146 fb_info.pAttachments = depthView;
20147 fb_info.width = 100;
20148 fb_info.height = 100;
20149 fb_info.layers = 1;
20150 VkFramebuffer fb;
20151 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20152 ASSERT_VK_SUCCESS(result);
20153
20154 VkRenderPassBeginInfo rpbinfo = {};
20155 rpbinfo.clearValueCount = 1;
20156 rpbinfo.pClearValues = &clear;
20157 rpbinfo.pNext = NULL;
20158 rpbinfo.renderPass = rp;
20159 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20160 rpbinfo.renderArea.extent.width = 100;
20161 rpbinfo.renderArea.extent.height = 100;
20162 rpbinfo.renderArea.offset.x = 0;
20163 rpbinfo.renderArea.offset.y = 0;
20164 rpbinfo.framebuffer = fb;
20165
20166 VkFence fence = {};
20167 VkFenceCreateInfo fence_ci = {};
20168 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20169 fence_ci.pNext = nullptr;
20170 fence_ci.flags = 0;
20171 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20172 ASSERT_VK_SUCCESS(result);
20173
20174 m_commandBuffer->BeginCommandBuffer();
20175 m_commandBuffer->BeginRenderPass(rpbinfo);
20176 m_commandBuffer->EndRenderPass();
20177 m_commandBuffer->EndCommandBuffer();
20178 m_commandBuffer->QueueCommandBuffer(fence);
20179
20180 VkImageObj destImage(m_device);
20181 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 -070020182 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020183 VkImageMemoryBarrier barrier = {};
20184 VkImageSubresourceRange range;
20185 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20186 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20187 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20188 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20189 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20190 barrier.image = m_depthStencil->handle();
20191 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20192 range.baseMipLevel = 0;
20193 range.levelCount = 1;
20194 range.baseArrayLayer = 0;
20195 range.layerCount = 1;
20196 barrier.subresourceRange = range;
20197 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20198 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20199 cmdbuf.BeginCommandBuffer();
20200 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 -070020201 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 barrier.srcAccessMask = 0;
20203 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20204 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20205 barrier.image = destImage.handle();
20206 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20207 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 -070020208 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020209 VkImageCopy cregion;
20210 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20211 cregion.srcSubresource.mipLevel = 0;
20212 cregion.srcSubresource.baseArrayLayer = 0;
20213 cregion.srcSubresource.layerCount = 1;
20214 cregion.srcOffset.x = 0;
20215 cregion.srcOffset.y = 0;
20216 cregion.srcOffset.z = 0;
20217 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20218 cregion.dstSubresource.mipLevel = 0;
20219 cregion.dstSubresource.baseArrayLayer = 0;
20220 cregion.dstSubresource.layerCount = 1;
20221 cregion.dstOffset.x = 0;
20222 cregion.dstOffset.y = 0;
20223 cregion.dstOffset.z = 0;
20224 cregion.extent.width = 100;
20225 cregion.extent.height = 100;
20226 cregion.extent.depth = 1;
20227 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020228 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020229 cmdbuf.EndCommandBuffer();
20230
20231 VkSubmitInfo submit_info;
20232 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20233 submit_info.pNext = NULL;
20234 submit_info.waitSemaphoreCount = 0;
20235 submit_info.pWaitSemaphores = NULL;
20236 submit_info.pWaitDstStageMask = NULL;
20237 submit_info.commandBufferCount = 1;
20238 submit_info.pCommandBuffers = &cmdbuf.handle();
20239 submit_info.signalSemaphoreCount = 0;
20240 submit_info.pSignalSemaphores = NULL;
20241
20242 m_errorMonitor->ExpectSuccess();
20243 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20244 m_errorMonitor->VerifyNotFound();
20245
20246 vkQueueWaitIdle(m_device->m_queue);
20247 vkDestroyFence(m_device->device(), fence, nullptr);
20248 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20249 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20250}
20251
20252// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070020253TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
20254 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
20255
20256 m_errorMonitor->ExpectSuccess();
20257
20258 ASSERT_NO_FATAL_FAILURE(InitState());
20259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20260
20261 VkImageMemoryBarrier img_barrier = {};
20262 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20263 img_barrier.pNext = NULL;
20264 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20265 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20266 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20267 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20268 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20269 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20270 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20271 img_barrier.subresourceRange.baseArrayLayer = 0;
20272 img_barrier.subresourceRange.baseMipLevel = 0;
20273 img_barrier.subresourceRange.layerCount = 1;
20274 img_barrier.subresourceRange.levelCount = 1;
20275
20276 {
20277 VkImageObj img_color(m_device);
20278 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20279 ASSERT_TRUE(img_color.initialized());
20280
20281 VkImageObj img_ds1(m_device);
20282 img_ds1.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20283 ASSERT_TRUE(img_ds1.initialized());
20284
20285 VkImageObj img_ds2(m_device);
20286 img_ds2.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20287 ASSERT_TRUE(img_ds2.initialized());
20288
20289 VkImageObj img_xfer_src(m_device);
20290 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
20291 ASSERT_TRUE(img_xfer_src.initialized());
20292
20293 VkImageObj img_xfer_dst(m_device);
20294 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
20295 ASSERT_TRUE(img_xfer_dst.initialized());
20296
20297 VkImageObj img_sampled(m_device);
20298 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
20299 ASSERT_TRUE(img_sampled.initialized());
20300
20301 VkImageObj img_input(m_device);
20302 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20303 ASSERT_TRUE(img_input.initialized());
20304
20305 const struct {
20306 VkImageObj &image_obj;
20307 VkImageLayout old_layout;
20308 VkImageLayout new_layout;
20309 } buffer_layouts[] = {
20310 // clang-format off
20311 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20312 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20313 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20314 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20315 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20316 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20317 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20318 // clang-format on
20319 };
20320 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
20321
20322 m_commandBuffer->BeginCommandBuffer();
20323 for (uint32_t i = 0; i < layout_count; ++i) {
20324 img_barrier.image = buffer_layouts[i].image_obj.handle();
20325 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
20326 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
20327 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
20328 : VK_IMAGE_ASPECT_COLOR_BIT;
20329
20330 img_barrier.oldLayout = buffer_layouts[i].old_layout;
20331 img_barrier.newLayout = buffer_layouts[i].new_layout;
20332 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20333 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20334
20335 img_barrier.oldLayout = buffer_layouts[i].new_layout;
20336 img_barrier.newLayout = buffer_layouts[i].old_layout;
20337 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20338 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20339 }
20340 m_commandBuffer->EndCommandBuffer();
20341
20342 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20343 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20344 }
20345 m_errorMonitor->VerifyNotFound();
20346}
20347
20348// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020349TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20350 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20351
20352 m_errorMonitor->ExpectSuccess();
20353 ASSERT_NO_FATAL_FAILURE(InitState());
20354
20355 VkEvent event;
20356 VkEventCreateInfo event_create_info{};
20357 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20358 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20359
20360 VkCommandPool command_pool;
20361 VkCommandPoolCreateInfo pool_create_info{};
20362 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20363 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20364 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20365 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20366
20367 VkCommandBuffer command_buffer;
20368 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20369 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20370 command_buffer_allocate_info.commandPool = command_pool;
20371 command_buffer_allocate_info.commandBufferCount = 1;
20372 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20373 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20374
20375 VkQueue queue = VK_NULL_HANDLE;
20376 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20377
20378 {
20379 VkCommandBufferBeginInfo begin_info{};
20380 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20381 vkBeginCommandBuffer(command_buffer, &begin_info);
20382
20383 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 -070020384 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020385 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20386 vkEndCommandBuffer(command_buffer);
20387 }
20388 {
20389 VkSubmitInfo submit_info{};
20390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20391 submit_info.commandBufferCount = 1;
20392 submit_info.pCommandBuffers = &command_buffer;
20393 submit_info.signalSemaphoreCount = 0;
20394 submit_info.pSignalSemaphores = nullptr;
20395 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20396 }
20397 { vkSetEvent(m_device->device(), event); }
20398
20399 vkQueueWaitIdle(queue);
20400
20401 vkDestroyEvent(m_device->device(), event, nullptr);
20402 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20403 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20404
20405 m_errorMonitor->VerifyNotFound();
20406}
20407// This is a positive test. No errors should be generated.
20408TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20409 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20410
20411 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020412 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020413
20414 m_errorMonitor->ExpectSuccess();
20415
20416 VkQueryPool query_pool;
20417 VkQueryPoolCreateInfo query_pool_create_info{};
20418 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20419 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20420 query_pool_create_info.queryCount = 1;
20421 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20422
20423 VkCommandPool command_pool;
20424 VkCommandPoolCreateInfo pool_create_info{};
20425 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20426 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20427 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20428 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20429
20430 VkCommandBuffer command_buffer;
20431 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20432 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20433 command_buffer_allocate_info.commandPool = command_pool;
20434 command_buffer_allocate_info.commandBufferCount = 1;
20435 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20436 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20437
20438 VkCommandBuffer secondary_command_buffer;
20439 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20440 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20441
20442 VkQueue queue = VK_NULL_HANDLE;
20443 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20444
20445 uint32_t qfi = 0;
20446 VkBufferCreateInfo buff_create_info = {};
20447 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20448 buff_create_info.size = 1024;
20449 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20450 buff_create_info.queueFamilyIndexCount = 1;
20451 buff_create_info.pQueueFamilyIndices = &qfi;
20452
20453 VkResult err;
20454 VkBuffer buffer;
20455 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20456 ASSERT_VK_SUCCESS(err);
20457 VkMemoryAllocateInfo mem_alloc = {};
20458 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20459 mem_alloc.pNext = NULL;
20460 mem_alloc.allocationSize = 1024;
20461 mem_alloc.memoryTypeIndex = 0;
20462
20463 VkMemoryRequirements memReqs;
20464 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20465 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20466 if (!pass) {
20467 vkDestroyBuffer(m_device->device(), buffer, NULL);
20468 return;
20469 }
20470
20471 VkDeviceMemory mem;
20472 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20473 ASSERT_VK_SUCCESS(err);
20474 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20475 ASSERT_VK_SUCCESS(err);
20476
20477 VkCommandBufferInheritanceInfo hinfo = {};
20478 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20479 hinfo.renderPass = VK_NULL_HANDLE;
20480 hinfo.subpass = 0;
20481 hinfo.framebuffer = VK_NULL_HANDLE;
20482 hinfo.occlusionQueryEnable = VK_FALSE;
20483 hinfo.queryFlags = 0;
20484 hinfo.pipelineStatistics = 0;
20485
20486 {
20487 VkCommandBufferBeginInfo begin_info{};
20488 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20489 begin_info.pInheritanceInfo = &hinfo;
20490 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20491
20492 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20493 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20494
20495 vkEndCommandBuffer(secondary_command_buffer);
20496
20497 begin_info.pInheritanceInfo = nullptr;
20498 vkBeginCommandBuffer(command_buffer, &begin_info);
20499
20500 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20501 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20502
20503 vkEndCommandBuffer(command_buffer);
20504 }
20505 {
20506 VkSubmitInfo submit_info{};
20507 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20508 submit_info.commandBufferCount = 1;
20509 submit_info.pCommandBuffers = &command_buffer;
20510 submit_info.signalSemaphoreCount = 0;
20511 submit_info.pSignalSemaphores = nullptr;
20512 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20513 }
20514
20515 vkQueueWaitIdle(queue);
20516
20517 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20518 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20519 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20520 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20521 vkDestroyBuffer(m_device->device(), buffer, NULL);
20522 vkFreeMemory(m_device->device(), mem, NULL);
20523
20524 m_errorMonitor->VerifyNotFound();
20525}
20526
20527// This is a positive test. No errors should be generated.
20528TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20529 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20530
20531 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020532 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020533
20534 m_errorMonitor->ExpectSuccess();
20535
20536 VkQueryPool query_pool;
20537 VkQueryPoolCreateInfo query_pool_create_info{};
20538 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20539 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20540 query_pool_create_info.queryCount = 1;
20541 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20542
20543 VkCommandPool command_pool;
20544 VkCommandPoolCreateInfo pool_create_info{};
20545 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20546 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20547 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20548 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20549
20550 VkCommandBuffer command_buffer[2];
20551 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20552 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20553 command_buffer_allocate_info.commandPool = command_pool;
20554 command_buffer_allocate_info.commandBufferCount = 2;
20555 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20556 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20557
20558 VkQueue queue = VK_NULL_HANDLE;
20559 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20560
20561 uint32_t qfi = 0;
20562 VkBufferCreateInfo buff_create_info = {};
20563 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20564 buff_create_info.size = 1024;
20565 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20566 buff_create_info.queueFamilyIndexCount = 1;
20567 buff_create_info.pQueueFamilyIndices = &qfi;
20568
20569 VkResult err;
20570 VkBuffer buffer;
20571 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20572 ASSERT_VK_SUCCESS(err);
20573 VkMemoryAllocateInfo mem_alloc = {};
20574 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20575 mem_alloc.pNext = NULL;
20576 mem_alloc.allocationSize = 1024;
20577 mem_alloc.memoryTypeIndex = 0;
20578
20579 VkMemoryRequirements memReqs;
20580 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20581 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20582 if (!pass) {
20583 vkDestroyBuffer(m_device->device(), buffer, NULL);
20584 return;
20585 }
20586
20587 VkDeviceMemory mem;
20588 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20589 ASSERT_VK_SUCCESS(err);
20590 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20591 ASSERT_VK_SUCCESS(err);
20592
20593 {
20594 VkCommandBufferBeginInfo begin_info{};
20595 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20596 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20597
20598 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20599 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20600
20601 vkEndCommandBuffer(command_buffer[0]);
20602
20603 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20604
20605 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20606
20607 vkEndCommandBuffer(command_buffer[1]);
20608 }
20609 {
20610 VkSubmitInfo submit_info{};
20611 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20612 submit_info.commandBufferCount = 2;
20613 submit_info.pCommandBuffers = command_buffer;
20614 submit_info.signalSemaphoreCount = 0;
20615 submit_info.pSignalSemaphores = nullptr;
20616 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20617 }
20618
20619 vkQueueWaitIdle(queue);
20620
20621 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20622 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20623 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20624 vkDestroyBuffer(m_device->device(), buffer, NULL);
20625 vkFreeMemory(m_device->device(), mem, NULL);
20626
20627 m_errorMonitor->VerifyNotFound();
20628}
20629
Tony Barbourc46924f2016-11-04 11:49:52 -060020630TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020631 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20632
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020633 ASSERT_NO_FATAL_FAILURE(InitState());
20634 VkEvent event;
20635 VkEventCreateInfo event_create_info{};
20636 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20637 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20638
20639 VkCommandPool command_pool;
20640 VkCommandPoolCreateInfo pool_create_info{};
20641 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20642 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20643 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20644 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20645
20646 VkCommandBuffer command_buffer;
20647 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20648 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20649 command_buffer_allocate_info.commandPool = command_pool;
20650 command_buffer_allocate_info.commandBufferCount = 1;
20651 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20652 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20653
20654 VkQueue queue = VK_NULL_HANDLE;
20655 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20656
20657 {
20658 VkCommandBufferBeginInfo begin_info{};
20659 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20660 vkBeginCommandBuffer(command_buffer, &begin_info);
20661
20662 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020663 vkEndCommandBuffer(command_buffer);
20664 }
20665 {
20666 VkSubmitInfo submit_info{};
20667 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20668 submit_info.commandBufferCount = 1;
20669 submit_info.pCommandBuffers = &command_buffer;
20670 submit_info.signalSemaphoreCount = 0;
20671 submit_info.pSignalSemaphores = nullptr;
20672 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20673 }
20674 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20676 "that is already in use by a "
20677 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020678 vkSetEvent(m_device->device(), event);
20679 m_errorMonitor->VerifyFound();
20680 }
20681
20682 vkQueueWaitIdle(queue);
20683
20684 vkDestroyEvent(m_device->device(), event, nullptr);
20685 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20686 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20687}
20688
20689// This is a positive test. No errors should be generated.
20690TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020691 TEST_DESCRIPTION(
20692 "Two command buffers with two separate fences are each "
20693 "run through a Submit & WaitForFences cycle 3 times. This "
20694 "previously revealed a bug so running this positive test "
20695 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020696 m_errorMonitor->ExpectSuccess();
20697
20698 ASSERT_NO_FATAL_FAILURE(InitState());
20699 VkQueue queue = VK_NULL_HANDLE;
20700 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20701
20702 static const uint32_t NUM_OBJECTS = 2;
20703 static const uint32_t NUM_FRAMES = 3;
20704 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20705 VkFence fences[NUM_OBJECTS] = {};
20706
20707 VkCommandPool cmd_pool;
20708 VkCommandPoolCreateInfo cmd_pool_ci = {};
20709 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20710 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20711 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20712 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20713 ASSERT_VK_SUCCESS(err);
20714
20715 VkCommandBufferAllocateInfo cmd_buf_info = {};
20716 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20717 cmd_buf_info.commandPool = cmd_pool;
20718 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20719 cmd_buf_info.commandBufferCount = 1;
20720
20721 VkFenceCreateInfo fence_ci = {};
20722 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20723 fence_ci.pNext = nullptr;
20724 fence_ci.flags = 0;
20725
20726 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20727 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20728 ASSERT_VK_SUCCESS(err);
20729 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20730 ASSERT_VK_SUCCESS(err);
20731 }
20732
20733 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20734 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20735 // Create empty cmd buffer
20736 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20737 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20738
20739 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20740 ASSERT_VK_SUCCESS(err);
20741 err = vkEndCommandBuffer(cmd_buffers[obj]);
20742 ASSERT_VK_SUCCESS(err);
20743
20744 VkSubmitInfo submit_info = {};
20745 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20746 submit_info.commandBufferCount = 1;
20747 submit_info.pCommandBuffers = &cmd_buffers[obj];
20748 // Submit cmd buffer and wait for fence
20749 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20750 ASSERT_VK_SUCCESS(err);
20751 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20752 ASSERT_VK_SUCCESS(err);
20753 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20754 ASSERT_VK_SUCCESS(err);
20755 }
20756 }
20757 m_errorMonitor->VerifyNotFound();
20758 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20759 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20760 vkDestroyFence(m_device->device(), fences[i], nullptr);
20761 }
20762}
20763// This is a positive test. No errors should be generated.
20764TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020765 TEST_DESCRIPTION(
20766 "Two command buffers, each in a separate QueueSubmit call "
20767 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020768
20769 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020770 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020771
20772 m_errorMonitor->ExpectSuccess();
20773
20774 VkSemaphore semaphore;
20775 VkSemaphoreCreateInfo semaphore_create_info{};
20776 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20777 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20778
20779 VkCommandPool command_pool;
20780 VkCommandPoolCreateInfo pool_create_info{};
20781 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20782 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20783 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20784 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20785
20786 VkCommandBuffer command_buffer[2];
20787 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20788 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20789 command_buffer_allocate_info.commandPool = command_pool;
20790 command_buffer_allocate_info.commandBufferCount = 2;
20791 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20792 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20793
20794 VkQueue queue = VK_NULL_HANDLE;
20795 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20796
20797 {
20798 VkCommandBufferBeginInfo begin_info{};
20799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20800 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20801
20802 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 -070020803 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020804
20805 VkViewport viewport{};
20806 viewport.maxDepth = 1.0f;
20807 viewport.minDepth = 0.0f;
20808 viewport.width = 512;
20809 viewport.height = 512;
20810 viewport.x = 0;
20811 viewport.y = 0;
20812 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20813 vkEndCommandBuffer(command_buffer[0]);
20814 }
20815 {
20816 VkCommandBufferBeginInfo begin_info{};
20817 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20818 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20819
20820 VkViewport viewport{};
20821 viewport.maxDepth = 1.0f;
20822 viewport.minDepth = 0.0f;
20823 viewport.width = 512;
20824 viewport.height = 512;
20825 viewport.x = 0;
20826 viewport.y = 0;
20827 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20828 vkEndCommandBuffer(command_buffer[1]);
20829 }
20830 {
20831 VkSubmitInfo submit_info{};
20832 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20833 submit_info.commandBufferCount = 1;
20834 submit_info.pCommandBuffers = &command_buffer[0];
20835 submit_info.signalSemaphoreCount = 1;
20836 submit_info.pSignalSemaphores = &semaphore;
20837 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20838 }
20839 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020840 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020841 VkSubmitInfo submit_info{};
20842 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20843 submit_info.commandBufferCount = 1;
20844 submit_info.pCommandBuffers = &command_buffer[1];
20845 submit_info.waitSemaphoreCount = 1;
20846 submit_info.pWaitSemaphores = &semaphore;
20847 submit_info.pWaitDstStageMask = flags;
20848 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20849 }
20850
20851 vkQueueWaitIdle(m_device->m_queue);
20852
20853 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20854 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20855 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20856
20857 m_errorMonitor->VerifyNotFound();
20858}
20859
20860// This is a positive test. No errors should be generated.
20861TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020862 TEST_DESCRIPTION(
20863 "Two command buffers, each in a separate QueueSubmit call "
20864 "submitted on separate queues, the second having a fence"
20865 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020866
20867 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020868 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020869
20870 m_errorMonitor->ExpectSuccess();
20871
20872 VkFence fence;
20873 VkFenceCreateInfo fence_create_info{};
20874 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20875 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20876
20877 VkSemaphore semaphore;
20878 VkSemaphoreCreateInfo semaphore_create_info{};
20879 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20880 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20881
20882 VkCommandPool command_pool;
20883 VkCommandPoolCreateInfo pool_create_info{};
20884 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20885 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20886 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20887 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20888
20889 VkCommandBuffer command_buffer[2];
20890 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20891 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20892 command_buffer_allocate_info.commandPool = command_pool;
20893 command_buffer_allocate_info.commandBufferCount = 2;
20894 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20895 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20896
20897 VkQueue queue = VK_NULL_HANDLE;
20898 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20899
20900 {
20901 VkCommandBufferBeginInfo begin_info{};
20902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20903 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20904
20905 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 -070020906 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020907
20908 VkViewport viewport{};
20909 viewport.maxDepth = 1.0f;
20910 viewport.minDepth = 0.0f;
20911 viewport.width = 512;
20912 viewport.height = 512;
20913 viewport.x = 0;
20914 viewport.y = 0;
20915 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20916 vkEndCommandBuffer(command_buffer[0]);
20917 }
20918 {
20919 VkCommandBufferBeginInfo begin_info{};
20920 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20921 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20922
20923 VkViewport viewport{};
20924 viewport.maxDepth = 1.0f;
20925 viewport.minDepth = 0.0f;
20926 viewport.width = 512;
20927 viewport.height = 512;
20928 viewport.x = 0;
20929 viewport.y = 0;
20930 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20931 vkEndCommandBuffer(command_buffer[1]);
20932 }
20933 {
20934 VkSubmitInfo submit_info{};
20935 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20936 submit_info.commandBufferCount = 1;
20937 submit_info.pCommandBuffers = &command_buffer[0];
20938 submit_info.signalSemaphoreCount = 1;
20939 submit_info.pSignalSemaphores = &semaphore;
20940 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20941 }
20942 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020943 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020944 VkSubmitInfo submit_info{};
20945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20946 submit_info.commandBufferCount = 1;
20947 submit_info.pCommandBuffers = &command_buffer[1];
20948 submit_info.waitSemaphoreCount = 1;
20949 submit_info.pWaitSemaphores = &semaphore;
20950 submit_info.pWaitDstStageMask = flags;
20951 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20952 }
20953
20954 vkQueueWaitIdle(m_device->m_queue);
20955
20956 vkDestroyFence(m_device->device(), fence, nullptr);
20957 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20958 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20959 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20960
20961 m_errorMonitor->VerifyNotFound();
20962}
20963
20964// This is a positive test. No errors should be generated.
20965TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020966 TEST_DESCRIPTION(
20967 "Two command buffers, each in a separate QueueSubmit call "
20968 "submitted on separate queues, the second having a fence"
20969 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020970
20971 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020972 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020973
20974 m_errorMonitor->ExpectSuccess();
20975
20976 VkFence fence;
20977 VkFenceCreateInfo fence_create_info{};
20978 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20979 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20980
20981 VkSemaphore semaphore;
20982 VkSemaphoreCreateInfo semaphore_create_info{};
20983 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20984 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20985
20986 VkCommandPool command_pool;
20987 VkCommandPoolCreateInfo pool_create_info{};
20988 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20989 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20990 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20991 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20992
20993 VkCommandBuffer command_buffer[2];
20994 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20995 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20996 command_buffer_allocate_info.commandPool = command_pool;
20997 command_buffer_allocate_info.commandBufferCount = 2;
20998 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20999 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21000
21001 VkQueue queue = VK_NULL_HANDLE;
21002 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21003
21004 {
21005 VkCommandBufferBeginInfo begin_info{};
21006 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21007 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21008
21009 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 -070021010 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021011
21012 VkViewport viewport{};
21013 viewport.maxDepth = 1.0f;
21014 viewport.minDepth = 0.0f;
21015 viewport.width = 512;
21016 viewport.height = 512;
21017 viewport.x = 0;
21018 viewport.y = 0;
21019 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21020 vkEndCommandBuffer(command_buffer[0]);
21021 }
21022 {
21023 VkCommandBufferBeginInfo begin_info{};
21024 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21025 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21026
21027 VkViewport viewport{};
21028 viewport.maxDepth = 1.0f;
21029 viewport.minDepth = 0.0f;
21030 viewport.width = 512;
21031 viewport.height = 512;
21032 viewport.x = 0;
21033 viewport.y = 0;
21034 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21035 vkEndCommandBuffer(command_buffer[1]);
21036 }
21037 {
21038 VkSubmitInfo submit_info{};
21039 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21040 submit_info.commandBufferCount = 1;
21041 submit_info.pCommandBuffers = &command_buffer[0];
21042 submit_info.signalSemaphoreCount = 1;
21043 submit_info.pSignalSemaphores = &semaphore;
21044 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21045 }
21046 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021047 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021048 VkSubmitInfo submit_info{};
21049 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21050 submit_info.commandBufferCount = 1;
21051 submit_info.pCommandBuffers = &command_buffer[1];
21052 submit_info.waitSemaphoreCount = 1;
21053 submit_info.pWaitSemaphores = &semaphore;
21054 submit_info.pWaitDstStageMask = flags;
21055 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21056 }
21057
21058 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21059 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21060
21061 vkDestroyFence(m_device->device(), fence, nullptr);
21062 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21063 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21064 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21065
21066 m_errorMonitor->VerifyNotFound();
21067}
21068
21069TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021070 ASSERT_NO_FATAL_FAILURE(InitState());
21071 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021072 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021073 return;
21074 }
21075
21076 VkResult err;
21077
21078 m_errorMonitor->ExpectSuccess();
21079
21080 VkQueue q0 = m_device->m_queue;
21081 VkQueue q1 = nullptr;
21082 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
21083 ASSERT_NE(q1, nullptr);
21084
21085 // An (empty) command buffer. We must have work in the first submission --
21086 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021087 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088 VkCommandPool pool;
21089 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
21090 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021091 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
21092 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021093 VkCommandBuffer cb;
21094 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
21095 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021096 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021097 err = vkBeginCommandBuffer(cb, &cbbi);
21098 ASSERT_VK_SUCCESS(err);
21099 err = vkEndCommandBuffer(cb);
21100 ASSERT_VK_SUCCESS(err);
21101
21102 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021103 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021104 VkSemaphore s;
21105 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
21106 ASSERT_VK_SUCCESS(err);
21107
21108 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021109 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021110
21111 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
21112 ASSERT_VK_SUCCESS(err);
21113
21114 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021115 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021116 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021117
21118 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
21119 ASSERT_VK_SUCCESS(err);
21120
21121 // Wait for q0 idle
21122 err = vkQueueWaitIdle(q0);
21123 ASSERT_VK_SUCCESS(err);
21124
21125 // Command buffer should have been completed (it was on q0); reset the pool.
21126 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
21127
21128 m_errorMonitor->VerifyNotFound();
21129
21130 // Force device completely idle and clean up resources
21131 vkDeviceWaitIdle(m_device->device());
21132 vkDestroyCommandPool(m_device->device(), pool, nullptr);
21133 vkDestroySemaphore(m_device->device(), s, nullptr);
21134}
21135
21136// This is a positive test. No errors should be generated.
21137TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021138 TEST_DESCRIPTION(
21139 "Two command buffers, each in a separate QueueSubmit call "
21140 "submitted on separate queues, the second having a fence, "
21141 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021142
21143 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021144 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021145
21146 m_errorMonitor->ExpectSuccess();
21147
21148 ASSERT_NO_FATAL_FAILURE(InitState());
21149 VkFence fence;
21150 VkFenceCreateInfo fence_create_info{};
21151 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21152 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21153
21154 VkSemaphore semaphore;
21155 VkSemaphoreCreateInfo semaphore_create_info{};
21156 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21157 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21158
21159 VkCommandPool command_pool;
21160 VkCommandPoolCreateInfo pool_create_info{};
21161 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21162 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21163 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21164 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21165
21166 VkCommandBuffer command_buffer[2];
21167 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21168 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21169 command_buffer_allocate_info.commandPool = command_pool;
21170 command_buffer_allocate_info.commandBufferCount = 2;
21171 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21172 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21173
21174 VkQueue queue = VK_NULL_HANDLE;
21175 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21176
21177 {
21178 VkCommandBufferBeginInfo begin_info{};
21179 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21180 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21181
21182 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 -070021183 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021184
21185 VkViewport viewport{};
21186 viewport.maxDepth = 1.0f;
21187 viewport.minDepth = 0.0f;
21188 viewport.width = 512;
21189 viewport.height = 512;
21190 viewport.x = 0;
21191 viewport.y = 0;
21192 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21193 vkEndCommandBuffer(command_buffer[0]);
21194 }
21195 {
21196 VkCommandBufferBeginInfo begin_info{};
21197 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21198 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21199
21200 VkViewport viewport{};
21201 viewport.maxDepth = 1.0f;
21202 viewport.minDepth = 0.0f;
21203 viewport.width = 512;
21204 viewport.height = 512;
21205 viewport.x = 0;
21206 viewport.y = 0;
21207 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21208 vkEndCommandBuffer(command_buffer[1]);
21209 }
21210 {
21211 VkSubmitInfo submit_info{};
21212 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21213 submit_info.commandBufferCount = 1;
21214 submit_info.pCommandBuffers = &command_buffer[0];
21215 submit_info.signalSemaphoreCount = 1;
21216 submit_info.pSignalSemaphores = &semaphore;
21217 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21218 }
21219 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021220 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021221 VkSubmitInfo submit_info{};
21222 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21223 submit_info.commandBufferCount = 1;
21224 submit_info.pCommandBuffers = &command_buffer[1];
21225 submit_info.waitSemaphoreCount = 1;
21226 submit_info.pWaitSemaphores = &semaphore;
21227 submit_info.pWaitDstStageMask = flags;
21228 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21229 }
21230
21231 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21232
21233 vkDestroyFence(m_device->device(), fence, nullptr);
21234 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21235 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21236 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21237
21238 m_errorMonitor->VerifyNotFound();
21239}
21240
21241// This is a positive test. No errors should be generated.
21242TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021243 TEST_DESCRIPTION(
21244 "Two command buffers, each in a separate QueueSubmit call "
21245 "on the same queue, sharing a signal/wait semaphore, the "
21246 "second having a fence, "
21247 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021248
21249 m_errorMonitor->ExpectSuccess();
21250
21251 ASSERT_NO_FATAL_FAILURE(InitState());
21252 VkFence fence;
21253 VkFenceCreateInfo fence_create_info{};
21254 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21255 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21256
21257 VkSemaphore semaphore;
21258 VkSemaphoreCreateInfo semaphore_create_info{};
21259 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21260 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21261
21262 VkCommandPool command_pool;
21263 VkCommandPoolCreateInfo pool_create_info{};
21264 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21265 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21266 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21267 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21268
21269 VkCommandBuffer command_buffer[2];
21270 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21271 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21272 command_buffer_allocate_info.commandPool = command_pool;
21273 command_buffer_allocate_info.commandBufferCount = 2;
21274 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21275 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21276
21277 {
21278 VkCommandBufferBeginInfo begin_info{};
21279 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21280 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21281
21282 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 -070021283 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021284
21285 VkViewport viewport{};
21286 viewport.maxDepth = 1.0f;
21287 viewport.minDepth = 0.0f;
21288 viewport.width = 512;
21289 viewport.height = 512;
21290 viewport.x = 0;
21291 viewport.y = 0;
21292 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21293 vkEndCommandBuffer(command_buffer[0]);
21294 }
21295 {
21296 VkCommandBufferBeginInfo begin_info{};
21297 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21298 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21299
21300 VkViewport viewport{};
21301 viewport.maxDepth = 1.0f;
21302 viewport.minDepth = 0.0f;
21303 viewport.width = 512;
21304 viewport.height = 512;
21305 viewport.x = 0;
21306 viewport.y = 0;
21307 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21308 vkEndCommandBuffer(command_buffer[1]);
21309 }
21310 {
21311 VkSubmitInfo submit_info{};
21312 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21313 submit_info.commandBufferCount = 1;
21314 submit_info.pCommandBuffers = &command_buffer[0];
21315 submit_info.signalSemaphoreCount = 1;
21316 submit_info.pSignalSemaphores = &semaphore;
21317 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21318 }
21319 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021320 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021321 VkSubmitInfo submit_info{};
21322 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21323 submit_info.commandBufferCount = 1;
21324 submit_info.pCommandBuffers = &command_buffer[1];
21325 submit_info.waitSemaphoreCount = 1;
21326 submit_info.pWaitSemaphores = &semaphore;
21327 submit_info.pWaitDstStageMask = flags;
21328 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21329 }
21330
21331 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21332
21333 vkDestroyFence(m_device->device(), fence, nullptr);
21334 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21335 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21336 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21337
21338 m_errorMonitor->VerifyNotFound();
21339}
21340
21341// This is a positive test. No errors should be generated.
21342TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021343 TEST_DESCRIPTION(
21344 "Two command buffers, each in a separate QueueSubmit call "
21345 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21346 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021347
21348 m_errorMonitor->ExpectSuccess();
21349
21350 ASSERT_NO_FATAL_FAILURE(InitState());
21351 VkFence fence;
21352 VkFenceCreateInfo fence_create_info{};
21353 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21354 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21355
21356 VkCommandPool command_pool;
21357 VkCommandPoolCreateInfo pool_create_info{};
21358 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21359 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21360 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21361 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21362
21363 VkCommandBuffer command_buffer[2];
21364 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21365 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21366 command_buffer_allocate_info.commandPool = command_pool;
21367 command_buffer_allocate_info.commandBufferCount = 2;
21368 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21369 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21370
21371 {
21372 VkCommandBufferBeginInfo begin_info{};
21373 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21374 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21375
21376 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 -070021377 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021378
21379 VkViewport viewport{};
21380 viewport.maxDepth = 1.0f;
21381 viewport.minDepth = 0.0f;
21382 viewport.width = 512;
21383 viewport.height = 512;
21384 viewport.x = 0;
21385 viewport.y = 0;
21386 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21387 vkEndCommandBuffer(command_buffer[0]);
21388 }
21389 {
21390 VkCommandBufferBeginInfo begin_info{};
21391 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21392 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21393
21394 VkViewport viewport{};
21395 viewport.maxDepth = 1.0f;
21396 viewport.minDepth = 0.0f;
21397 viewport.width = 512;
21398 viewport.height = 512;
21399 viewport.x = 0;
21400 viewport.y = 0;
21401 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21402 vkEndCommandBuffer(command_buffer[1]);
21403 }
21404 {
21405 VkSubmitInfo submit_info{};
21406 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21407 submit_info.commandBufferCount = 1;
21408 submit_info.pCommandBuffers = &command_buffer[0];
21409 submit_info.signalSemaphoreCount = 0;
21410 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21411 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21412 }
21413 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021414 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021415 VkSubmitInfo submit_info{};
21416 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21417 submit_info.commandBufferCount = 1;
21418 submit_info.pCommandBuffers = &command_buffer[1];
21419 submit_info.waitSemaphoreCount = 0;
21420 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21421 submit_info.pWaitDstStageMask = flags;
21422 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21423 }
21424
21425 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21426
21427 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21428 ASSERT_VK_SUCCESS(err);
21429
21430 vkDestroyFence(m_device->device(), fence, nullptr);
21431 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21432 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21433
21434 m_errorMonitor->VerifyNotFound();
21435}
21436
21437// This is a positive test. No errors should be generated.
21438TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021439 TEST_DESCRIPTION(
21440 "Two command buffers, each in a separate QueueSubmit call "
21441 "on the same queue, the second having a fence, followed "
21442 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021443
21444 m_errorMonitor->ExpectSuccess();
21445
21446 ASSERT_NO_FATAL_FAILURE(InitState());
21447 VkFence fence;
21448 VkFenceCreateInfo fence_create_info{};
21449 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21450 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21451
21452 VkCommandPool command_pool;
21453 VkCommandPoolCreateInfo pool_create_info{};
21454 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21455 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21456 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21457 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21458
21459 VkCommandBuffer command_buffer[2];
21460 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21461 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21462 command_buffer_allocate_info.commandPool = command_pool;
21463 command_buffer_allocate_info.commandBufferCount = 2;
21464 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21465 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21466
21467 {
21468 VkCommandBufferBeginInfo begin_info{};
21469 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21470 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21471
21472 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 -070021473 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021474
21475 VkViewport viewport{};
21476 viewport.maxDepth = 1.0f;
21477 viewport.minDepth = 0.0f;
21478 viewport.width = 512;
21479 viewport.height = 512;
21480 viewport.x = 0;
21481 viewport.y = 0;
21482 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21483 vkEndCommandBuffer(command_buffer[0]);
21484 }
21485 {
21486 VkCommandBufferBeginInfo begin_info{};
21487 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21488 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21489
21490 VkViewport viewport{};
21491 viewport.maxDepth = 1.0f;
21492 viewport.minDepth = 0.0f;
21493 viewport.width = 512;
21494 viewport.height = 512;
21495 viewport.x = 0;
21496 viewport.y = 0;
21497 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21498 vkEndCommandBuffer(command_buffer[1]);
21499 }
21500 {
21501 VkSubmitInfo submit_info{};
21502 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21503 submit_info.commandBufferCount = 1;
21504 submit_info.pCommandBuffers = &command_buffer[0];
21505 submit_info.signalSemaphoreCount = 0;
21506 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21507 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21508 }
21509 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021510 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021511 VkSubmitInfo submit_info{};
21512 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21513 submit_info.commandBufferCount = 1;
21514 submit_info.pCommandBuffers = &command_buffer[1];
21515 submit_info.waitSemaphoreCount = 0;
21516 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21517 submit_info.pWaitDstStageMask = flags;
21518 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21519 }
21520
21521 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21522
21523 vkDestroyFence(m_device->device(), fence, nullptr);
21524 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21525 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21526
21527 m_errorMonitor->VerifyNotFound();
21528}
21529
21530// This is a positive test. No errors should be generated.
21531TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021532 TEST_DESCRIPTION(
21533 "Two command buffers each in a separate SubmitInfo sent in a single "
21534 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021535 ASSERT_NO_FATAL_FAILURE(InitState());
21536
21537 m_errorMonitor->ExpectSuccess();
21538
21539 VkFence fence;
21540 VkFenceCreateInfo fence_create_info{};
21541 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21542 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21543
21544 VkSemaphore semaphore;
21545 VkSemaphoreCreateInfo semaphore_create_info{};
21546 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21547 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21548
21549 VkCommandPool command_pool;
21550 VkCommandPoolCreateInfo pool_create_info{};
21551 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21552 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21553 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21554 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21555
21556 VkCommandBuffer command_buffer[2];
21557 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21558 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21559 command_buffer_allocate_info.commandPool = command_pool;
21560 command_buffer_allocate_info.commandBufferCount = 2;
21561 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21562 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21563
21564 {
21565 VkCommandBufferBeginInfo begin_info{};
21566 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21567 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21568
21569 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 -070021570 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021571
21572 VkViewport viewport{};
21573 viewport.maxDepth = 1.0f;
21574 viewport.minDepth = 0.0f;
21575 viewport.width = 512;
21576 viewport.height = 512;
21577 viewport.x = 0;
21578 viewport.y = 0;
21579 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21580 vkEndCommandBuffer(command_buffer[0]);
21581 }
21582 {
21583 VkCommandBufferBeginInfo begin_info{};
21584 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21585 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21586
21587 VkViewport viewport{};
21588 viewport.maxDepth = 1.0f;
21589 viewport.minDepth = 0.0f;
21590 viewport.width = 512;
21591 viewport.height = 512;
21592 viewport.x = 0;
21593 viewport.y = 0;
21594 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21595 vkEndCommandBuffer(command_buffer[1]);
21596 }
21597 {
21598 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021599 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021600
21601 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21602 submit_info[0].pNext = NULL;
21603 submit_info[0].commandBufferCount = 1;
21604 submit_info[0].pCommandBuffers = &command_buffer[0];
21605 submit_info[0].signalSemaphoreCount = 1;
21606 submit_info[0].pSignalSemaphores = &semaphore;
21607 submit_info[0].waitSemaphoreCount = 0;
21608 submit_info[0].pWaitSemaphores = NULL;
21609 submit_info[0].pWaitDstStageMask = 0;
21610
21611 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21612 submit_info[1].pNext = NULL;
21613 submit_info[1].commandBufferCount = 1;
21614 submit_info[1].pCommandBuffers = &command_buffer[1];
21615 submit_info[1].waitSemaphoreCount = 1;
21616 submit_info[1].pWaitSemaphores = &semaphore;
21617 submit_info[1].pWaitDstStageMask = flags;
21618 submit_info[1].signalSemaphoreCount = 0;
21619 submit_info[1].pSignalSemaphores = NULL;
21620 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21621 }
21622
21623 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21624
21625 vkDestroyFence(m_device->device(), fence, nullptr);
21626 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21627 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21628 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21629
21630 m_errorMonitor->VerifyNotFound();
21631}
21632
21633TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21634 m_errorMonitor->ExpectSuccess();
21635
21636 ASSERT_NO_FATAL_FAILURE(InitState());
21637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21638
Tony Barbour552f6c02016-12-21 14:34:07 -070021639 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021640
21641 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21642 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21643 m_errorMonitor->VerifyNotFound();
21644 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21645 m_errorMonitor->VerifyNotFound();
21646 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21647 m_errorMonitor->VerifyNotFound();
21648
21649 m_commandBuffer->EndCommandBuffer();
21650 m_errorMonitor->VerifyNotFound();
21651}
21652
21653TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021654 TEST_DESCRIPTION(
21655 "Positive test where we create a renderpass with an "
21656 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21657 "has a valid layout, and a second subpass then uses a "
21658 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021659 m_errorMonitor->ExpectSuccess();
21660 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021661 auto depth_format = find_depth_stencil_format(m_device);
21662 if (!depth_format) {
21663 printf(" No Depth + Stencil format found. Skipped.\n");
21664 return;
21665 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021666
21667 VkAttachmentReference attach[2] = {};
21668 attach[0].attachment = 0;
21669 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21670 attach[1].attachment = 0;
21671 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21672 VkSubpassDescription subpasses[2] = {};
21673 // First subpass clears DS attach on load
21674 subpasses[0].pDepthStencilAttachment = &attach[0];
21675 // 2nd subpass reads in DS as input attachment
21676 subpasses[1].inputAttachmentCount = 1;
21677 subpasses[1].pInputAttachments = &attach[1];
21678 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021679 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021680 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21681 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21682 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21683 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21684 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21685 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21686 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21687 VkRenderPassCreateInfo rpci = {};
21688 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21689 rpci.attachmentCount = 1;
21690 rpci.pAttachments = &attach_desc;
21691 rpci.subpassCount = 2;
21692 rpci.pSubpasses = subpasses;
21693
21694 // Now create RenderPass and verify no errors
21695 VkRenderPass rp;
21696 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21697 m_errorMonitor->VerifyNotFound();
21698
21699 vkDestroyRenderPass(m_device->device(), rp, NULL);
21700}
21701
Tobin Ehlis01103de2017-02-16 13:22:47 -070021702TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21703 TEST_DESCRIPTION(
21704 "Create a render pass with depth-stencil attachment where layout transition "
21705 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21706 "transition has correctly occurred at queue submit time with no validation errors.");
21707
Tony Barbourf887b162017-03-09 10:06:46 -070021708 ASSERT_NO_FATAL_FAILURE(InitState());
21709 auto depth_format = find_depth_stencil_format(m_device);
21710 if (!depth_format) {
21711 printf(" No Depth + Stencil format found. Skipped.\n");
21712 return;
21713 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021714 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021715 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021716 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21717 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021718 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021719 return;
21720 }
21721
21722 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21724
21725 // A renderpass with one depth/stencil attachment.
21726 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021727 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021728 VK_SAMPLE_COUNT_1_BIT,
21729 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21730 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21731 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21732 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21733 VK_IMAGE_LAYOUT_UNDEFINED,
21734 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21735
21736 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21737
21738 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21739
21740 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21741
21742 VkRenderPass rp;
21743 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21744 ASSERT_VK_SUCCESS(err);
21745 // A compatible ds image.
21746 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021747 image.init(32, 32, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070021748 ASSERT_TRUE(image.initialized());
21749
21750 VkImageViewCreateInfo ivci = {
21751 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21752 nullptr,
21753 0,
21754 image.handle(),
21755 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021756 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021757 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21758 VK_COMPONENT_SWIZZLE_IDENTITY},
21759 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21760 };
21761 VkImageView view;
21762 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21763 ASSERT_VK_SUCCESS(err);
21764
21765 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21766 VkFramebuffer fb;
21767 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21768 ASSERT_VK_SUCCESS(err);
21769
21770 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21771 m_commandBuffer->BeginCommandBuffer();
21772 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21773 vkCmdEndRenderPass(m_commandBuffer->handle());
21774 m_commandBuffer->EndCommandBuffer();
21775 QueueCommandBuffer(false);
21776 m_errorMonitor->VerifyNotFound();
21777
21778 // Cleanup
21779 vkDestroyImageView(m_device->device(), view, NULL);
21780 vkDestroyRenderPass(m_device->device(), rp, NULL);
21781 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21782}
21783
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021784TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021785 TEST_DESCRIPTION(
21786 "Test that pipeline validation accepts matrices passed "
21787 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021788 m_errorMonitor->ExpectSuccess();
21789
21790 ASSERT_NO_FATAL_FAILURE(InitState());
21791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21792
21793 VkVertexInputBindingDescription input_binding;
21794 memset(&input_binding, 0, sizeof(input_binding));
21795
21796 VkVertexInputAttributeDescription input_attribs[2];
21797 memset(input_attribs, 0, sizeof(input_attribs));
21798
21799 for (int i = 0; i < 2; i++) {
21800 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21801 input_attribs[i].location = i;
21802 }
21803
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021804 char const *vsSource =
21805 "#version 450\n"
21806 "\n"
21807 "layout(location=0) in mat2x4 x;\n"
21808 "out gl_PerVertex {\n"
21809 " vec4 gl_Position;\n"
21810 "};\n"
21811 "void main(){\n"
21812 " gl_Position = x[0] + x[1];\n"
21813 "}\n";
21814 char const *fsSource =
21815 "#version 450\n"
21816 "\n"
21817 "layout(location=0) out vec4 color;\n"
21818 "void main(){\n"
21819 " color = vec4(1);\n"
21820 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021821
21822 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21823 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21824
21825 VkPipelineObj pipe(m_device);
21826 pipe.AddColorAttachment();
21827 pipe.AddShader(&vs);
21828 pipe.AddShader(&fs);
21829
21830 pipe.AddVertexInputBindings(&input_binding, 1);
21831 pipe.AddVertexInputAttribs(input_attribs, 2);
21832
21833 VkDescriptorSetObj descriptorSet(m_device);
21834 descriptorSet.AppendDummy();
21835 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21836
21837 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21838
21839 /* expect success */
21840 m_errorMonitor->VerifyNotFound();
21841}
21842
21843TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21844 m_errorMonitor->ExpectSuccess();
21845
21846 ASSERT_NO_FATAL_FAILURE(InitState());
21847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21848
21849 VkVertexInputBindingDescription input_binding;
21850 memset(&input_binding, 0, sizeof(input_binding));
21851
21852 VkVertexInputAttributeDescription input_attribs[2];
21853 memset(input_attribs, 0, sizeof(input_attribs));
21854
21855 for (int i = 0; i < 2; i++) {
21856 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21857 input_attribs[i].location = i;
21858 }
21859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021860 char const *vsSource =
21861 "#version 450\n"
21862 "\n"
21863 "layout(location=0) in vec4 x[2];\n"
21864 "out gl_PerVertex {\n"
21865 " vec4 gl_Position;\n"
21866 "};\n"
21867 "void main(){\n"
21868 " gl_Position = x[0] + x[1];\n"
21869 "}\n";
21870 char const *fsSource =
21871 "#version 450\n"
21872 "\n"
21873 "layout(location=0) out vec4 color;\n"
21874 "void main(){\n"
21875 " color = vec4(1);\n"
21876 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021877
21878 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21879 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21880
21881 VkPipelineObj pipe(m_device);
21882 pipe.AddColorAttachment();
21883 pipe.AddShader(&vs);
21884 pipe.AddShader(&fs);
21885
21886 pipe.AddVertexInputBindings(&input_binding, 1);
21887 pipe.AddVertexInputAttribs(input_attribs, 2);
21888
21889 VkDescriptorSetObj descriptorSet(m_device);
21890 descriptorSet.AppendDummy();
21891 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21892
21893 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21894
21895 m_errorMonitor->VerifyNotFound();
21896}
21897
21898TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021899 TEST_DESCRIPTION(
21900 "Test that pipeline validation accepts consuming a vertex attribute "
21901 "through multiple vertex shader inputs, each consuming a different "
21902 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021903 m_errorMonitor->ExpectSuccess();
21904
21905 ASSERT_NO_FATAL_FAILURE(InitState());
21906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21907
21908 VkVertexInputBindingDescription input_binding;
21909 memset(&input_binding, 0, sizeof(input_binding));
21910
21911 VkVertexInputAttributeDescription input_attribs[3];
21912 memset(input_attribs, 0, sizeof(input_attribs));
21913
21914 for (int i = 0; i < 3; i++) {
21915 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21916 input_attribs[i].location = i;
21917 }
21918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021919 char const *vsSource =
21920 "#version 450\n"
21921 "\n"
21922 "layout(location=0) in vec4 x;\n"
21923 "layout(location=1) in vec3 y1;\n"
21924 "layout(location=1, component=3) in float y2;\n"
21925 "layout(location=2) in vec4 z;\n"
21926 "out gl_PerVertex {\n"
21927 " vec4 gl_Position;\n"
21928 "};\n"
21929 "void main(){\n"
21930 " gl_Position = x + vec4(y1, y2) + z;\n"
21931 "}\n";
21932 char const *fsSource =
21933 "#version 450\n"
21934 "\n"
21935 "layout(location=0) out vec4 color;\n"
21936 "void main(){\n"
21937 " color = vec4(1);\n"
21938 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021939
21940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21942
21943 VkPipelineObj pipe(m_device);
21944 pipe.AddColorAttachment();
21945 pipe.AddShader(&vs);
21946 pipe.AddShader(&fs);
21947
21948 pipe.AddVertexInputBindings(&input_binding, 1);
21949 pipe.AddVertexInputAttribs(input_attribs, 3);
21950
21951 VkDescriptorSetObj descriptorSet(m_device);
21952 descriptorSet.AppendDummy();
21953 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21954
21955 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21956
21957 m_errorMonitor->VerifyNotFound();
21958}
21959
21960TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21961 m_errorMonitor->ExpectSuccess();
21962
21963 ASSERT_NO_FATAL_FAILURE(InitState());
21964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21965
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021966 char const *vsSource =
21967 "#version 450\n"
21968 "out gl_PerVertex {\n"
21969 " vec4 gl_Position;\n"
21970 "};\n"
21971 "void main(){\n"
21972 " gl_Position = vec4(0);\n"
21973 "}\n";
21974 char const *fsSource =
21975 "#version 450\n"
21976 "\n"
21977 "layout(location=0) out vec4 color;\n"
21978 "void main(){\n"
21979 " color = vec4(1);\n"
21980 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021981
21982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21984
21985 VkPipelineObj pipe(m_device);
21986 pipe.AddColorAttachment();
21987 pipe.AddShader(&vs);
21988 pipe.AddShader(&fs);
21989
21990 VkDescriptorSetObj descriptorSet(m_device);
21991 descriptorSet.AppendDummy();
21992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21993
21994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21995
21996 m_errorMonitor->VerifyNotFound();
21997}
21998
21999TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022000 TEST_DESCRIPTION(
22001 "Test that pipeline validation accepts the relaxed type matching rules "
22002 "set out in 14.1.3: fundamental type must match, and producer side must "
22003 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022004 m_errorMonitor->ExpectSuccess();
22005
22006 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
22007
22008 ASSERT_NO_FATAL_FAILURE(InitState());
22009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22010
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022011 char const *vsSource =
22012 "#version 450\n"
22013 "out gl_PerVertex {\n"
22014 " vec4 gl_Position;\n"
22015 "};\n"
22016 "layout(location=0) out vec3 x;\n"
22017 "layout(location=1) out ivec3 y;\n"
22018 "layout(location=2) out vec3 z;\n"
22019 "void main(){\n"
22020 " gl_Position = vec4(0);\n"
22021 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
22022 "}\n";
22023 char const *fsSource =
22024 "#version 450\n"
22025 "\n"
22026 "layout(location=0) out vec4 color;\n"
22027 "layout(location=0) in float x;\n"
22028 "layout(location=1) flat in int y;\n"
22029 "layout(location=2) in vec2 z;\n"
22030 "void main(){\n"
22031 " color = vec4(1 + x + y + z.x);\n"
22032 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022033
22034 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22035 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22036
22037 VkPipelineObj pipe(m_device);
22038 pipe.AddColorAttachment();
22039 pipe.AddShader(&vs);
22040 pipe.AddShader(&fs);
22041
22042 VkDescriptorSetObj descriptorSet(m_device);
22043 descriptorSet.AppendDummy();
22044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22045
22046 VkResult err = VK_SUCCESS;
22047 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22048 ASSERT_VK_SUCCESS(err);
22049
22050 m_errorMonitor->VerifyNotFound();
22051}
22052
22053TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022054 TEST_DESCRIPTION(
22055 "Test that pipeline validation accepts per-vertex variables "
22056 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022057 m_errorMonitor->ExpectSuccess();
22058
22059 ASSERT_NO_FATAL_FAILURE(InitState());
22060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22061
22062 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022063 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022064 return;
22065 }
22066
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022067 char const *vsSource =
22068 "#version 450\n"
22069 "void main(){}\n";
22070 char const *tcsSource =
22071 "#version 450\n"
22072 "layout(location=0) out int x[];\n"
22073 "layout(vertices=3) out;\n"
22074 "void main(){\n"
22075 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
22076 " gl_TessLevelInner[0] = 1;\n"
22077 " x[gl_InvocationID] = gl_InvocationID;\n"
22078 "}\n";
22079 char const *tesSource =
22080 "#version 450\n"
22081 "layout(triangles, equal_spacing, cw) in;\n"
22082 "layout(location=0) in int x[];\n"
22083 "out gl_PerVertex { vec4 gl_Position; };\n"
22084 "void main(){\n"
22085 " gl_Position.xyz = gl_TessCoord;\n"
22086 " gl_Position.w = x[0] + x[1] + x[2];\n"
22087 "}\n";
22088 char const *fsSource =
22089 "#version 450\n"
22090 "layout(location=0) out vec4 color;\n"
22091 "void main(){\n"
22092 " color = vec4(1);\n"
22093 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022094
22095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22096 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
22097 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
22098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22099
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022100 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
22101 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022102
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022103 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022104
22105 VkPipelineObj pipe(m_device);
22106 pipe.SetInputAssembly(&iasci);
22107 pipe.SetTessellation(&tsci);
22108 pipe.AddColorAttachment();
22109 pipe.AddShader(&vs);
22110 pipe.AddShader(&tcs);
22111 pipe.AddShader(&tes);
22112 pipe.AddShader(&fs);
22113
22114 VkDescriptorSetObj descriptorSet(m_device);
22115 descriptorSet.AppendDummy();
22116 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22117
22118 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22119
22120 m_errorMonitor->VerifyNotFound();
22121}
22122
22123TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022124 TEST_DESCRIPTION(
22125 "Test that pipeline validation accepts a user-defined "
22126 "interface block passed into the geometry shader. This "
22127 "is interesting because the 'extra' array level is not "
22128 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022129 m_errorMonitor->ExpectSuccess();
22130
22131 ASSERT_NO_FATAL_FAILURE(InitState());
22132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22133
22134 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022135 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022136 return;
22137 }
22138
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022139 char const *vsSource =
22140 "#version 450\n"
22141 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
22142 "void main(){\n"
22143 " vs_out.x = vec4(1);\n"
22144 "}\n";
22145 char const *gsSource =
22146 "#version 450\n"
22147 "layout(triangles) in;\n"
22148 "layout(triangle_strip, max_vertices=3) out;\n"
22149 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
22150 "out gl_PerVertex { vec4 gl_Position; };\n"
22151 "void main() {\n"
22152 " gl_Position = gs_in[0].x;\n"
22153 " EmitVertex();\n"
22154 "}\n";
22155 char const *fsSource =
22156 "#version 450\n"
22157 "layout(location=0) out vec4 color;\n"
22158 "void main(){\n"
22159 " color = vec4(1);\n"
22160 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022161
22162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22163 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
22164 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22165
22166 VkPipelineObj pipe(m_device);
22167 pipe.AddColorAttachment();
22168 pipe.AddShader(&vs);
22169 pipe.AddShader(&gs);
22170 pipe.AddShader(&fs);
22171
22172 VkDescriptorSetObj descriptorSet(m_device);
22173 descriptorSet.AppendDummy();
22174 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22175
22176 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22177
22178 m_errorMonitor->VerifyNotFound();
22179}
22180
22181TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022182 TEST_DESCRIPTION(
22183 "Test that pipeline validation accepts basic use of 64bit vertex "
22184 "attributes. This is interesting because they consume multiple "
22185 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022186 m_errorMonitor->ExpectSuccess();
22187
22188 ASSERT_NO_FATAL_FAILURE(InitState());
22189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22190
22191 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022192 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022193 return;
22194 }
22195
22196 VkVertexInputBindingDescription input_bindings[1];
22197 memset(input_bindings, 0, sizeof(input_bindings));
22198
22199 VkVertexInputAttributeDescription input_attribs[4];
22200 memset(input_attribs, 0, sizeof(input_attribs));
22201 input_attribs[0].location = 0;
22202 input_attribs[0].offset = 0;
22203 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22204 input_attribs[1].location = 2;
22205 input_attribs[1].offset = 32;
22206 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22207 input_attribs[2].location = 4;
22208 input_attribs[2].offset = 64;
22209 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22210 input_attribs[3].location = 6;
22211 input_attribs[3].offset = 96;
22212 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022214 char const *vsSource =
22215 "#version 450\n"
22216 "\n"
22217 "layout(location=0) in dmat4 x;\n"
22218 "out gl_PerVertex {\n"
22219 " vec4 gl_Position;\n"
22220 "};\n"
22221 "void main(){\n"
22222 " gl_Position = vec4(x[0][0]);\n"
22223 "}\n";
22224 char const *fsSource =
22225 "#version 450\n"
22226 "\n"
22227 "layout(location=0) out vec4 color;\n"
22228 "void main(){\n"
22229 " color = vec4(1);\n"
22230 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022231
22232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22234
22235 VkPipelineObj pipe(m_device);
22236 pipe.AddColorAttachment();
22237 pipe.AddShader(&vs);
22238 pipe.AddShader(&fs);
22239
22240 pipe.AddVertexInputBindings(input_bindings, 1);
22241 pipe.AddVertexInputAttribs(input_attribs, 4);
22242
22243 VkDescriptorSetObj descriptorSet(m_device);
22244 descriptorSet.AppendDummy();
22245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22246
22247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22248
22249 m_errorMonitor->VerifyNotFound();
22250}
22251
22252TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22253 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22254 m_errorMonitor->ExpectSuccess();
22255
22256 ASSERT_NO_FATAL_FAILURE(InitState());
22257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022258 char const *vsSource =
22259 "#version 450\n"
22260 "\n"
22261 "out gl_PerVertex {\n"
22262 " vec4 gl_Position;\n"
22263 "};\n"
22264 "void main(){\n"
22265 " gl_Position = vec4(1);\n"
22266 "}\n";
22267 char const *fsSource =
22268 "#version 450\n"
22269 "\n"
22270 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22271 "layout(location=0) out vec4 color;\n"
22272 "void main() {\n"
22273 " color = subpassLoad(x);\n"
22274 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022275
22276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22278
22279 VkPipelineObj pipe(m_device);
22280 pipe.AddShader(&vs);
22281 pipe.AddShader(&fs);
22282 pipe.AddColorAttachment();
22283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22284
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022285 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22286 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022287 VkDescriptorSetLayout dsl;
22288 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22289 ASSERT_VK_SUCCESS(err);
22290
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022291 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022292 VkPipelineLayout pl;
22293 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22294 ASSERT_VK_SUCCESS(err);
22295
22296 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022297 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22298 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22299 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22300 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22301 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 -060022302 };
22303 VkAttachmentReference color = {
22304 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22305 };
22306 VkAttachmentReference input = {
22307 1, VK_IMAGE_LAYOUT_GENERAL,
22308 };
22309
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022310 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022311
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022312 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022313 VkRenderPass rp;
22314 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22315 ASSERT_VK_SUCCESS(err);
22316
22317 // should be OK. would go wrong here if it's going to...
22318 pipe.CreateVKPipeline(pl, rp);
22319
22320 m_errorMonitor->VerifyNotFound();
22321
22322 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22323 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22324 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22325}
22326
22327TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022328 TEST_DESCRIPTION(
22329 "Test that pipeline validation accepts a compute pipeline which declares a "
22330 "descriptor-backed resource which is not provided, but the shader does not "
22331 "statically use it. This is interesting because it requires compute pipelines "
22332 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022333 m_errorMonitor->ExpectSuccess();
22334
22335 ASSERT_NO_FATAL_FAILURE(InitState());
22336
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022337 char const *csSource =
22338 "#version 450\n"
22339 "\n"
22340 "layout(local_size_x=1) in;\n"
22341 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22342 "void main(){\n"
22343 " // x is not used.\n"
22344 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022345
22346 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22347
22348 VkDescriptorSetObj descriptorSet(m_device);
22349 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022351 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22352 nullptr,
22353 0,
22354 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22355 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22356 descriptorSet.GetPipelineLayout(),
22357 VK_NULL_HANDLE,
22358 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022359
22360 VkPipeline pipe;
22361 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22362
22363 m_errorMonitor->VerifyNotFound();
22364
22365 if (err == VK_SUCCESS) {
22366 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22367 }
22368}
22369
22370TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022371 TEST_DESCRIPTION(
22372 "Test that pipeline validation accepts a shader consuming only the "
22373 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022374 m_errorMonitor->ExpectSuccess();
22375
22376 ASSERT_NO_FATAL_FAILURE(InitState());
22377
22378 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022379 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22380 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22381 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022382 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022383 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022384 VkDescriptorSetLayout dsl;
22385 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22386 ASSERT_VK_SUCCESS(err);
22387
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022388 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022389 VkPipelineLayout pl;
22390 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22391 ASSERT_VK_SUCCESS(err);
22392
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022393 char const *csSource =
22394 "#version 450\n"
22395 "\n"
22396 "layout(local_size_x=1) in;\n"
22397 "layout(set=0, binding=0) uniform sampler s;\n"
22398 "layout(set=0, binding=1) uniform texture2D t;\n"
22399 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22400 "void main() {\n"
22401 " x = texture(sampler2D(t, s), vec2(0));\n"
22402 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022403 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22404
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022405 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22406 nullptr,
22407 0,
22408 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22409 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22410 pl,
22411 VK_NULL_HANDLE,
22412 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022413
22414 VkPipeline pipe;
22415 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22416
22417 m_errorMonitor->VerifyNotFound();
22418
22419 if (err == VK_SUCCESS) {
22420 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22421 }
22422
22423 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22424 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22425}
22426
22427TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022428 TEST_DESCRIPTION(
22429 "Test that pipeline validation accepts a shader consuming only the "
22430 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022431 m_errorMonitor->ExpectSuccess();
22432
22433 ASSERT_NO_FATAL_FAILURE(InitState());
22434
22435 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022436 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22437 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22438 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022439 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022440 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022441 VkDescriptorSetLayout dsl;
22442 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22443 ASSERT_VK_SUCCESS(err);
22444
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022445 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022446 VkPipelineLayout pl;
22447 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22448 ASSERT_VK_SUCCESS(err);
22449
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022450 char const *csSource =
22451 "#version 450\n"
22452 "\n"
22453 "layout(local_size_x=1) in;\n"
22454 "layout(set=0, binding=0) uniform texture2D t;\n"
22455 "layout(set=0, binding=1) uniform sampler s;\n"
22456 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22457 "void main() {\n"
22458 " x = texture(sampler2D(t, s), vec2(0));\n"
22459 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022460 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22461
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022462 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22463 nullptr,
22464 0,
22465 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22466 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22467 pl,
22468 VK_NULL_HANDLE,
22469 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022470
22471 VkPipeline pipe;
22472 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22473
22474 m_errorMonitor->VerifyNotFound();
22475
22476 if (err == VK_SUCCESS) {
22477 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22478 }
22479
22480 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22481 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22482}
22483
22484TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022485 TEST_DESCRIPTION(
22486 "Test that pipeline validation accepts a shader consuming "
22487 "both the sampler and the image of a combined image+sampler "
22488 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022489 m_errorMonitor->ExpectSuccess();
22490
22491 ASSERT_NO_FATAL_FAILURE(InitState());
22492
22493 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022494 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22495 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022496 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022497 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022498 VkDescriptorSetLayout dsl;
22499 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22500 ASSERT_VK_SUCCESS(err);
22501
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022502 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022503 VkPipelineLayout pl;
22504 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22505 ASSERT_VK_SUCCESS(err);
22506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022507 char const *csSource =
22508 "#version 450\n"
22509 "\n"
22510 "layout(local_size_x=1) in;\n"
22511 "layout(set=0, binding=0) uniform texture2D t;\n"
22512 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22513 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22514 "void main() {\n"
22515 " x = texture(sampler2D(t, s), vec2(0));\n"
22516 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022517 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22518
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022519 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22520 nullptr,
22521 0,
22522 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22523 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22524 pl,
22525 VK_NULL_HANDLE,
22526 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022527
22528 VkPipeline pipe;
22529 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22530
22531 m_errorMonitor->VerifyNotFound();
22532
22533 if (err == VK_SUCCESS) {
22534 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22535 }
22536
22537 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22538 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22539}
22540
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022541// This test class enables the Maintenance1 extension for related validation tests
22542TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22543 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22544
22545 // Ensure that extension is available and enabled.
22546 uint32_t extension_count = 0;
22547 bool supports_maintenance1_extension = false;
22548 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22549 ASSERT_VK_SUCCESS(err);
22550 if (extension_count > 0) {
22551 std::vector<VkExtensionProperties> available_extensions(extension_count);
22552
22553 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22554 ASSERT_VK_SUCCESS(err);
22555 for (const auto &extension_props : available_extensions) {
22556 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22557 supports_maintenance1_extension = true;
22558 }
22559 }
22560 }
22561
22562 // Proceed if extension is supported by hardware
22563 if (!supports_maintenance1_extension) {
22564 printf(" Maintenance1 Extension not supported, skipping tests\n");
22565 return;
22566 }
22567 ASSERT_NO_FATAL_FAILURE(InitState());
22568
22569 m_errorMonitor->ExpectSuccess();
22570
22571 VkCommandBuffer cmd_buf;
22572 VkCommandBufferAllocateInfo alloc_info;
22573 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22574 alloc_info.pNext = NULL;
22575 alloc_info.commandBufferCount = 1;
22576 alloc_info.commandPool = m_commandPool;
22577 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22578 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22579
22580 VkCommandBufferBeginInfo cb_binfo;
22581 cb_binfo.pNext = NULL;
22582 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22583 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22584 cb_binfo.flags = 0;
22585 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22586 // Set Negative height, should give error if Maintenance 1 is not enabled
22587 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22588 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22589 vkEndCommandBuffer(cmd_buf);
22590
22591 m_errorMonitor->VerifyNotFound();
22592}
22593
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022594TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22595 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22596
22597 ASSERT_NO_FATAL_FAILURE(InitState());
22598
22599 // Positive test to check parameter_validation and unique_objects support
22600 // for NV_dedicated_allocation
22601 uint32_t extension_count = 0;
22602 bool supports_nv_dedicated_allocation = false;
22603 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22604 ASSERT_VK_SUCCESS(err);
22605
22606 if (extension_count > 0) {
22607 std::vector<VkExtensionProperties> available_extensions(extension_count);
22608
22609 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22610 ASSERT_VK_SUCCESS(err);
22611
22612 for (const auto &extension_props : available_extensions) {
22613 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22614 supports_nv_dedicated_allocation = true;
22615 }
22616 }
22617 }
22618
22619 if (supports_nv_dedicated_allocation) {
22620 m_errorMonitor->ExpectSuccess();
22621
22622 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22623 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22624 dedicated_buffer_create_info.pNext = nullptr;
22625 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22626
22627 uint32_t queue_family_index = 0;
22628 VkBufferCreateInfo buffer_create_info = {};
22629 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22630 buffer_create_info.pNext = &dedicated_buffer_create_info;
22631 buffer_create_info.size = 1024;
22632 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22633 buffer_create_info.queueFamilyIndexCount = 1;
22634 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22635
22636 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022637 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022638 ASSERT_VK_SUCCESS(err);
22639
22640 VkMemoryRequirements memory_reqs;
22641 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22642
22643 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22644 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22645 dedicated_memory_info.pNext = nullptr;
22646 dedicated_memory_info.buffer = buffer;
22647 dedicated_memory_info.image = VK_NULL_HANDLE;
22648
22649 VkMemoryAllocateInfo memory_info = {};
22650 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22651 memory_info.pNext = &dedicated_memory_info;
22652 memory_info.allocationSize = memory_reqs.size;
22653
22654 bool pass;
22655 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22656 ASSERT_TRUE(pass);
22657
22658 VkDeviceMemory buffer_memory;
22659 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22660 ASSERT_VK_SUCCESS(err);
22661
22662 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22663 ASSERT_VK_SUCCESS(err);
22664
22665 vkDestroyBuffer(m_device->device(), buffer, NULL);
22666 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22667
22668 m_errorMonitor->VerifyNotFound();
22669 }
22670}
22671
22672TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22673 VkResult err;
22674
22675 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22676
22677 ASSERT_NO_FATAL_FAILURE(InitState());
22678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22679
22680 std::vector<const char *> device_extension_names;
22681 auto features = m_device->phy().features();
22682 // Artificially disable support for non-solid fill modes
22683 features.fillModeNonSolid = false;
22684 // The sacrificial device object
22685 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22686
22687 VkRenderpassObj render_pass(&test_device);
22688
22689 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22690 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22691 pipeline_layout_ci.setLayoutCount = 0;
22692 pipeline_layout_ci.pSetLayouts = NULL;
22693
22694 VkPipelineLayout pipeline_layout;
22695 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22696 ASSERT_VK_SUCCESS(err);
22697
22698 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22699 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22700 rs_ci.pNext = nullptr;
22701 rs_ci.lineWidth = 1.0f;
22702 rs_ci.rasterizerDiscardEnable = true;
22703
22704 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22705 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22706
22707 // Set polygonMode=FILL. No error is expected
22708 m_errorMonitor->ExpectSuccess();
22709 {
22710 VkPipelineObj pipe(&test_device);
22711 pipe.AddShader(&vs);
22712 pipe.AddShader(&fs);
22713 pipe.AddColorAttachment();
22714 // Set polygonMode to a good value
22715 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22716 pipe.SetRasterization(&rs_ci);
22717 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22718 }
22719 m_errorMonitor->VerifyNotFound();
22720
22721 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22722}
22723
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022724#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022725TEST_F(VkPositiveLayerTest, LongFenceChain)
22726{
22727 m_errorMonitor->ExpectSuccess();
22728
22729 ASSERT_NO_FATAL_FAILURE(InitState());
22730 VkResult err;
22731
22732 std::vector<VkFence> fences;
22733
22734 const int chainLength = 32768;
22735
22736 for (int i = 0; i < chainLength; i++) {
22737 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22738 VkFence fence;
22739 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22740 ASSERT_VK_SUCCESS(err);
22741
22742 fences.push_back(fence);
22743
22744 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22745 0, nullptr, 0, nullptr };
22746 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22747 ASSERT_VK_SUCCESS(err);
22748
22749 }
22750
22751 // BOOM, stack overflow.
22752 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22753
22754 for (auto fence : fences)
22755 vkDestroyFence(m_device->device(), fence, nullptr);
22756
22757 m_errorMonitor->VerifyNotFound();
22758}
22759#endif
22760
Cody Northrop1242dfd2016-07-13 17:24:59 -060022761#if defined(ANDROID) && defined(VALIDATION_APK)
22762static bool initialized = false;
22763static bool active = false;
22764
22765// Convert Intents to argv
22766// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022767std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022768 std::vector<std::string> args;
22769 JavaVM &vm = *app.activity->vm;
22770 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022771 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022772
22773 JNIEnv &env = *p_env;
22774 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022775 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022776 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022777 jmethodID get_string_extra_method =
22778 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022779 jvalue get_string_extra_args;
22780 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022781 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022782
22783 std::string args_str;
22784 if (extra_str) {
22785 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22786 args_str = extra_utf;
22787 env.ReleaseStringUTFChars(extra_str, extra_utf);
22788 env.DeleteLocalRef(extra_str);
22789 }
22790
22791 env.DeleteLocalRef(get_string_extra_args.l);
22792 env.DeleteLocalRef(intent);
22793 vm.DetachCurrentThread();
22794
22795 // split args_str
22796 std::stringstream ss(args_str);
22797 std::string arg;
22798 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022799 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022800 }
22801
22802 return args;
22803}
22804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022805static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022807static void processCommand(struct android_app *app, int32_t cmd) {
22808 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022809 case APP_CMD_INIT_WINDOW: {
22810 if (app->window) {
22811 initialized = true;
22812 }
22813 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022814 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022815 case APP_CMD_GAINED_FOCUS: {
22816 active = true;
22817 break;
22818 }
22819 case APP_CMD_LOST_FOCUS: {
22820 active = false;
22821 break;
22822 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022823 }
22824}
22825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022826void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022827 app_dummy();
22828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022829 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022830
22831 int vulkanSupport = InitVulkan();
22832 if (vulkanSupport == 0) {
22833 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22834 return;
22835 }
22836
22837 app->onAppCmd = processCommand;
22838 app->onInputEvent = processInput;
22839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022840 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022841 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022842 struct android_poll_source *source;
22843 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022844 if (source) {
22845 source->process(app, source);
22846 }
22847
22848 if (app->destroyRequested != 0) {
22849 VkTestFramework::Finish();
22850 return;
22851 }
22852 }
22853
22854 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022855 // Use the following key to send arguments to gtest, i.e.
22856 // --es args "--gtest_filter=-VkLayerTest.foo"
22857 const char key[] = "args";
22858 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022860 std::string filter = "";
22861 if (args.size() > 0) {
22862 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22863 filter += args[0];
22864 } else {
22865 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22866 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022868 int argc = 2;
22869 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22870 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022872 // Route output to files until we can override the gtest output
22873 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22874 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022876 ::testing::InitGoogleTest(&argc, argv);
22877 VkTestFramework::InitArgs(&argc, argv);
22878 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022880 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022882 if (result != 0) {
22883 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22884 } else {
22885 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22886 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022888 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022890 fclose(stdout);
22891 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022893 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022894 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022895 }
22896 }
22897}
22898#endif
22899
Tony Barbour300a6082015-04-07 13:44:53 -060022900int main(int argc, char **argv) {
22901 int result;
22902
Cody Northrop8e54a402016-03-08 22:25:52 -070022903#ifdef ANDROID
22904 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022905 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022906#endif
22907
Tony Barbour300a6082015-04-07 13:44:53 -060022908 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022909 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022910
22911 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22912
22913 result = RUN_ALL_TESTS();
22914
Tony Barbour6918cd52015-04-09 12:58:51 -060022915 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022916 return result;
22917}